Skip to content

Commit 2d415a2

Browse files
committed
Initial commit
Signed-off-by: Jarrod Bell <[email protected]>
0 parents  commit 2d415a2

File tree

8 files changed

+268
-0
lines changed

8 files changed

+268
-0
lines changed

MiCasaVerde/MiCasa.gui

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<gui>
3+
<properties>
4+
<project>MiCasa</project>
5+
<designer>
6+
</designer>
7+
<size autoposition="scale">
8+
<portrait width="768" height="1024" />
9+
<landscape width="1024" height="768" />
10+
</size>
11+
<autoposition />
12+
<imagefolder>
13+
</imagefolder>
14+
<debug loaderrors="1" connectionerrors="1" />
15+
<devices>
16+
<device name="Craers iPad">A06EB470294983EF8801BDA61F8B4B76</device>
17+
</devices>
18+
</properties>
19+
<themes>
20+
<theme type="text" name=".Device_Name"><![CDATA[ color: White; font-size: 12px; font-family: 'Arial'; text-align: left; vertical-align: middle; font-weight: normal; font-style: none; text-decoration: none; display: table-cell;]]></theme>
21+
<theme type="button" name=".Button_On[state='0']"><![CDATA[padding: 0px 0px 0px 0px; background-image: url(Resources\On.png); color: White; font-size: 12px; font-family: 'Verdana'; font-weight: normal; font-style: none; text-decoration: none; text-align: center; vertical-align: middle; display: table-cell; box-sizing: border-box; -webkit-box-sizing: border-box; -webkit-tap-highlight-color:rgba(0,0,0,0);]]></theme>
22+
<theme type="button" name=".Button_On[state='1']"><![CDATA[padding: 0px 0px 0px 0px; color: White; font-size: 12px; font-family: 'Verdana'; font-weight: normal; font-style: none; text-decoration: none; text-align: center; vertical-align: middle; display: table-cell; box-sizing: border-box; -webkit-box-sizing: border-box; -webkit-tap-highlight-color:rgba(0,0,0,0);]]></theme>
23+
<theme type="button" name=".Button_Off[state='0']"><![CDATA[padding: 0px 0px 0px 0px; background-image: url(Resources\Off.png); color: White; font-size: 12px; font-family: 'Verdana'; font-weight: normal; font-style: none; text-decoration: none; text-align: center; vertical-align: middle; display: table-cell; box-sizing: border-box; -webkit-box-sizing: border-box; -webkit-tap-highlight-color:rgba(0,0,0,0);]]></theme>
24+
<theme type="button" name=".Button_Off[state='1']"><![CDATA[padding: 0px 0px 0px 0px; color: White; font-size: 12px; font-family: 'Verdana'; font-weight: normal; font-style: none; text-decoration: none; text-align: center; vertical-align: middle; display: table-cell; box-sizing: border-box; -webkit-box-sizing: border-box; -webkit-tap-highlight-color:rgba(0,0,0,0);]]></theme>
25+
<theme type="text" name=".Room"><![CDATA[ color: Blue; font-size: 15px; font-family: 'Arial'; text-align: left; vertical-align: middle; font-weight: normal; font-style: none; text-decoration: none; display: table-cell;]]></theme>
26+
</themes>
27+
<scripts>
28+
<script name="MiCasaVerde.js" />
29+
</scripts>
30+
<page name="Main" j="0" tags="" transition="" subtype="" time="0" ease="">
31+
<portrait />
32+
<landscape>
33+
<subpage name="DeviceList" x="37" y="25" j="0" transition1="" subtype1="" time1="0" ease1="" transition2="" subtype2="" time2="0" ease2="" clickthrough="0" topmost="0" v="1" l="0" tags="" />
34+
<subpage name="DeviceList_2" x="37" y="214" j="0" transition1="" subtype1="" time1="0" ease1="" transition2="" subtype2="" time2="0" ease2="" clickthrough="0" topmost="0" v="1" l="0" tags="" />
35+
<subpage name="DeviceList_3" x="37" y="404" j="0" transition1="" subtype1="" time1="0" ease1="" transition2="" subtype2="" time2="0" ease2="" clickthrough="0" topmost="0" v="1" l="0" tags="" />
36+
<subpage name="DeviceList_4" x="37" y="593" j="0" transition1="" subtype1="" time1="0" ease1="" transition2="" subtype2="" time2="0" ease2="" clickthrough="0" topmost="0" v="1" l="0" tags="" />
37+
</landscape>
38+
</page>
39+
<subpage name="DeviceListItem" w="225" h="110" clip="1">
40+
<img x="0" y="0" w="200" h="100" j="0" clickthrough="0" refresh="0" l="0" noCache="0" downloadIndicator="0" clearOnURLChange="0" tags="">Resources\Device_Background.png</img>
41+
<txt j="10" x="14" y="5" w="172" h="15" t="Device_Name" wrap="False" l="0" tags="">Text</txt>
42+
<img x="6" y="34" w="50" h="50" j="11" clickthrough="0" refresh="0" l="0" noCache="0" downloadIndicator="0" clearOnURLChange="0" tags="" />
43+
<btn j="12" x="61" y="38" w="50" h="25" t="Button_On" flip="None" sim="0" l="0" s="1" tags="">
44+
<actions>
45+
<action>
46+
<release delay="0" js="DeviceOn(list, listIndex, join)" />
47+
</action>
48+
</actions>
49+
<inactive s="12">
50+
</inactive>
51+
<active s="12">
52+
</active>
53+
</btn>
54+
<btn j="13" x="128" y="38" w="50" h="25" t="Button_Off" flip="None" sim="0" l="0" s="1" tags="">
55+
<actions>
56+
<action>
57+
<release delay="0" js="DeviceOff(list, listIndex, join)" />
58+
</action>
59+
</actions>
60+
<inactive s="13">
61+
</inactive>
62+
<active s="13">
63+
</active>
64+
</btn>
65+
</subpage>
66+
<subpage name="DeviceList" w="950" h="150" clip="1">
67+
<list j="100" x="5" y="25" w="943" h="150" headerSub="" titleSub="" contentSub="DeviceListItem" footerSub="" orientation="h" l="0" swipedelete="0" tags="" />
68+
<txt j="200" x="22" y="1" w="456" h="21" t="Room" wrap="False" l="0" tags="">
69+
</txt>
70+
</subpage>
71+
<subpage name="DeviceList_2" w="950" h="150" clip="1">
72+
<list j="101" x="5" y="25" w="943" h="150" headerSub="" titleSub="" contentSub="DeviceListItem" footerSub="" orientation="h" l="0" swipedelete="0" tags="" />
73+
<txt j="201" x="22" y="1" w="456" h="21" t="Room" wrap="False" l="0" tags="">
74+
</txt>
75+
</subpage>
76+
<subpage name="DeviceList_3" w="950" h="150" clip="1">
77+
<list j="102" x="5" y="25" w="943" h="150" headerSub="" titleSub="" contentSub="DeviceListItem" footerSub="" orientation="h" l="0" swipedelete="0" tags="" />
78+
<txt j="202" x="22" y="1" w="456" h="21" t="Room" wrap="False" l="0" tags="">
79+
</txt>
80+
</subpage>
81+
<subpage name="DeviceList_4" w="950" h="150" clip="1">
82+
<list j="103" x="5" y="25" w="943" h="150" headerSub="" titleSub="" contentSub="DeviceListItem" footerSub="" orientation="h" l="0" swipedelete="0" tags="" />
83+
<txt j="203" x="22" y="1" w="456" h="21" t="Room" wrap="False" l="0" tags="">
84+
</txt>
85+
</subpage>
86+
<subpage name="zCACHE" w="768" h="1024" clip="1">
87+
<img x="19" y="23" w="50" h="50" j="0" clickthrough="0" refresh="0" l="0" noCache="0" downloadIndicator="0" clearOnURLChange="0" tags="">Resources\light_Off.jpg</img>
88+
<img x="76" y="23" w="50" h="50" j="0" clickthrough="0" refresh="0" l="0" noCache="0" downloadIndicator="0" clearOnURLChange="0" tags="">Resources\light_On.jpg</img>
89+
</subpage>
90+
</gui>

MiCasaVerde/MiCasaVerde.js

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
/*========================================
2+
MiCasa Verde VeraLite Device Demo
3+
==========================================*/
4+
5+
//Change the IP below to the IP of your Vera unit
6+
var MiCasaIP = "192.168.50.155";
7+
var MiCasaPort = "3480";
8+
9+
//Main function auto loads when iViewer is started
10+
//Make sure you don't have more than one CF.userMain declared in your any scripts your project uses.
11+
CF.userMain = function() {
12+
//calls getDevices with a basejoin of 100
13+
getDevices(100);
14+
getRooms(200);
15+
};
16+
17+
//Gets the url/host before sending the JSON request to MiCasaVerde
18+
geturl = function() {
19+
return "http://" + MiCasaIP +":" + MiCasaPort + "/";
20+
};
21+
22+
micasarpc = function(method, callback) {
23+
var host = self.geturl();
24+
var url = host + method;
25+
26+
CF.request(url, function(status, headers, body) {
27+
var data = JSON.parse(body);
28+
callback(data);
29+
});
30+
};
31+
32+
//Sets up room names for each list
33+
getRooms = function(join) {
34+
var baseJoin = join;
35+
36+
micasarpc("data_request?id=user_data&output_format=json", function(data) {
37+
38+
RoomArray = [];
39+
40+
for (var i = 0; i<data.rooms.length; i++) {
41+
42+
var roomid = data.rooms[i].id;
43+
var roomname = data.rooms[i].name;
44+
45+
CF.setJoin("s"+baseJoin, roomname);
46+
baseJoin++;
47+
};
48+
});
49+
};
50+
51+
//called when iViewer is started and gets all devices of Mi Casa Verde. Then Assigns names and device id's to buttons
52+
getDevices = function(join) {
53+
var baseJoin = join;
54+
55+
micasarpc("data_request?id=user_data&output_format=json", function(data) {
56+
57+
DeviceArray = [];
58+
59+
for (var i = 0; i<data.devices.length; i++) {
60+
61+
var deviceid = data.devices[i].id;
62+
var name = data.devices[i].name;
63+
var roomid = data.devices[i].room;
64+
65+
if (data.devices[i].invisible == null) {
66+
// Add to array to add to list in one go later
67+
DeviceArray.push({
68+
s10: name,
69+
Room: roomid,
70+
s11: {
71+
tokens: {
72+
"[id]": deviceid
73+
}
74+
},
75+
d12: {
76+
tokens: {
77+
"[id]": deviceid
78+
}
79+
},
80+
d13: {
81+
tokens: {
82+
"[id]": deviceid
83+
}
84+
}
85+
});
86+
};
87+
};
88+
89+
//add all devices found to Room list
90+
for (var i = 0; i<DeviceArray.length; i++) {
91+
if (DeviceArray[i].Room == "1") {
92+
CF.listAdd("l"+baseJoin, [DeviceArray[i]]);
93+
};
94+
if (DeviceArray[i].Room == "2") {
95+
CF.listAdd("l"+(baseJoin + 1), [DeviceArray[i]]);
96+
};
97+
if (DeviceArray[i].Room == "3") {
98+
CF.listAdd("l"+(baseJoin + 2), [DeviceArray[i]]);
99+
};
100+
if (DeviceArray[i].Room == "4") {
101+
CF.listAdd("l"+(baseJoin + 3), [DeviceArray[i]]);
102+
};
103+
};
104+
105+
//get the status of all devices
106+
UpdateAllDevices();
107+
});
108+
};
109+
110+
DeviceOn = function(list, listIndex, join) {
111+
112+
CF.getJoin(list+":"+listIndex+":"+join, function(j,v,t) {
113+
micasarpc( ("data_request?id=action&output_format=json&DeviceNum=" + t["[id]"] + "&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1"), function(data) {
114+
115+
//data gives back the job id, can use: http://ip_address:3480/data_request?id=jobstatus&job=6&plugin=zwave to pull back job success
116+
117+
});
118+
});
119+
120+
//delay for 1 second then get the device status
121+
setTimeout(function() {UpdateAllDevices()}, 1000);
122+
};
123+
124+
DeviceOff = function(list, listIndex, join) {
125+
126+
CF.getJoin(list+":"+listIndex+":"+join, function(j,v,t) {
127+
micasarpc( ("data_request?id=action&output_format=json&DeviceNum=" + t["[id]"] + "&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0"), function(data) {
128+
129+
//data gives back the job id, can use: http://ip_address:3480/data_request?id=jobstatus&job=6&plugin=zwave to pull back job success/fail
130+
131+
});
132+
});
133+
134+
//delay for 1 second then get the device status
135+
setTimeout(function() {UpdateAllDevices()}, 1000);
136+
};
137+
138+
GetDeviceStatus = function(list, listIndex, join) {
139+
CF.getJoin(list+":"+listIndex+":"+join, function(j,v,t) {
140+
micasarpc( ("data_request?id=status&output_format=json&DeviceNum=" + t["[id]"]), function(data) {
141+
142+
var devicestatus = data["Device_Num_"+t["[id]"]].states[0].value;
143+
144+
SetDeviceStatus(list, listIndex, devicestatus);
145+
});
146+
});
147+
};
148+
149+
SetDeviceStatus = function(list, listIndex, status) {
150+
if (status === "0") {
151+
CF.setJoin(list +":" + listIndex +":s11", "Resources/light_Off.jpg");
152+
};
153+
154+
if (status === "1") {
155+
CF.setJoin(list +":" + listIndex +":s11", "Resources/light_On.jpg");
156+
};
157+
};
158+
159+
UpdateAllDevices = function() {
160+
var listjoin = 100;
161+
var maxrooms = (listjoin + 4);
162+
163+
//gets each list and then updates all devices in each list
164+
for (listjoin; listjoin<maxrooms; listjoin++) {
165+
var list = ("l" + listjoin);
166+
167+
CF.listInfo(list, function(list, count, first, numVisible, scrollPosition) {
168+
//loop through the list and set the devices status.
169+
var listcount = count;
170+
171+
for (var i = 0; i<listcount; i++){
172+
GetDeviceStatus(list, i, "s11");
173+
};
174+
});
175+
};
176+
};
879 Bytes
Loading

MiCasaVerde/Resources/Off.png

415 Bytes
Loading

MiCasaVerde/Resources/On.png

491 Bytes
Loading
2.11 KB
Loading

MiCasaVerde/Resources/light_On.jpg

2.49 KB
Loading

readme.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Integrate VeraControls devices with CommandFusion iViewer
2+
For more details, see the [CommandFusion Wiki VeraControls page](http://www.commandfusion.com/wiki2/software/modules-and-examples/vera-control)

0 commit comments

Comments
 (0)