forked from node-red/node-red-nodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeMoNG.html
257 lines (244 loc) · 9.15 KB
/
WeMoNG.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<script type="text/x-red" data-template-name="wemo in">
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
<input type="text" id="node-input-topic" placeholder="Topic">
</div>
<br/>
<div class="form-row">
<label for="node-input-device"><i class="fa fa-tasks"></i> Device</label>
<input type="text" id="node-input-device" placeholder="Device">
</div>
<br/>
<!-- By convention, most nodes have a 'name' property. The following div -->
<!-- provides the necessary field. Should always be the last option -->
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="wemo in">
<p>A node that listens to event notifications from Belkin WeMo devices.</p>
<p>Supported devices include:</p>
<ul>
<li>Sockets</li>
<li>Insight Sockets</li>
<li>Light Bulbs</li>
<li>Light Groups</li>
<li>Motion Detector</li>
</ul>
<p>Sockets will generate msg.payload with values of 0/1/8 for off or on
(8 is on but at standby load for insight sockets), lightswill return an
object like this:</p>
<pre>
{
name: 'Bedroom light',
type: 'light',
id: '94103EA2B27803ED',
capability: '1006',
value: 1
}
</pre>
<p>Current known capabilities</p>
<ul>
<li>10006 - on/off</li>
<li>10008 - brightness</li>
<li>10300 - color</li>
<li>30301 - color temperature</li>
</ul>
</script>
<script type="text/javascript">
RED.nodes.registerType('wemo in',{
category: 'input', // the palette category
defaults: { // defines the editable properties of the node
name: {value:""}, // along with default values.
topic: {value:"wemo", required: true},
device: {value:"", type: "wemo-dev"},
label: {value:""}
},
color: "LawnGreen",
inputs:0, // set the number of inputs - only 0 or 1
outputs:1, // set the number of outputs - 0 to n
// set the icon (held in icons dir below where you save the node)
icon: "belkin.png", // saved in icons/myicon.png
label: function() { // sets the default label contents
if (this.name){
return this.name;
} else {
return this.label||"wemo";
}
},
labelStyle: function() { // sets the class to apply to the label
return this.name?"node_label_italic":"";
},
oneditsave: function(){
this.label = $('#node-input-device option:selected').text();
}
});
</script>
<script type="text/x-red" data-template-name="wemo out">
<div class="form-row">
<label for="node-input-device"><i class="fa fa-tasks"></i> Device</label>
<input type="text" id="node-input-device" placeholder="Device">
</div>
<br/>
<!-- By convention, most nodes have a 'name' property. The following div -->
<!-- provides the necessary field. Should always be the last option -->
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="wemo out">
<p>A node to control Belkin WeMo Devices</p>
<p>Supported devices include:</p>
<ul>
<li>Sockets</li>
<li>Insight Sockets</li>
<li>Light Bulbs</li>
</ul>
<p>Sets the device on or off based on the passed in msg.payload values of:</p>
<ul>
<li>on/off</li>
<li>1/0</li>
<li>true/false</li>
</ul>
<p>for light bulbs it also accepts an object with the following structure</p>
<pre>
{
state: 1,
dim: 255,
color: '255,255,255',
temperature: 25000
}
</pre>
<p>color control is still a work in progress, but the rest should work</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('wemo out',{
category: 'output', // the palette category
defaults: { // defines the editable properties of the node
name: {value:""}, // along with default values.
device: {type: "wemo-dev", required: true},
label: {value: ""}
},
color: "LawnGreen",
inputs: 1, // set the number of inputs - only 0 or 1
// set the icon (held in icons dir below where you save the node)
icon: "belkin.png", // saved in icons/myicon.png
label: function() { // sets the default label contents
if (this.name){
return this.name;
} else {
return this.label||"wemo";
}
},
labelStyle: function() { // sets the class to apply to the label
return this.name?"node_label_italic":"";
},
oneditsave: function(){
this.label = $('#node-input-device option:selected').text();
}
});
</script>
<script type="text/x-red" data-template-name="wemo lookup">
<div class="form-row">
<label for="node-input-device"><i class="fa fa-tasks"></i> Device</label>
<input type="text" id="node-input-device" placeholder="Device">
</div>
<br/>
<!-- By convention, most nodes have a 'name' property. The following div -->
<!-- provides the necessary field. Should always be the last option -->
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="wemo lookup">
<p>This node queries the current state of a device</p>
<p>For lights it return a msg.payload that looks like this:</p>
<pre>{
available: true,
state: 0,
dim: 13
}</pre>
<p>Where <em>available</em> is if the blub is actually turned on
at the wall switch<p>
</script>
<script type="text/javascript">
RED.nodes.registerType('wemo lookup',{
category: 'function', // the palette category
defaults: { // defines the editable properties of the node
name: {value:""}, // along with default values.
device: {type: "wemo-dev", required: true},
label: {value:""}
},
color: "LawnGreen",
inputs: 1, // set the number of inputs - only 0 or 1
outputs: 1,
// set the icon (held in icons dir below where you save the node)
icon: "belkin.png", // saved in icons/myicon.png
label: function() { // sets the default label contents
if (this.name){
return this.name;
} else {
return this.label||"wemo";
}
},
labelStyle: function() { // sets the class to apply to the label
return this.name?"node_label_italic":"";
},
oneditsave: function(){
this.label = $('#node-input-device option:selected').text();
}
});
</script>
<script type="text/x-red" data-template-name="wemo-dev">
<div class="form-row">
<label for="node-config-input-device"><i class="fa fa-tasks"></i> Device</label>
<select size="4" id="node-config-input-device">
</select>
</div>
<br/>
<div class="form-row">
<label for="node-config-input-type"><i class="fa fa-tasks"></i> Type</label>
<input type="text" editable="false" id="node-config-input-type" placeholder="Type"/>
<input type="hidden" editable="false" id="node-config-input-name"/>
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('wemo-dev',{
category: 'config', // the palette category
defaults: { // defines the editable properties of the node
device: {value:"", required: true}, // along with default values.
name: {value: ""}
},
label: function() { // sets the default label contents
return this.name;
},
oneditprepare: function() {
var devices;
$.getJSON('wemoNG/devices', function(data) {
devices = data;
var devs = Object.keys(data);
if (devs.length !== 0) {
for (var d in devs) {
if (devs.hasOwnProperty(d)) {
$('<option/>',{
'value': devs[d],
'text': data[devs[d]].name
}).appendTo('#node-config-input-device');
console.log(data[devs[d]].name);
}
}
}
});
$('#node-config-input-device').change(function() {
var id = $( "#node-config-input-device option:selected" ).first().val();
if (devices) {
$('#node-config-input-type').val(devices[id].type);
$('#node-config-input-name').val(devices[id].name);
}
});
}
});
</script>