forked from estbeetoo/node-red-contrib-openzwave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10-zwave.html
687 lines (647 loc) · 34.8 KB
/
10-zwave.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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
<!--
OpenZWave nodes for IBM's Node-Red
https://github.com/ekarak/node-red-contrib-openzwave
(c) 2014, Elias Karakoulakis <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/x-red" data-template-name="zwave-controller">
<div class="form-row">
<label for="node-config-input-port"><i class="icon-bookmark"></i> Port</label>
<input type="text" id="node-config-input-port" style="width:60%;" data-i18n="[placeholder]serial.placeholder.port">
<a id="node-config-lookup-serial" class="btn"><i id="node-config-lookup-serial-icon" class="fa fa-search"></i></a>
</div>
<div class="form-row">
<label for="homeid"><i class="icon-bookmark"></i> HomeID</label>
<input type="text" id="homeid" disabled="true" size="16">
</div>
<div class="form-row">
<label for="node-config-input-driverattempts"><i class="icon-bookmark"></i> Driver attempts</label>
<input type="text" id="node-config-input-driverattempts">
</div>
<div class="form-row">
<label for="node-config-input-pollinterval"><i class="icon-bookmark"></i> Poll interval (ms)</label>
<input type="text" id="node-config-input-pollinterval" placeholder="10000 ms">
</div>
<div class="form-row">
<label for="node-config-input-allowunreadyupdates" style="vertical-align: top"><i class="icon-bookmark"></i> Pre-wake Updates</label>
<input type="checkbox" id="node-config-input-allowunreadyupdates" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-config-input-allowunreadyupdates" style="width: 70%;">Allow updates from devices not fully scanned?</label>
</div>
<div class="form-row">
<label for="node-config-input-logging" style="vertical-align: top"><i class="icon-bookmark"></i> Logging</label>
<select id="node-config-input-logging" style="width:70%">
<option value="0">No Logging</option>
<option value="1">All Messages</option>
<option value="2">Fatal Messages Only</option>
<option value="3">Error Messages and Higher</option>
<option value="4">Warning Messages and Higher</option>
<option value="5">Alert Messages and Higher</option>
<option value="6">Info Messages and Higher</option>
<option value="7">Detailed Messages and Higher</option>
<option value="8">Debug Messages and Higher</option>
<option value="9">Protocol Information and Higher</option>
</select>
</div>
<div class="form-row">
<input id="node-config-add-node" type="button" value="Add node" style="margin-right: 5px; width: 100px;"/>
<input id="node-config-remove-node" type="button" value="Remove node" style="margin-right: 5px; width: 120px;"/>
<input id="node-config-remove-dead-nodes" type="button" value="Remove dead nodes" style="margin-right: 5px; width: 170px;"/>
<input id="node-config-cancel-add-remove" type="button" value="Cancel Add/Remove node" style="width: 200px;"/>
<input id="node-config-soft-reset" type="button" value="SoftReset" style="width: 200px;"/>
<input id="node-config-heal-network" type="button" value="HealNetwork" style="width: 200px;"/>
</div>
<div class="form-row node-config-container-row" style="margin-bottom: 0px;">
<input id="node-config-refresh-nodes" type="button" value="Refresh" style="width: 100px;"/><br/>
<div id="node-config-container-div" style="box-sizing: border-box; border-radius: 5px; height: 310px; padding: 5px; border: 1px solid #ccc; overflow-y:scroll;">
<ol id="node-config-container" style=" list-style-type:none; margin: 0;"></ol>
</div>
</div>
</script>
<script type="text/x-red" data-template-name="zwave-in">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Node Name</label>
<input type="text" id="node-input-name" placeholder="ZWave command">
</div>
<div class="form-row">
<label for="node-input-controller"><i class="icon-bookmark"></i> Controller</label>
<input type="text" id="node-input-controller">
</div>
</script>
<script type="text/x-red" data-template-name="zwave-out">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Node Name</label>
<input type="text" id="node-input-name" placeholder="ZWave status">
</div>
<div class="form-row">
<label for="node-input-controller"><i class="icon-bookmark"></i> Controller</label>
<input type="text" id="node-input-controller">
</div>
</script>
<script type="text/x-red" data-template-name="zwave-cmd">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Node Name</label>
<input type="text" id="node-input-name" placeholder="ZWave status">
</div>
<div class="form-row">
<label for="node-input-controller"><i class="icon-bookmark"></i> Controller</label>
<input type="text" id="node-input-controller">
</div>
<div class="form-row">
<label for="node-input-topic"><i class="icon-bookmark"></i> Topic</label>
<select id="node-input-topic">
<option value=""><i>use msg.topic</i></option>
<option value="setConfigParam">setConfigParam</option>
<option value="requestConfigParam">requestConfigParam</option>
<option value="requestAllConfigParams">requestAllConfigParams</option>
<option value="hardReset">hardReset</option>
<option value="softReset">softReset</option>
<option value="getControllerNodeId">getControllerNodeId</option>
<option value="getSUCNodeId">getSUCNodeId</option>
<option value="isPrimaryController">isPrimaryController</option>
<option value="isStaticUpdateController">isStaticUpdateController</option>
<option value="isBridgeController">isBridgeController</option>
<option value="getLibraryVersion">getLibraryVersion</option>
<option value="getLibraryTypeName">getLibraryTypeName</option>
<option value="getSendQueueCount">getSendQueueCount</option>
<option value="connect">connect</option>
<option value="disconnect">disconnect</option>
<option value="getNumGroups">getNumGroups</option>
<option value="getAssociations">getAssociations</option>
<option value="getMaxAssociations">getMaxAssociations</option>
<option value="getGroupLabel">getGroupLabel</option>
<option value="addAssociation">addAssociation</option>
<option value="removeAssociation">removeAssociation</option>
<option value="addNode">addNode</option>
<option value="removeNode">removeNode</option>
<option value="removeFailedNode">removeFailedNode</option>
<option value="hasNodeFailed">hasNodeFailed</option>
<option value="requestNodeNeighborUpdate">requestNodeNeighborUpdate</option>
<option value="assignReturnRoute">assignReturnRoute</option>
<option value="deleteAllReturnRoutes">deleteAllReturnRoutes</option>
<option value="sendNodeInformation">sendNodeInformation</option>
<option value="createNewPrimary">createNewPrimary</option>
<option value="receiveConfiguration">receiveConfiguration</option>
<option value="replaceFailedNode">replaceFailedNode</option>
<option value="transferPrimaryRole">transferPrimaryRole</option>
<option value="requestNetworkUpdate">requestNetworkUpdate</option>
<option value="replicationSend">replicationSend</option>
<option value="createButton">createButton</option>
<option value="deleteButton">deleteButton</option>
<option value="beginControllerCommand">beginControllerCommand</option>
<option value="cancelControllerCommand">cancelControllerCommand</option>
<option value="testNetworkNode">testNetworkNode</option>
<option value="testNetwork">testNetwork</option>
<option value="healNetworkNode">healNetworkNode</option>
<option value="healNetwork">healNetwork</option>
<option value="setNodeOn">setNodeOn</option>
<option value="setNodeOff">setNodeOff</option>
<option value="setNodeLevel">setNodeLevel</option>
<option value="switchAllOn">switchAllOn</option>
<option value="switchAllOff">switchAllOff</option>
<option value="pressButton">pressButton</option>
<option value="refreshNodeInfo">refreshNodeInfo</option>
<option value="requestNodeState">requestNodeState</option>
<option value="requestNodeDynamic">requestNodeDynamic</option>
<option value="getNodeLocation">getNodeLocation</option>
<option value="setNodeLocation">setNodeLocation</option>
<option value="getNodeName">getNodeName</option>
<option value="setNodeName">setNodeName</option>
<option value="getNodeManufacturerName">getNodeManufacturerName</option>
<option value="setNodeManufacturerName">setNodeManufacturerName</option>
<option value="getNodeProductName">getNodeProductName</option>
<option value="setNodeProductName">setNodeProductName</option>
<option value="getNodeMaxBaudRate">getNodeMaxBaudRate</option>
<option value="getNodeVersion">getNodeVersion</option>
<option value="getNodeBasic">getNodeBasic</option>
<option value="getNodeGeneric">getNodeGeneric</option>
<option value="getNodeManufacturerId">getNodeManufacturerId</option>
<option value="getNodeNeighbors">getNodeNeighbors</option>
<option value="getNodeProductId">getNodeProductId</option>
<option value="getNodeProductType">getNodeProductType</option>
<option value="getNodeSecurity">getNodeSecurity</option>
<option value="getNodeSpecific">getNodeSpecific</option>
<option value="getNodeType">getNodeType</option>
<option value="isNodeListeningDevice">isNodeListeningDevice</option>
<option value="isNodeFrequentListeningDevice">isNodeFrequentListeningDevice</option>
<option value="isNodeBeamingDevice">isNodeBeamingDevice</option>
<option value="isNodeRoutingDevice">isNodeRoutingDevice</option>
<option value="isNodeSecurityDevice">isNodeSecurityDevice</option>
<option value="setValue">setValue</option>
<option value="refreshValue">refreshValue</option>
<option value="setChangeVerified">setChangeVerified</option>
<option value="getNumSwitchPoints">getNumSwitchPoints</option>
<option value="clearSwitchPoints">clearSwitchPoints</option>
<option value="getSwitchPoint">getSwitchPoint</option>
<option value="setSwitchPoint">setSwitchPoint</option>
<option value="removeSwitchPoint">removeSwitchPoint</option>
<option value="enablePoll">enablePoll</option>
<option value="disablePoll">disablePoll</option>
<option value="isPolled">isPolled</option>
<option value="getPollInterval">getPollInterval</option>
<option value="setPollInterval">setPollInterval</option>
<option value="getPollIntensity">getPollIntensity</option>
<option value="setPollIntensity">setPollIntensity</option>
<option value="createScene">createScene</option>
<option value="removeScene">removeScene</option>
<option value="getScenes">getScenes</option>
<option value="addSceneValue">addSceneValue</option>
<option value="removeSceneValue">removeSceneValue</option>
<option value="sceneGetValues">sceneGetValues</option>
<option value="activateScene">activateScene</option>
</select>
</div>
</script>
<!-- ============================================================================================== -->
<script type="text/x-red" data-help-name="zwave-controller">
<ul>
<li><b><i class="icon-bookmark"></i> Port:</b>
The serial port your ZWave controller stick is attached to. Usual values:
<pre>/dev/ttyUSB0</pre> in Linux, <pre>/dev/cu.usbmodem1411</pre> in MacOSX, <pre>\\\\.\\COM3</pre> in Windows.
</li>
<li><b><i class="icon-bookmark"></i> Driver attempts:</b>
How many attempts should OpenZWave make to set up the controller.
</li>
<li><b><i class="icon-bookmark"></i> Poll interval:</b>
How often to poll devices that do not offer automatic feedback on their status, in milliseconds.
</li>
<li><b><i class="icon-bookmark"></i> Pre-wake Updates:</b>
Allow updates from devices before OpenZWave has finished initialising
</li>
<li><b><i class="icon-bookmark"></i> Logging:</b>
Set the logging level for OpenZWave lib
Please note that a Node-Red restart is required for OpenZWave to pick up any changes in the logging level.
</li>
</ul>
</script>
<script type="text/x-red" data-help-name="zwave-in">
<p><b>Input node for ZWave events.</b><br/>
Fires node-red events when a ZWave ValueID is changed. See OpenZWave documentation on ValueIDs.</p>
</script>
<script type="text/x-red" data-help-name="zwave-out">
<p><b>Output node for ZWave commands.</b><br/>
Use this to control individual ZWave devices. See OpenZWave documentation on ValueIDs.<br/>
<b>msg.topic</b> can be: <b>setLevel, setValue, switchOn, switchOff, setConfigParam, requestConfigParam, requestAllConfigParams</b><br/>
<b>msg.payload</b> has these sub-elements:<br/>
<br/> <b>msg.payload.nodeId: (REQUIRED for all topics)</b> zwave node to send the command (eg. 2)
<br/> <b>msg.payload.cmdclass</b>(default:37) OZW command class in decimal (eg. 37 for switches, 38 for dimmers)
<br/> <b>msg.payload.cmdidx</b>(default: 0) command index (0 for most command classes, see OZW/Value.cpp)
<br/> <b>msg.payload.instance</b>(default: 1) for multi-instance devices (like FGS-211)
<br/> <b>msg.payload.value</b>(default: 0) value to set (eg. 0/1 for switches, 100 to set dimmers to 100% etc)
<br/>
<b>msg.payload</b> has these sub-elements for setConfigParam action:<br/>
<br/> <b>msg.payload.nodeId: (REQUIRED for all topics)</b> zwave node to send the command (eg. 2)
<br/> <b>msg.payload.paramId: (REQUIRED for all topics)</b> configuration parameter number (decimal index)
<br/> <b>msg.payload.paramValue (or msg.payload.value)</b>(default: 0) value to set (eg. 0/1 for switches, 100 to set dimmers to 100% etc)
<br/>
<b>msg.payload</b> has these sub-elements for requestConfigParam action:<br/>
<br/> <b>msg.payload.nodeId: (REQUIRED for all topics)</b> zwave node to send the command (eg. 2)
<br/> <b>msg.payload.paramId: (REQUIRED for all topics)</b> configuration parameter number (decimal index)
</p>
<b>msg.payload</b> has this sub-element for requestAllConfigParams action:<br/>
<br/> <b>msg.payload.nodeId: (REQUIRED for all topics)</b> zwave node to send the command (eg. 2)
</p>
<p>
<b>EXPERIMENTAL:</b> Any other topic command is send basically every available command down
to OpenZWave, just name the function in the message topic
and pass in the arguments as "payload.args" as an array:
{"topic": "someOpenZWaveCommand", "payload": {"args": [1, 2, 3]}}
If the command needs the HomeID as the 1st arg, use "payload.prependHomeId"
</p>
</script>
<script type="text/x-red" data-help-name="zwave-cmd">
<p>
<b>Function node for directly calling OpenZWave functions.</b><br/>
Directly call OpenZWave functions<br/>
<b>msg.topic</b> is the name of the function, if not set in the node settings.<br/>
<b>msg.payload.args</b> must be an array containing the function call arguments, in the correct order.<br/>
<b>msg.payload.prependHomeId</b> If the command needs the HomeID as the 1st arg, set this to <i>true</i>
</p>
<p>
The Node-Red message payload should contain an array of the command arguments **in the correct order**.<br/>
For example:
* to **add a new ZWave node** to your network, you need to prepend the ZWave Home ID to the `addNode()` management call as follows:
`{"topic": "addNode", "payload": {"prependHomeId": true}}`
* to **enable polling** for ZWave node #5 for the on-off command class (0x25 == decimal 37). Notice that the [EnablePoll() command](http://www.openzwave.com/dev/classOpenZWave_1_1Manager.html#a50d795cb20a0bea55ecfd4a02c9777f3) does **not** need a HomeId as an argument, hence we don't need to add `prependHomeId` to the message payload:
`{"topic": "enablePoll", "payload": {"args": [5, 37]}}`
* to get **a node's statistics** by using the `getNodeStatistics()` call:
`{"topic": "getNodeStatistics", "payload": {"args": [2]}}`
</script>
<script type="text/javascript">
var ZWAVE_CLASSES = {
32: 'BASIC',
33: 'CONTROLLER REPLICATION',
34: 'APPLICATION STATUS',
35: 'ZIP SERVICES',
36: 'ZIP SERVER',
37: 'SWITCH BINARY',
38: 'SWITCH MULTILEVEL',
39: 'SWITCH ALL',
40: 'SWITCH TOGGLE BINARY',
41: 'SWITCH TOGGLE MULTILEVEL',
42: 'CHIMNEY FAN',
43: 'SCENE ACTIVATION',
44: 'SCENE ACTUATOR CONF',
45: 'SCENE CONTROLLER CONF',
46: 'ZIP CLIENT',
47: 'ZIP ADV SERVICES',
48: 'SENSOR BINARY',
49: 'SENSOR MULTILEVEL',
50: 'METER',
51: 'ZIP ADV SERVER',
52: 'ZIP ADV CLIENT',
53: 'METER PULSE',
60: 'METER TBL CONFIG',
61: 'METER TBL MONITOR',
62: 'METER TBL PUSH',
56: 'THERMOSTAT HEATING',
64: 'THERMOSTAT MODE',
66: 'THERMOSTAT OPERATING STATE',
67: 'THERMOSTAT SETPOINT',
68: 'THERMOSTAT FAN MODE',
69: 'THERMOSTAT FAN STATE',
70: 'CLIMATE CONTROL SCHEDULE',
71: 'THERMOSTAT SETBACK',
74: 'TARIF CONFIG',
75: 'TARIF TABLE MONITOR',
76: 'COMMAND CLASS DOOR LOCK LOGGING',
78: 'SCHEDULE ENTRY LOCK',
79: 'ZIP 6LOWPAN',
80: 'BASIC WINDOW COVERING',
81: 'MTP WINDOW COVERING',
96: 'MULTI INSTANCE',
98: 'DOOR LOCK',
99: 'USER CODE',
112: 'CONFIGURATION',
113: 'ALARM',
114: 'MANUFACTURER SPECIFIC',
115: 'POWER LEVEL',
117: 'PROTECTION',
118: 'LOCK',
119: 'NODE NAMING',
122: 'FIRMWARE UPDATE MD',
123: 'GROUPING NAME',
124: 'REMOTE ASSOCIATION ACTIVATE',
125: 'REMOTE ASSOCIATION',
128: 'BATTERY',
129: 'CLOCK',
130: 'HAIL',
132: 'WAKE UP',
133: 'ASSOCIATION',
134: 'VERSION',
135: 'INDICATOR',
136: 'PROPRIETARY',
137: 'LANGUAGE',
138: 'TIME',
139: 'TIME PARAMETERS',
140: 'GEOGRAPHIC LOCATION',
141: 'COMPOSITE',
142: 'MULTI INSTANCE ASSOCIATION',
143: 'MULTI CMD',
144: 'ENERGY PRODUCTION',
145: 'MANUFACTURER PROPRIETARY',
146: 'SCREEN MD',
147: 'SCREEN ATTRIBUTES',
148: 'SIMPLE AV CONTROL',
149: 'AV CONTENT DIRECTORY MD',
150: 'AV RENDERER STATUS',
151: 'AV CONTENT SEARCH MD',
152: 'SECURITY',
153: 'AV TAGGING MD',
154: 'IP CONFIGURATION',
155: 'ASSOCIATION COMMAND CONFIGURATION',
156: 'SENSOR ALARM',
157: 'SILENCE ALARM',
158: 'SENSOR CONFIGURATION',
239: 'MARK',
240: 'NON INTEROPERABLE'
}
RED.nodes.registerType('zwave-controller', {
category: 'config',
defaults: {
name: {value: ""},
port: {value: "/dev/ttyUSB0", required: true},
driverattempts: {value: 3, required: true, validate: RED.validators.number()},
pollinterval: {value: 10000, required: true, validate: RED.validators.number()},
allowunreadyupdates: {value: false, required:true},
logging: {value: 0, required: false},
},
label: function () {
return ("openzwave@" + this.port);
},
oneditprepare: function () {
var node = this;
var index = 0;
function getNodes() {
$('#node-config-refresh-nodes').val('Loading...');
$('#node-config-refresh-nodes').prop("disabled", true);
$.ajax({
url: "openzwave/" + node.id + "/list_nodes",
type: "POST",
success: function (resp) {
clearZNodeList();
for (var znodeid in resp) {
fillZNodeList(znodeid, resp[znodeid]);
}
RED.notify(node._("openzwave.success", {label: 'list_nodes'}), "success");
$('#node-config-refresh-nodes').val('Refresh');
$('#node-config-refresh-nodes').prop("disabled", false);
},
error: function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 404) {
RED.notify(node._("common.notification.error", {message: node._("common.notification.errors.not-deployed")}), "error");
} else if (jqXHR.status == 500) {
RED.notify(node._("common.notification.error", {message: node._("openzwave.errors.failed")}), "error");
} else if (jqXHR.status == 0) {
RED.notify(node._("common.notification.error", {message: node._("common.notification.errors.no-response")}), "error");
} else {
RED.notify(node._("common.notification.error", {
message: node._("common.notification.errors.unexpected", {
status: jqXHR.status,
message: textStatus
})
}), "error");
}
}
});
}
function getHomeID() {
$('#homeid').val('Loading...');
$.ajax({
url: "openzwave/" + node.id + "/get_homeid",
type: "POST",
success: function (resp) {
$('#homeid').val(resp.name + ' (' + resp.homeid + ')');
RED.notify(node._("openzwave.success", {label: 'get_homeid'}), "success");
},
error: function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 404) {
RED.notify(node._("common.notification.error", {message: node._("common.notification.errors.not-deployed")}), "error");
} else if (jqXHR.status == 500) {
RED.notify(node._("common.notification.error", {message: node._("openzwave.errors.failed")}), "error");
} else if (jqXHR.status == 0) {
RED.notify(node._("common.notification.error", {message: node._("common.notification.errors.no-response")}), "error");
} else {
RED.notify(node._("common.notification.error", {
message: node._("common.notification.errors.unexpected", {
status: jqXHR.status,
message: textStatus
})
}), "error");
}
}
});
}
function bindSend(id, cmd) {
$('#' + id).click(function () {
$.ajax({
url: "openzwave/" + node.id + "/" + cmd,
type: "POST",
success: function (resp) {
RED.notify(node._("openzwave.success", {label: cmd}), "success");
getNodes();
setTimeout(getNodes, 10000);
},
error: function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 404) {
RED.notify(node._("common.notification.error", {message: node._("common.notification.errors.not-deployed")}), "error");
} else if (jqXHR.status == 500) {
RED.notify(node._("common.notification.error", {message: node._("openzwave.errors.failed")}), "error");
} else if (jqXHR.status == 0) {
RED.notify(node._("common.notification.error", {message: node._("common.notification.errors.no-response")}), "error");
} else {
RED.notify(node._("common.notification.error", {
message: node._("common.notification.errors.unexpected", {
status: jqXHR.status,
message: textStatus
})
}), "error");
}
}
});
});
}
function clearZNodeList() {
$("#node-config-container").empty();
index = 0;
}
function fillZNodeList(znodeid, znode) {
var container = $('<li/>', {style: "background: #fff; margin:0; padding:8px 0px; border-bottom: 1px solid #ccc;"});
var row = $('<div/>').appendTo(container);
var classesField = $('<a href="#" class="editor-button editor-button-small" style="width: 60px; height: 34px; position: relative; line-height: 34px; font-size: 12px;"><span data-i18n="openzwave.label.classes">classes</span></a>').appendTo(row);
classesField.click(function () {
var zclasses_html = $('<table class="table table-bordered table-striped"><tr><th>class</th><th>label</th><th>type</th><th>instance : index</th><th>permission</th><th>polled</th><th>min:max</th><th>value (in units)</th></tr></table>');
var zclass;
var zclass_tr;
for (var classId in znode.classes)
for (var classInstance in znode.classes[classId])
for (var classIndex in znode.classes[classId][classInstance]) {
zclass = znode.classes[classId][classInstance][classIndex];
if (!zclass) {
zclass_tr = $('<tr><td colspan="8">' + JSON.stringify(znode.classes[classId]) + '</td></tr>');
zclasses_html.append(zclass_tr);
continue;
}
zclass_tr = $('<tr></tr>');
zclass_tr.append('<td>' + (ZWAVE_CLASSES[zclass.class_id] ? ('(' + zclass.class_id + ') ' + ZWAVE_CLASSES[zclass.class_id]) : ('(' + zclass.class_id + ')') ) + '</td>')
zclass_tr.append('<td>' + zclass.label + '</td>')
zclass_tr.append('<td>' + zclass.type + '</td>')
zclass_tr.append('<td>' + zclass.instance + ':' + zclass.index + '</td>')
zclass_tr.append('<td>read_only:' + zclass.read_only + '<br/>write_only:' + zclass.write_only + '</td>')
zclass_tr.append('<td>polled:' + zclass.is_polled + '</td>')
var valueTD = $('<td>Value: ' + zclass.value + ' ' + zclass.units + '</td>');
if (zclass.values) {
valueTD.append('<br/>Allowed values:<br/><ul>');
for (var valueKey in zclass.values)
valueTD.append('<li>' + zclass.values[valueKey] + '</li>');
valueTD.append('</ul>');
}
zclass_tr.append('<td>min: ' + zclass.min + ', max: ' + zclass.max + '</td>')
zclass_tr.append(valueTD);
zclasses_html.append(zclass_tr);
}
var dialogContent = $('<div id="node-additional-dialog" class="hide ui-dialog-content ui-widget-content" style="display: block; width: auto; min-height: 150px; max-height: none; height: auto;">');
dialogContent.append(zclasses_html);
dialogContent.dialog({
autoOpen: true,
title: 'ZWave classes of node[id:' + znodeid + ']',
width: '700px'
});
});
var nodeidField = $('<input/>', {
class: "node-config-container-nodeid",
type: "text",
disabled: "true",
style: "margin-left: 5px; width: 25px;",
placeholder: "NodeId "
}).appendTo(row);
var typeField = $('<input/>', {
class: "node-config-container-type",
type: "text",
disabled: "true",
style: "margin-left: 5px; width: 200px;",
placeholder: "Type "
}).appendTo(row);
var manufacturerField = $('<input/>', {
class: "node-config-container-manufacturer",
type: "text",
disabled: "true",
style: "margin-left: 5px; width: 100px;",
placeholder: "Manufacturer "
}).appendTo(row);
var availField = $('<input/>', {
class: "node-config-container-available",
type: "text",
disabled: "true",
style: "margin-left: 5px; width: 65px;",
placeholder: "Available "
}).appendTo(row);
var readyField = $('<input/>', {
class: "node-config-container-ready",
type: "text",
disabled: "true",
style: "margin-left: 5px; width: 65px;",
placeholder: "Ready "
}).appendTo(row);
var aliveField = $('<input/>', {
class: "node-config-container-alive",
type: "text",
disabled: "true",
style: "margin-left: 5px; width: 65px;",
placeholder: "Alive "
}).appendTo(row);
var finalspan = $('<span/>', {style: "float: right;margin-right: 10px;"}).appendTo(row);
finalspan.append('<span class="node-config-container-index">' + ( ++index) + '</span> ');
$("#node-config-container").append(container);
nodeidField.val(znodeid);
typeField.val(znode.type);
manufacturerField.val(znode.manufacturer);
availField.val('avail['+(znode.available ? 't' : 'f')+']');
readyField.val('ready['+(znode.ready ? 't' : 'f')+']');
aliveField.val(znode.alive ? 'alive' : 'dead');
}
bindSend('node-config-add-node', 'add');
bindSend('node-config-remove-node', 'remove');
bindSend('node-config-remove-dead-nodes', 'remove_dead');
bindSend('node-config-cancel-add-remove', 'cancel');
bindSend('node-config-soft-reset', 'soft_reset');
bindSend('node-config-heal-network', 'heal_network');
$('#node-config-refresh-nodes').click(getNodes);
getHomeID();
getNodes();
try {
$("#node-config-input-port").autocomplete( "destroy" );
} catch(err) {
}
$("#node-config-lookup-serial").click(function() {
//$("#node-config-lookup-serial-icon").removeClass('fa fa-search');
//$("#node-config-lookup-serial-icon").addClass('fa fa-spinner');
$("#node-config-lookup-serial").addClass('disabled');
$.getJSON('openzwaveports',function(data) {
//$("#node-config-lookup-serial-icon").addClass('fa fa-search');
//$("#node-config-lookup-serial-icon").removeClass('fa fa-spinner');
$("#node-config-lookup-serial").removeClass('disabled');
var ports = [];
$.each(data, function(i, port){
ports.push(port.comName);
});
$("#node-config-input-port").autocomplete({
source:ports,
minLength:0,
close: function( event, ui ) {
$("#node-config-input-port").autocomplete( "destroy" );
}
}).autocomplete("search","");
});
});
}
});
RED.nodes.registerType('zwave-in', {
category: 'home automation',
color: 'pink',
defaults: {
name: {value: ""},
controller: {value: "", type: "zwave-controller"},
},
inputs: 0,
outputs: 1,
icon: "zwave.png",
label: function () {
return (this.name || "zwave-in");
}
});
RED.nodes.registerType('zwave-out', {
category: 'home automation',
color: 'pink',
defaults: {
name: {value: ""},
controller: {value: "", type: "zwave-controller"},
},
inputs: 1,
outputs: 0,
icon: "zwave.png",
label: function () {
return (this.name || "zwave-out");
}
});
RED.nodes.registerType('zwave-cmd',{
category:'home automation',
color: 'pink',
defaults: {
name: {value:""},
controller: {value:"", type:"zwave-controller"},
topic: {value:""}
},
inputs:1,
outputs:1,
icon: "zwave.png",
label: function() { return (this.name || this.topic || "zwave-cmd"); }
});
</script>