-
Notifications
You must be signed in to change notification settings - Fork 13
/
node-ikea.html
executable file
·482 lines (432 loc) · 22.6 KB
/
node-ikea.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
<!-- Config Node -->
<script type="text/javascript">
RED.nodes.registerType('ikea-connection',{
category: 'config',
defaults: {
address: { value:"", required:true },
name: { value:"" }
},
credentials: {
securityCode: { type:"text" },
identity: { type:"text" },
psk: { type:"text" }
},
label: function() {
return this.name || "ikea@" + this.address;
}
});
</script>
<script type="text/x-red" data-template-name="ikea-connection">
<div class="form-row">
<label for="node-config-input-address"><i class="fa fa-globe"></i> Address</label>
<input type="text" id="node-config-input-address">
</div>
<div class="form-row">
<label for="node-config-input-securityCode"><i class="fa fa-gears"></i> Security Code</label>
<input type="text" id="node-config-input-securityCode">
</div>
<div class="form-row">
<label for="node-config-input-identity"><i class="fa fa-address-card-o"></i> Identity</label>
<input type="text" id="node-config-input-identity">
</div>
<div class="form-row">
<label for="node-config-input-psk"><i class="fa fa-lock"></i> Pre-shared key</label>
<input type="text" id="node-config-input-psk">
</div>
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-config-input-name">
</div>
</script>
<script type="text/x-red" data-help-name="ikea-connection">
<ul>
<li><i class="fa fa-globe"></i> <b>Address:</b> The address to your gateway.</li>
<li><i class="fa fa-gears"></i> <b>Security code:</b> The security code on the backside of your gateway. You only need to enter this if you <em>don't</em> have an identiy and PSK. In that case identity and PSK will be generated for you using the security key.</li>
<li><i class="fa fa-address-card-o"></i> <b>Address:</b> The identiy used to access the gateway. Used together with a PSK.</li>
<li><i class="fa fa-lock"></i> <b>Pre-shared key:</b> The passkey used to access the gateway. Used together with an identity.</li>
</ul>
</script>
<!--- Homesmart Node -->
<script type="text/javascript">
var updateDevices = (currentDeviceId) => {
let configNodeId = $('#node-input-connection').find(":selected").val();
if (configNodeId == null || configNodeId === '_ADD_') { return; }
let deviceType = $('#node-input-deviceType').find(":selected").val();
if (deviceType == null || deviceType === '_ADD_') {
$('#node-input-deviceId').find('option').not(':first').remove();
$('#node-input-deviceId-icon').attr('class', 'fa fa-home');
$('#deviceObserve').hide();
$('#sceneId').hide();
return;
}
$.get('ikea/' + deviceType, {nodeId: configNodeId}, function(resp) {
let devices = JSON.parse(resp);
$('#node-input-deviceId').find('option').not(':first').remove();
if (!Array.isArray(devices) || devices.length <= 0) { return; }
//$('#node-input-deviceId').find('option').not(':first').remove();
$.each(devices, function(i, device) {
let opt = {};
opt.value = device.id;
opt.text = device.name;
if (device.id === currentDeviceId) {
opt.selected = "selected";
}
$('#node-input-deviceId').append($('<option>', opt));
});
});
if (deviceType === 'ikea-groups') {
$.get('ikea/ikea-scenes', {nodeId: configNodeId}, function(resp) {
let scenes = JSON.parse(resp);
if (!Array.isArray(scenes) || scenes.length <= 0) { return; }
$('#node-option-scene').find('tr').not(':first').remove();
$.each(scenes, function(i, scene) {
if (scene.group === $('#node-input-deviceId').find(":selected").val()) {
$('#node-option-scene').append('<tr><td>' + scene.name + '</td><td><code>{"sceneId": ' + scene.id + '}</code></td></tr>');
}
});
});
}
switch (deviceType) {
case "ikea-blinds":
$('#node-input-deviceId-icon').attr('class', 'fa fa-window-maximize');
$('#deviceObserve').show();
$('#sceneId').hide();
break;
case "ikea-lights":
$('#node-input-deviceId-icon').attr('class', 'fa fa-lightbulb-o');
$('#deviceObserve').show();
$('#sceneId').hide();
break;
case "ikea-plugs":
$('#node-input-deviceId-icon').attr('class', 'fa fa-plug');
$('#deviceObserve').show();
$('#sceneId').hide();
break;
case "ikea-sensors":
$('#node-input-deviceId-icon').attr('class', 'fa fa-bullseye');
$('#deviceObserve').hide();
$('#sceneId').hide();
break;
case "ikea-remotes":
$('#node-input-deviceId-icon').attr('class', 'fa fa-power-off');
$('#deviceObserve').hide();
$('#sceneId').hide();
break;
case "ikea-groups":
$('#node-input-deviceId-icon').attr('class', 'fa fa-sitemap');
$('#deviceObserve').show();
$('#sceneId').show();
break;
default:
break;
}
};
RED.nodes.registerType('ikea-homesmart', {
category: 'homesmart',
color: '#FFDA1A',
defaults: {
name: { value: "" },
deviceId: { value: "", required: true, validate: RED.validators.number() },
deviceName: { value: "" },
deviceType: { value: "" },
deviceIcon: { value: "" },
connection: { value: "", type: "ikea-connection" },
observe: { value: false, required: true }
},
align: 'left',
inputs: 1,
outputs: 1,
icon: function() {
return this.deviceIcon || 'font-awesome/fa-home';
},
label: function() {
if (this.name !== "") {
return this.name;
} else {
return this.deviceName || "ikea-homesmart";
}
},
oneditprepare: function() {
var node = this;
$('#deviceObserve').hide();
$('#sceneId').hide();
$('#node-input-connection').change(function(){
updateDevices(node.deviceId);
});
$('#node-input-deviceType').change(function(){
updateDevices(node.deviceId);
});
$('#ikea-deviceId-refresh-spinner').click(function(){
updateDevices(node.deviceId);
});
$(document).ready(function() {
$('#node-input-msgPassthrough').prop('checked', node.observe);
});
},
oneditsave: function() {
this.deviceType = $('#node-input-deviceType').find(":selected").text();
this.deviceName = $('#node-input-deviceId').find(":selected").text();
this.deviceIcon = 'font-awesome/' + $('#node-input-deviceId-icon').attr('class').substring(3);
}
});
</script>
<style>
th { text-align: left; }
</style>
<script type="text/x-red" data-template-name="ikea-homesmart">
<div class="form-row" id="deviceConnection">
<label for="node-input-connection"><i class="fa fa-cog"></i> Connection</label>
<input type="text" id="node-input-connection" placeholder="Connection">
</div>
<div class="form-row" id="deviceType">
<label for="node-input-deviceType"><i class="fa fa-home"></i> Device Type</label>
<div style="display: inline-block; position: relative; width: 70%; height: 20px;">
<div style="position: absolute; left: 0px; right: 40px;">
<select id="node-input-deviceType" style="width: 100%">
<option value="_ADD_" selected>None</option>
<option value="ikea-blinds">Blind</option>
<option value="ikea-lights">Light</option>
<option value="ikea-plugs">Plug</option>
<option value="ikea-sensors">Sensor</option>
<option value="ikea-remotes">Remote</option>
<option value="ikea-groups">Group</option>
</select>
</div>
</div>
</div>
<div class="form-row" id="deviceId">
<label for="node-input-deviceId"><i id="node-input-deviceId-icon" class="fa fa-home"></i> Device</label>
<div style="display: inline-block; position: relative; width: 70%; height: 20px;">
<div style="position: absolute; left: 0px; right: 40px;">
<select id="node-input-deviceId" style="width: 100%">
<option selected>None</option>
</select>
</div>
<a id="node-input-lookup-connection" class="editor-button" style="position: absolute; right: 0px; top: 0px;"><i id="ikea-deviceId-refresh-spinner" class="fa fa-refresh"></i></a>
</div>
</div>
<div class="form-row" id="deviceObserve">
<label> </label>
<input type="checkbox" id="node-input-observe" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-observe" style="width: 70%;" >Observe device?</label>
</div>
<div class="form-row" id="deviceName">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row" id="sceneId">
<label for="node-option-scene"><i class="fa fa-picture-o"></i> Available Scenes</label>
<div style="display: inline-block; position: relative; width: 70%; height: 20px;">
<div style="position: absolute; left: 0px; right: 40px;">
<table id="node-option-scene" style="width:100%">
<tr>
<th>Scene</th>
<th>command</th>
</tr>
</table>
</div>
</div>
</div>
</script>
<script type="text/x-red" data-help-name="ikea-homesmart">
<p>Interface for IKEA smart home devices</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>payload<span class="property-type">string | object</span></dt>
<dd>The payload can either be a single command to the node (such as a status update request) sent as a string or an object with one or more commands targeting the blind.</dd>
</dl>
<h3>Outputs</h3>
<dl class="message-properties">
<dt>payload<span class="property-type">object</span></dt>
<dd>The status of the node.</dd>
<dt>topic<span class="property-type">string</span></dt>
</dl>
<h3>Details</h3>
The ikea-homesmart node can be set to control a blind, light, plug or group.
Nodes can be programmatically controlled by sending a message with <code>msg.payload</code> set to one of the following strings:
<ul>
<li><code>"status"</code> The node will output the current status of its target accessory.
</ul>
<h3>Controlling the blinds</h3>
A blind's position can be controled by sending an object with the following property as <code>msg.payload</code> to the node.
<ul>
<li><code>"position"</code>: number - The position in percent [0..100%].</li>
<li><code>"trigger"</code>: number - A trigger event to stop a moving blind [0.0].</li>
</ul>
<div><pre><code class="language-json">{ "position": number }
{ "trigger": number }</code></pre></div>
<h3>Controlling the lights</h3>
A light represents a single lightbulb and has several properties describing its state. The supported properties depend on the spectrum of the lightbulb.
<strong>All</strong> of them support the most basic properties, which can be controlled by sending an object with one or more of the following properties as <code>msg.payload</code> to the node.
<ul>
<li><code>"dimmer"</code>: number - The brightness in percent [0..100%].</li>
<li><code>"onOff"</code>: boolean - If the lightbulb is on (true) or off (false)</li>
<li><code>"transitionTime"</code>: number - The duration of state changes in seconds. Default 0.5s, not supported for on/off.</li>
</ul>
<strong>White spectrum</strong> lightbulbs also support
<ul>
<li><code>"colorTemperature"</code>: number - The color temperature in percent, where 0% equals cold white and 100% equals warm white.</li>
</ul>
<strong>RGB</strong> lightbulbs have the following properties:
<ul>
<li><code>"color"</code>: string - The 6 digit hex number representing the lightbulb's color. Don't use any prefixes like "#", only the hex number itself!</li>
<li><code>"hue"</code>: number - The color's hue [0..360°].</li>
<li><code>"saturation"</code>: number - The color's saturation [0..100%].</li>
</ul>
<div><pre><code class="language-json">{
"onOff": boolean,
"dimmer": number,
"transitionTime": number,
"colorTemperature": number,
"color": string,
"hue": number,
"saturation": number
}</code></pre></div>
<h3>Controlling the plugs</h3>
A plug represents a single outlet plug and has several properties describing its state.
And one property which can control the plugs by sending an object with the following property as <code>msg.payload</code> to the node.
<ul>
<li><code>"onOff"</code>: boolean - If the plug is on (true) or off (false).</li>
</ul>
<div><pre><code class="language-json">{ "onOff": boolean }</code></pre></div>
<h3>Controlling the groups</h3>
A group contains several devices, usually a remote control and either lightbulbs, plugs or blinds. To control the group send the following properties as <code>msg.payload</code> to the node:
<br>
<strong>For a group of lights</strong>
<ul>
<li><code>"dimmer"</code>: number - The brightness in percent [0..100%].</li>
<li><code>"onOff"</code>: boolean - If the lightbulb is on (true) or off (false)</li>
<li><code>"transitionTime"</code>: number - The duration of state changes in seconds. Default 0.5s, not supported for on/off.</li>
</ul>
Additionally, this property is also supported:
<ul>
<li><code>"sceneId"</code>: number - Set this to the instanceId of a scene (or "mood" as IKEA calls them), to activate it.</li>
</ul>
<div><pre><code class="language-json">{
"onOff": boolean,
"dimmer": number,
"transitionTime": number
}
{
"sceneId": number
}</code></pre></div>
<strong>For a group of blinds</strong>
<ul>
<li><code>"position"</code>: number - The position in percent [0..100%].</li>
<li><code>"trigger"</code>: number - A trigger event to stop a group of moving blinds [0.0].</li>
</ul>
Additionally, this property is also supported:
<ul>
<li><code>"sceneId"</code>: number - Set this to the instanceId of a scene (or "mood" as IKEA calls them), to activate it.</li>
</ul>
<div><pre><code class="language-json">{ "position": number }
{ "trigger": number }
{ "sceneId": number }</code></pre></div>
<strong>For a group of plugs</strong>
<ul>
<li><code>"onOff"</code>: boolean - If the plug is on (true) or off (false)</li>
</ul>
Additionally, this property is also supported:
<ul>
<li><code>"sceneId"</code>: number - Set this to the instanceId of a scene (or "mood" as IKEA calls them), to activate it.</li>
</ul>
<div><pre><code class="language-json">{ "onOff": boolean }
{ "sceneId": number }</code></pre></div>
<h3>Observing</h3>
If the node is set to observe it will send a message with the accessories current properties as <code>msg.payload</code> every time the node is updated or a status request <code>"status"</code> is sent.
<br><br>
<ul>
<li><code>"name"</code>: string - The name of this accessory.</li>
<li><code>"createdAt"</code>: number - The unix timestamp of the creation of the device.</li>
<li><code>"instanceId"</code>: number - The ID under which the accessory is known to the gateway.</li>
<li><code>"type"</code>: number - The type of the accessory.</li>
<ul>
<li>remote (0) - A "normal" remote</li>
<li>slaveRemote (1) - A remote which has been paired with another remote. You can find details here on how to achieve this configuration.</li>
<li>lightbulb (2) - A lightbulb</li>
<li>plug (3) - A smart plug</li>
<li>motionSensor (4) - A motion sensor</li>
<li>signalRepeater (6) - A signal repeater</li>
<li>blind (7) - A blind</li>
</ul>
<li><code>"alive"</code>: boolean - Whether the gateway considers this device as alive.</li>
<li><code>"lastSeen"</code>: number - The unix timestamp of the last communication with the gateway.</li>
<li><code>"otaUpdateState"</code>: number - Unknown. Might be a boolean</li>
<li><code>"deviceInfo"</code>: object - Some additional information about the device.</li>
<ul>
<li><code>"firmwareVersion"</code>: string - The firmware version of the device.</li>
<li><code>"manufacturer"</code>: string - The device manufacturer.</li>
<li><code>"modelNumber"</code>: string - The name/type of the device.</li>
<li><code>"power"</code>: number - How the device is powered.</li>
<ul>
<li>Unknown (0)</li>
<li>InternalBattery (1)</li>
<li>ExternalBattery (2)</li>
<li>Battery (3) - Although not in the specs, this is apparently used by the remote</li>
<li>PowerOverEthernet (4)</li>
<li>USB (5)</li>
<li>AC_Power (6)</li>
<li>Solar (7)</li>
</ul>
<li><code>"serialNumber"</code>: string - Not used currently. Always ""</li>
<li><code>"battery"</code>: number - The battery percentage of a device. Only present if the device is battery-powered.</li>
</ul>
<li><code>"blindList"</code>: array - An array of all blinds belonging to this accessory.</li>
<ul>
<li><code>"position"</code>: number - The position in percent [0..100%].</li>
</ul>
<li><code>"lightList"</code>: array - An array of all lights belonging to this accessory.</li>
<ul>
<li><code>"onOff"</code>: boolean - If the lightbulb is on (true) or off (false)</li>
<li><code>"dimmer"</code>: number - The brightness in percent [0..100%].</li>
<li><code>"transitionTime"</code>: number - The duration of state changes in seconds. Default 0.5s, not supported for on/off.</li>
<li><code>"colorTemperature"</code>: number - The color temperature in percent, where 0% equals cold white and 100% equals warm white.</li>
<li><code>"color"</code>: string - The 6 digit hex number representing the lightbulb's color.</li>
<li><code>"colorX"</code>: number - The x component of the xy-color</li>
<li><code>"colorY"</code>: number - The y component of the xy-color</li>
<li><code>"hue"</code>: number - The color's hue [0..360°].</li>
<li><code>"saturation"</code>: number - The color's saturation [0..100%].</li>
</ul>
<li><code>"plugList"</code>: array - An array of all plugs belonging to this accessory.</li>
<ul>
<li><code>"onOff"</code>: boolean - If the plug is on (true) or off (false).</li>
<li><code>"isSwitchable"</code>: boolean - Whether the plug supports on/off (always true).</li>
<li><code>"isDimmable"</code>: boolean - Whether the plug supports setting the dimmer value (always false for now).</li>
</ul>
<li><code>"sensorList"</code>: array - An array of all sensors belonging to this accessory.</li>
<ul>
<li><code>"name"</code>: string - Currently not supported.</li>
<li><code>"createdAt"</code>: number - Currently not supported.</li>
<li><code>"instanceId"</code>: number - Currently not supported.</li>
<li><code>"appType"</code>: string - Currently not supported.</li>
<li><code>"sensorType"</code>: string - Currently not supported.</li>
<li><code>"minMeasuredValue"</code>: number - Currently not supported.</li>
<li><code>"maxMeasuredValue"</code>: number - Currently not supported.</li>
<li><code>"minRangeValue"</code>: number - Currently not supported.</li>
<li><code>"maxRangeValue"</code>: number - Currently not supported.</li>
<li><code>"resetMinMaxMeasureValue"</code>: boolean - Currently not supported.</li>
<li><code>"sensorValue"</code>: number - Currently not supported.</li>
<li><code>"unit"</code>: string - Currently not supported.</li>
</ul>
<li><code>"switchList"</code>: array - An array of all remotes belonging to this accessory.</li>
<ul>
<li><code>"name"</code>: string - Currently not supported.</li>
<li><code>"createdAt"</code>: number - Currently not supported.</li>
<li><code>"instanceId"</code>: number - Currently not supported.</li>
</ul>
</ul>
Currently observing the control of a group is not possible, due to the gateway only reporting changes to every single device.
If a group is renamed, a device removed or added to it, a scene redefined or
manually a status request sent to the node, it will respond with a <code>msg.payload</code> containing the groups current properties.
<br><br>
<ul>
<li><code>"name"</code>: string - The name of this group.</li>
<li><code>"createdAt"</code>: number - The unix timestamp of the creation of the group.</li>
<li><code>"instanceId"</code>: number - The ID under which the group is known to the gateway.</li>
<li><code>"onOff"</code>: boolean - If the group is on (true) or off (false)
<li><code>"dimmer</code>: number - The brightness in percent [0..100%].
<li><code>"deviceIDs</code>: object - An array of all instanceIds of the devices in this group.</li>
<li><code>"sceneId</code>: number - the instanceId of the current scene (or "mood" as IKEA calls them).</li>
<li><code>"groupType"</code>: number - The type of the group.</li>
</ul>
</script>