This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
77-openhab2.html
800 lines (766 loc) · 30.9 KB
/
77-openhab2.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
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
<!--
openHAB nodes for IBM's Node-Red
https://github.com/pdmangel/node-red-contrib-openhab2
(c) 2017, Peter De Mangelaere <peter.demangelaere@gmail.com>
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="openhab2-controller2">
<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" placeholder="Name">
</div>
<div class="form-row">
<label for="node-config-input-protocol"><i class="fa fa-unlock-alt"></i> Protocol</label>
<select id="node-config-input-protocol" name="node-config-input-protocol" style="width: 250px;">
<option value="http">http</option>
<option value="https">https</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-host"><i class="fa fa-globe"></i> Host</label>
<input type="text" id="node-config-input-host">
</div>
<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">
</div>
<div class="form-row">
<label for="node-config-input-path"><i class="fa fa-chevron-right"></i> Path</label>
<input type="text" id="node-config-input-path">
</div>
<div class="form-row">
<label for="node-config-input-username"><i class="fa fa-user"></i> Username</label>
<input type="text" id="node-config-input-username">
</div>
<div class="form-row">
<label for="node-config-input-password"><i class="fa fa-user-secret"></i> Password</label>
<input type="password" id="node-config-input-password">
</div>
<div class="form-row">
<label for="node-config-input-ohversion"><i class="fa fa-unlock-alt"></i>openHAB version</label>
<select id="node-config-input-ohversion" name="node-config-input-ohversion" style="width: 250px;">
<option value="v2">v1 and v2</option>
<option value="v3">v3</option>
</select>
</div>
<div class="form-row node-token">
<label for="node-config-input-token"><i class="fa fa-user-secret"></i> OAuth2 Bearer token</label>
<input type="password" id="node-config-input-token">
</div>
</script>
<script type="text/x-red" data-template-name="openhab2-in2">
<style type="text/css">
.btn-group {
width: 70%;
}
.multiselect {
width: 100%;
}
.form-row input.multiselect-search {
width: 100%;
}
.multiselect-clear-filter {
display: none;
}
.dropdown-menu {
width: 100% !important;
}
.multiselect-container input[type="checkbox"] {
display: none;
}
.multiselect-container > li > a > label.radio {
margin: 5px;
width: 90%;
height: 100%;
cursor: pointer;
font-weight: 400;
padding: 3px 20px 3px 20px;
}
.multiselect-container label.radio input[type="radio"] {
display: none;
}
</style>
<link rel="stylesheet" href="static/css/bootstrap-multiselect.css" type="text/css" />
<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>
<div class="form-row">
<label for="node-input-controller"><i class="fa fa-globe"></i> Controller</label>
<input type="text" id="node-input-controller">
</div>
<div class="form-row">
<label for="node-input-itemname"><i class="fa fa-crosshairs"></i> ItemName</label>
<select id="node-input-itemname" name="node-input-itemname">
</select>
</div>
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
<input type="text" id="node-input-topic" name="node-input-topic" style="width: 250px;">
</div>
<div class="form-tips">
An 'InitialStateEvent'-typed message (when selected below) will be send whenever this node is (re-)initialised, but also whenever the controller reconnects to the openHAB server.
</div>
<div class="form-row">
<label for="node-input-initialstate"><i class="fa fa-crosshairs"></i> Send initial<br/>(<code>InitialStateEvent</code>)</label>
<input type="checkbox" id="node-input-initialstate" style="display: inline-block; width: auto; vertical-align: top;">
</input>
</div>
<div class="form-row">
<label for="node-input-whenupdated"><i class="fa fa-crosshairs"></i> Send updated<br/>(<code>ItemStateEvent</code>)</label>
<input type="checkbox" id="node-input-whenupdated" style="display: inline-block; width: auto; vertical-align: top;">
</input>
</div>
<div class="form-row">
<label for="node-input-whencommand"><i class="fa fa-crosshairs"></i> Send command<br/>(<code>ItemCommandEvent</code>)</label>
<input type="checkbox" id="node-input-whencommand" style="display: inline-block; width: auto; vertical-align: top;">
</input>
</div>
<div class="form-row">
<label for="node-input-whenchanged"><i class="fa fa-crosshairs"></i> Send changed<br/>(<code>ItemStateChangedEvent</code> or <code>GroupItemStateChangedEvent</code>)</label>
<input type="checkbox" id="node-input-whenchanged" style="display: inline-block; width: auto; vertical-align: top;">
</input>
</div>
<div class="form-row node-whenchanged">
<label for="node-input-changedfrom"><i class="fa fa-tag"></i> From (oldValue)</label>
<input type="text" id="node-input-changedfrom" placeholder="<anything>">
</div>
<div class="form-row node-whenchanged">
<label for="node-input-changedto"><i class="fa fa-tag"></i> To (value)</label>
<input type="text" id="node-input-changedto" placeholder="<anything>">
</div>
</script>
<script type="text/x-red" data-template-name="openhab2-get2">
<style type="text/css">
.btn-group {
width: 70%;
}
.multiselect {
width: 100%;
}
.form-row input.multiselect-search {
width: 100%;
}
.multiselect-clear-filter {
display: none;
}
.dropdown-menu {
width: 100% !important;
}
.multiselect-container input[type="checkbox"] {
display: none;
}
.multiselect-container > li > a > label.radio {
margin: 5px;
width: 90%;
height: 100%;
cursor: pointer;
font-weight: 400;
padding: 3px 20px 3px 20px;
}
.multiselect-container label.radio input[type="radio"] {
display: none;
}
</style>
<link rel="stylesheet" href="static/css/bootstrap-multiselect.css" type="text/css" />
<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>
<div class="form-row">
<label for="node-input-controller"><i class="fa fa-globe"></i> Controller</label>
<input type="text" id="node-input-controller">
</div>
<div class="form-row">
<label for="node-input-itemname"><i class="fa fa-crosshairs"></i> ItemName</label>
<select id="node-input-itemname" name="node-input-itemname">
</select>
</div>
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
<input type="text" id="node-input-topic" name="node-input-topic" style="width: 250px;">
</div>
<div class="form-row">
<label for="node-input-sendnull"><i class="fa fa-crosshairs"></i> Send NULL-values</label>
<input type="checkbox" id="node-input-sendnull" style="display: inline-block; width: auto; vertical-align: top;">
</input>
</div>
</script>
<script type="text/x-red" data-template-name="openhab2-monitor2">
<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>
<div class="form-row">
<label for="node-input-controller"><i class="fa fa-globe"></i> Controller</label>
<input type="text" id="node-input-controller">
</div>
</script>
<script type="text/x-red" data-template-name="openhab2-out2">
<style type="text/css">
.btn-group {
width: 70%;
}
.multiselect {
width: 100%;
}
.form-row input.multiselect-search {
width: 100%;
}
.multiselect-clear-filter {
display: none;
}
.dropdown-menu {
width: 100% !important;
}
.multiselect-container input[type="checkbox"] {
display: none;
}
.multiselect-container > li > a > label.radio {
margin: 5px;
width: 90%;
height: 100%;
cursor: pointer;
font-weight: 400;
padding: 3px 20px 3px 20px;
}
.multiselect-container label.radio input[type="radio"] {
display: none;
}
</style>
<link rel="stylesheet" href="static/css/bootstrap-multiselect.css" type="text/css" />
<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>
<div class="form-row">
<label for="node-input-controller"><i class="fa fa-globe"></i> Controller</label>
<input type="text" id="node-input-controller">
</div>
<div class="form-row">
<label for="node-input-itemname"><i class="fa fa-crosshairs"></i> ItemName</label>
<select id="node-input-itemname" name="node-input-itemname">
</select>
</div>
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
<select id="node-input-topic" name="node-input-topic" style="width: 250px;">
<option value=""></option>
<option value="ItemCommand">ItemCommand</option>
<option value="ItemUpdate">ItemUpdate</option>
</select>
</div>
<div class="form-row">
<label for="node-input-payload"><i class="fa fa-envelope"></i> Payload</label>
<input type="text" id="node-input-payload" placeholder="Payload">
</div>
<div class="form-row">
<label for="node-input-onlywhenchanged"><i class="fa fa-crosshairs"></i> Only when changed</label>
<input type="checkbox" id="node-input-onlywhenchanged" style="display: inline-block; width: auto; vertical-align: top;">
</input>
</div>
</script>
<script type="text/x-red" data-template-name="openhab2-events2">
<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>
<div class="form-row">
<label for="node-input-controller"><i class="fa fa-globe"></i> Controller</label>
<input type="text" id="node-input-controller">
</div>
</script>
<script type="text/x-red" data-help-name="openhab2-controller2">
<p>Configuration node for communication with an openHAB controller.</p>
<p></p>
<b>Configuration</b>
<ul>
<li><b>Name :</b> Specify a name for the configuration node</li>
<li><b>Protocol :</b> "http" or "https"</li>
<li><b>Host :</b> Specify the hostname or ip address</li>
<li><b>Port :</b> (Optionally) Specify the ip port</li>
<li><b>Path :</b> (Optionally) Specify the additional base path</li>
<li><b>Username :</b> (Optionally) Specify the username to authenticate. This is for authenticating to an reverse proxy, not for authenticating with openHAB itself, as openHAB <a href="https://www.openhab.org/docs/installation/security.html#authentication-and-access-control" target="_blank"><i>"does not (yet) support restricting access through HTTP(S) for certain users - there is no authentication in place, nor is there a limitation of functionality or information that different users can access."</i></a></li>
<li><b>Password :</b> (Optionally) Specify the password to authenticate</li>
<li><b>openHAB version :</b> "v1 and v2" or "v3".</li>
<li><b>OAuth2 Bearer token :</b> An OAuth2 token created in openHAB 3, according to the <a href="https://www.openhab.org/docs/configuration/apitokens.html" target="_blank">documentation</a>, with the important note that the token should be filled NOT for the <code>Username</code> or <code>Password</code> field, but <strong>only the</strong> <code>OAuth2 Bearer token</code> <strong>field!</strong> A token looks like this: <code>oh.nodered.CgpQ...</code></li>
</ul>
</script>
<script type="text/x-red" data-help-name="openhab2-in2">
<p>Subscribes to state changes for the selected openHAB Item. Items or Groups with a value of NULL are not sent to the output channel.</p>
<p></p>
<b>Configuration</b>
<ul>
<li><b>Name :</b> Optionally specify a name</li>
<li><b>Controller :</b> Select the openHAB controller</li>
<li><b>Item :</b>Select the Item to monitor</li>
<li><b>Topic :</b> Set .topic for the outgoing message</li>
<li><b>Send initial :</b>Send message at node and/or the connected controller (openhab2-controller2) startup (type 'InitialStateEvent')</li>
<li><b>When updated :</b>Send message when node state updates (type 'ItemStateEvent')</li>
<li><b>When command :</b>Send message when node state receives a command (type 'ItemCommandEvent')</li>
<li><b>When changed :</b>Send message when node state changes (type 'ItemStateChangedEvent' or 'GroupItemStateChangedEvent')</li>
<li><b>From :</b>Old state value that should match before outputting a message. Ignored when left empty. Leave this field empty when the above "When command" is checked.</li>
<li><b>To :</b>New state value that should match before outputting a message. Ignored when left empty.</li>
</ul>
<p></p>
<b>Messages injected in NodeRED flows (1 output channel)</b>
<ul>
<li>Channel 1:
<ul>
<li><code>msg.item</code> : the item's itemname (not the label)</li>
<li><code>msg.topic</code> : the item's topic as specified</li>
<li><code>msg.event</code> : InitialStateEvent | ItemStateEvent | ItemCommandEvent | ItemStateChangedEvent | GroupItemStateChangedEvent</li>
<li><code>msg.payload</code> : the current state of the selected item</li>
<li><code>msg.oldValue</code> : the previous state of the selected item</li>
</ul>
</li>
</ul>
</script>
<script type="text/x-red" data-help-name="openhab2-get2">
<p>Gets an openHAB Item' state on an input message. Items or Groups with a value of NULL are not sent to the output channel.</p>
<p></p>
<b>Configuration</b>
<ul>
<li><b>Name :</b> Optionally specify a name</li>
<li><b>Controller :</b> Select the openHAB controller</li>
<li><b>Item :</b> Optionally select the Item to address. If specified, it overrides the item specified in the incoming message.</li>
<li><b>Topic :</b> Set .topic for the outgoing message</li>
</ul>
<p></p>
<b>Messages accepted by NodeRED flows (1 input channel)</b>
<ul>
<li><code>msg.item</code> optionally the Item to address</li>
</ul>
<p></p>
<b>Messages injected in NodeRED flows (1 output channel)</b>
<ul>
<li>Channel 1:
<p>Outputs the received input message with addition of: <p>
<ul>
<li><code>msg.item</code> : the item's itemname (not the label)</li>
<li><code>msg.topic</code> : the item's topic as specified</li>
<li><code>msg.event</code> : will be set to "ActualState"</li>
<li><code>msg.payload</code> : the current state of the selected item</li>
<li><code>msg.payload_in</code> : copy of incoming message payload</li>
<li><code>msg.type</code> : returns the type of the item (like <code>String</code> or <code>Group</code>)</li>
<li><code>msg.groups</code> : contains the list of group(s) the item belongs to. If the item does not belong to any group, the list will be empty.</li>
<li><code>msg.members</code> : when msg.type is <code>Group</code>, this will contain a list of all members that are part of this group</li>
</ul>
</li>
</ul>
</script>
<script type="text/x-red" data-help-name="openhab2-monitor2">
<p>Monitors the openhab2-controller2 node.</p>
<p></p>
<b>Configuration</b>
<ul>
<li><b>Name :</b> Optionally specify a name</li>
<li><b>Controller :</b> Select the openHAB controller</li>
</ul>
<p></p>
<b>Messages injected in NodeRED flows (3 output channels)</b>
<ul>
<li>Channel 1:
<ul>
<li><code>msg.topic</code> : "ConnectionStatus"</li>
<li><code>msg.payload</code> : connection status ('ON' or 'OFF')</li>
</ul>
</li>
<li>Channel 2:
<ul>
<li><code>msg.topic</code> : "ConnectionError"</li>
<li><code>msg.payload</code> : error message(s)</li>
</ul>
</li>
<li>Channel 3:
<ul>
<li><code>msg.topic</code> : "RawEvent"</li>
<li><code>msg.payload</code> : raw (unprocessed) event for all items</li>
</ul>
</li>
</ul>
</script>
<script type="text/x-red" data-help-name="openhab2-out2">
<p>Sends commands or state updates to a selected openHAB Item. You can choose to only write the state value if it differs from the actual state.</p>
<p></p>
<b>Configuration</b>
<ul>
<li><b>Name :</b> Optionally specify a name</li>
<li><b>Controller :</b> Select the openHAB controller</li>
<li><b>Item :</b> Optionally select the Item to address. If specified, it overrides the item specified in the incoming message.</li>
<li><b>Topic :</b> Optionally select "ItemCommand" or "ItemUpdate". If specified, it overrides the topic specified in the incoming message.</li>
<li><b>Payload :</b> Optionally specify the command or update value to send to the selected item. If specified, it overrides the value specified in the incoming message.</li>
<li><b>Only when changed :</b> Optionally check this if you want to ouput the value if it changed in comparison to the actual (current) value.</li>
</ul>
<p></p>
<b>Messages accepted by NodeRED flows (1 input channel)</b>
<ul>
<li><code>msg.item</code> optionally the Item to address</li>
<li><code>msg.topic</code> optionally "ItemCommand", "ItemUpdate"</li>
<li><code>msg.payload</code> optionally the fixed command or update value to send to the selected item</li>
</ul>
<p></p>
<b>Messages injected in NodeRED flows (1 output channel)</b>
<ul>
<li>Channel 1:
<p>Outputs the received input message in case it was delivered to openhab successfully. In case the 'Only when changed' settings is checked, a message will only be sent when there was an actual change to the value.<p>
</li>
</ul>
</script>
<script type="text/x-red" data-help-name="openhab2-events2">
<p>Watches the event bus.</p>
<p></p>
<b>Configuration</b>
<ul>
<li><b>Name :</b> Optionally specify a name</li>
<li><b>Controller :</b> Select the openHAB controller</li>
</ul>
<p></p>
<b>Sample message (1 output channel)</b>
<code>
{
"topic": "openhab/items/TestString/statechanged",
"payload": {
"type": "String",
"value": "A",
"oldType": "String",
"oldValue": "B"
},
"type": "ItemStateChangedEvent",
"_msgid": "c437e8981c45b326"
}
</code>
</script>
<script type="text/javascript">
RED.nodes.registerType('openhab2-controller2', {
category: 'config',
defaults: {
name: {
value: "",
required: true
},
protocol: {
value: "http",
required: true,
validate: RED.validators.regex(/http[s]?/)
},
host: {
value: "localhost",
required: true
},
port: {
value: 8080,
required: false,
validate: RED.validators.number()
},
path: {
value: "",
required: false
},
username: {
value: "",
required: false
},
password: {
value: "",
required: false
},
ohversion: {
value: "v3",
required: true,
validate: RED.validators.regex(/v[23]/)
},
token: {
value: "",
required: false
}
},
paletteLabel: "openhab2-controller2",
label: function () {
return this.name || this.host + ":" + this.port;
},
oneditprepare: function () {
$("#node-config-input-ohversion").change(function () {
if ($("#node-config-input-ohversion").val() == "v3") {
$(".node-token").show();
} else {
$(".node-token").hide();
}
});
}
});
</script>
<script type="text/javascript">
// some code shared by openhab2-in2 and openhab2-out2
function openhabEditPrepare(node, allowEmpty) {
function updateOpenhabItemSelection(cntrlConfig, itemName) {
var itemSelectionEl = $('#node-input-itemname');
// itemSelectionEl.children().remove();
itemSelectionEl.multiselect({
enableFiltering: true,
enableCaseInsensitiveFiltering: true,
maxHeight: 300,
disableIfEmpty: true,
nonSelectedText: 'Select item...',
disabledText: 'No items found...'
});
if (cntrlConfig) {
var config = {
name: cntrlConfig.name,
protocol: cntrlConfig.protocol,
host: cntrlConfig.host,
port: cntrlConfig.port,
path: cntrlConfig.path,
username: cntrlConfig.username,
password: cntrlConfig.password,
ohversion: cntrlConfig.ohversion,
token: cntrlConfig.token,
}
//console.log("config = " + JSON.stringify(config));
// For some Node-Red installations, the relative webroot is changed from "/" to "/endpoint" using the
// httpRoot: '/endpoint' setting (in the settings.json on disk). This could break the request below,
// so we lookup the `httpNodeRoot` setting to construct the callback url.
// More info: https://discourse.nodered.org/t/http-endpoint-guidelines/2309/4
$.getJSON(RED.settings.httpNodeRoot + "openhab3/items", config)
.done(function (data) {
itemSelectionEl.children().remove();
var items = data;
items.sort(function (a, b) {
if (a.name < b.name)
return -1;
else if (a.name > b.name)
return 1;
else
return 0;
});
if (allowEmpty)
itemSelectionEl.append('<option value=""></option>');
items.forEach(function (item) {
itemSelectionEl.append('<option>' + item.name + '</option>');
var it = itemSelectionEl.find('option').last();
it.attr('value', item.name);
});
itemSelectionEl.val(itemName);
itemSelectionEl.multiselect('rebuild');
})
.fail(function (e1, e2, e3) {
console.log("error : " + JSON.stringify(e1));
});
}
}
updateOpenhabItemSelection(RED.nodes.node(node.controller), node.itemname);
$('#node-input-controller').change(function (ev) {
updateOpenhabItemSelection(RED.nodes.node($('#node-input-controller').val()), $('#node-input-')
.val() || node.itemname);
});
}
</script>
<script type="text/javascript">
$.getScript('static/js/bootstrap-multiselect.js');
RED.nodes.registerType('openhab2-in2', {
category: 'home automation',
color: '#00cc00',
defaults: {
name: {
value: ""
},
controller: {
value: "",
type: "openhab2-controller2",
required: true
},
itemname: {
value: "",
required: true
},
topic: {
value: "",
required: false
},
initialstate: {
value: false
},
whenupdated: {
value: true
},
whencommand: {
value: true
},
whenchanged: {
value: false
},
changedfrom: {
value: "",
required: false
},
changedto: {
value: "",
required: false
}
},
inputs: 0,
outputs: 1,
icon: "node-red-contrib-openhab2.png",
paletteLabel: "openhab2-in2",
label: function () {
return (this.name || this.itemname || "openhab2 in2");
},
oneditprepare: function () {
openhabEditPrepare(this, false);
$("#node-input-whenchanged").change(function () {
if ($(this).is(":checked")) {
$(".node-whenchanged").show();
} else {
$(".node-whenchanged").hide();
$('#node-input-changedfrom').val('');
$('#node-input-changedto').val('');
}
});
if (this.whenchanged === "true" || this.whenchanged === true) {
$("#node-input-whenchanged").prop("checked", true);
} else {
$("#node-input-whenchanged").prop("checked", false);
}
}
});
</script>
<script type="text/javascript">
RED.nodes.registerType('openhab2-get2', {
category: 'home automation',
color: '#00cc00',
defaults: {
name: {
value: ""
},
controller: {
value: "",
type: "openhab2-controller2",
required: true
},
itemname: {
value: "",
required: false
},
topic: {
value: "",
required: false
},
sendnull: {
value: false
}
},
inputs: 1,
outputs: 1,
icon: "node-red-contrib-openhab2.png",
paletteLabel: "openhab2-get2",
label: function () {
return (this.name || this.itemname || "openhab2 get2");
},
oneditprepare: function () {
openhabEditPrepare(this, true);
}
});
</script>
<script type="text/javascript">
RED.nodes.registerType('openhab2-monitor2', {
category: 'home automation',
color: '#00cc00',
defaults: {
name: {
value: ""
},
controller: {
value: "",
type: "openhab2-controller2",
required: true
}
},
inputs: 0,
outputs: 3,
icon: "node-red-contrib-openhab2.png",
paletteLabel: "openhab2-monitor",
label: function () {
return (this.name || "openhab2 monitor");
},
oneditprepare: function () {}
});
</script>
<script type="text/javascript">
RED.nodes.registerType('openhab2-out2', {
category: 'home automation',
color: '#00cc00',
defaults: {
name: {
value: ""
},
controller: {
value: "",
type: "openhab2-controller2",
required: true
},
itemname: {
value: "",
required: false
},
topic: {
value: "",
required: false
},
payload: {
value: "",
required: false
},
onlywhenchanged: {
value: false
},
},
inputs: 1,
outputs: 1,
icon: "node-red-contrib-openhab2.png",
paletteLabel: "openhab2-out2",
label: function () {
return (this.name || this.itemname || "openhab2 out2");
},
oneditprepare: function () {
openhabEditPrepare(this, true);
}
});
</script>
<script type="text/javascript">
RED.nodes.registerType('openhab2-events2', {
category: 'home automation',
color: '#0fdd0f',
defaults: {
name: {
value: ""
},
controller: {
value: "",
type: "openhab2-controller2",
required: true
},
itemname: {
value: "",
required: false
},
},
inputs: 0,
outputs: 1,
icon: "node-red-contrib-openhab2.png",
paletteLabel: "openhab2-events2",
label: function () {
return (this.name || this.itemname || "openhab2 events2");
},
oneditprepare: function () {
openhabEditPrepare(this, true);
}
});
</script>