forked from rperciaccante/HomeAssistant_OneControl_Discovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flow.json
2135 lines (2135 loc) · 107 KB
/
flow.json
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
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
[
{
"id": "c5bf60a40630c5e3",
"type": "tab",
"label": "OneControl Discovery",
"disabled": false,
"info": "",
"env": []
},
{
"id": "43b59d10c7fbb603",
"type": "tab",
"label": "OneControl Monitoring",
"disabled": false,
"info": ""
},
{
"id": "fbf3308551f314be",
"type": "tab",
"label": "Tools",
"disabled": false,
"info": "",
"env": []
},
{
"id": "a2d4a149bd5c14b2",
"type": "group",
"z": "fbf3308551f314be",
"name": "Connect to your OneControl platform and download entities",
"style": {
"fill": "#ffffbf",
"label": true,
"label-position": "ne"
},
"nodes": [
"2ab54f412889170c",
"22e486b014509a50",
"0e37680e62b8250e",
"398ef1a0a16d08f0",
"018e9d1e4c093a3e",
"3d605545bfab8cd3"
],
"x": 54,
"y": 59
},
{
"id": "2ec83346dffc7d94",
"type": "group",
"z": "c5bf60a40630c5e3",
"name": "Data Publishing",
"style": {
"fill": "#e3f3d3",
"label": true
},
"nodes": [
"888e1201759d2203",
"273da8d4173943bb",
"11af832c02c64601",
"9be463bbf9a8f997",
"99f937e3894a08b8",
"dffd7703ab060e9f",
"6a2e6e770864cdd0",
"f11ec4beb8586b8f",
"3e2a20b42543032b",
"4a241eecd05a027a",
"6fc28ef47b87f702",
"670878733f3ed1be"
],
"x": 954,
"y": 179,
"w": 592,
"h": 342
},
{
"id": "6858fb2384f7f246",
"type": "group",
"z": "c5bf60a40630c5e3",
"name": "Processing Options",
"style": {
"label": true,
"fill": "#e3f3d3"
},
"nodes": [
"e0aac92236e32259",
"a80200c65e78f34a",
"aa1ffe397c27678d",
"45a56438708b01c9"
],
"x": 954,
"y": 19,
"w": 592,
"h": 142
},
{
"id": "90c01626219c9b6e",
"type": "group",
"z": "c5bf60a40630c5e3",
"name": "Get current state of entities",
"style": {
"fill": "#e3f3d3",
"label": true
},
"nodes": [
"2246a7b0e41df251",
"5534c824af950556",
"ddd5b4ca9b2214d1"
],
"x": 614,
"y": 239,
"w": 292,
"h": 162
},
{
"id": "b07fe501c3da07e1",
"type": "group",
"z": "c5bf60a40630c5e3",
"name": "Create Control Entities",
"style": {
"fill": "#ffC000",
"label": true,
"color": "#000000"
},
"nodes": [
"8efc57e27bef52e5",
"d25248e6a91d7fea",
"dab9d99d41494c79",
"491b0949692ff5c9"
],
"x": 614,
"y": 19,
"w": 292,
"h": 202
},
{
"id": "4979df7953c906ee",
"type": "group",
"z": "c5bf60a40630c5e3",
"name": "Enable Debugging",
"style": {
"fill": "#ffefbf",
"label": true
},
"nodes": [
"66b533eb7bb555b6",
"879a7280e4ff88f2"
],
"x": 614,
"y": 559,
"w": 292,
"h": 142
},
{
"id": "b786722f1abebf90",
"type": "group",
"z": "c5bf60a40630c5e3",
"name": "Build HVAC Entities",
"style": {
"fill": "#e3f3d3",
"label": true
},
"nodes": [
"098e7e902113652b"
],
"x": 614,
"y": 419,
"w": 292,
"h": 82
},
{
"id": "09ec6382357415d1",
"type": "group",
"z": "c5bf60a40630c5e3",
"name": "Collect devices from OneControl",
"style": {
"fill": "#e3f3d3",
"label": true
},
"nodes": [
"98f4ba26adf91fe6",
"ea1e858d19760df3",
"489f1d4567f2e9fe",
"bdf45c1455481f97"
],
"x": 254,
"y": 19,
"w": 292,
"h": 162
},
{
"id": "11cee4e8082393f2",
"type": "group",
"z": "c5bf60a40630c5e3",
"name": "Gather and process individual control channels",
"style": {
"fill": "#e3f3d3",
"label": true
},
"nodes": [
"f5a3506e1a122e6b",
"1baacf69c1df92ac",
"0b7b92b04bceb755",
"02c44407100b5dfe",
"25ecfdaf34edb547",
"0fb7b59456f85d4b"
],
"x": 254,
"y": 199,
"w": 299,
"h": 282
},
{
"id": "4514be5227808dc1",
"type": "group",
"z": "c5bf60a40630c5e3",
"name": "Generate Supplemental Entities",
"style": {
"fill": "#e3f3d3",
"label": true
},
"nodes": [
"af180c05203f3bf8",
"f3dc76e8144ad4bd",
"d445b1bb9cd4ab81",
"4efa180cc4812cc4",
"7c688006afafe03e"
],
"x": 254,
"y": 499,
"w": 312,
"h": 242
},
{
"id": "6aae06d09c613fad",
"type": "group",
"z": "43b59d10c7fbb603",
"name": "OneControl Event Stream",
"style": {
"fill": "#e3f3d3",
"label": true
},
"nodes": [
"affcfc4989bec16b",
"ca6fbeb5c26fcf8c",
"aa5f06d40fe8cb5a",
"c858ec7c0b44668c",
"73638f0d908217b1",
"b8221c75079a0d4c",
"a7a4976dfe29fe86",
"86020bb309d0ae86",
"e3142aa105a58b6f",
"5c0b50257b9bbe74",
"4f9578a7eba52f1d",
"9f8f72780fcd08cd"
],
"x": 34,
"y": 19,
"w": 1572,
"h": 202
},
{
"id": "c2cef54b587f0bcb",
"type": "group",
"z": "43b59d10c7fbb603",
"name": "OneControl Event Send",
"style": {
"fill": "#e3f3d3",
"label": true
},
"nodes": [
"8f14976b64bb3146",
"391a9569a63dcb2a",
"d798d4fbbc01f36d",
"3e7e3125a5625d70",
"f2bdd5e747c58fb2",
"2b59b7ebf7f8c64f",
"97ebd9ec3e8a6fde",
"948bd492828276bc",
"5dfeec5f086a1a5d"
],
"x": 34,
"y": 239,
"w": 1572,
"h": 182
},
{
"id": "b81fcae9f8b73e0b",
"type": "group",
"z": "43b59d10c7fbb603",
"name": "Entities in Home Assistant that control this integration",
"style": {
"fill": "#e3f3d3",
"label": true
},
"nodes": [
"285a06fd6b523577",
"c5a20be305249658",
"0d6b1468c7e8402c",
"30a5d1b17151aadd",
"68e445fc2b0a42c7",
"d6d1322b9d745884",
"9d3f4ffa65c1772b",
"94ae0ec5e36d0e7b",
"93753410a1771126",
"8d475c51d06f4ba7",
"00417d306bc2e61c",
"3b970ff7deaf8436",
"1cf20926d2520c98"
],
"x": 34,
"y": 439,
"w": 1572,
"h": 282
},
{
"id": "4410210f.6939c",
"type": "mqtt-broker",
"name": "Localhost",
"broker": "127.0.0.1",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"compatmode": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"sessionExpiry": ""
},
{
"id": "f5a3506e1a122e6b",
"type": "split",
"z": "c5bf60a40630c5e3",
"g": "11cee4e8082393f2",
"name": "Split Individual Channels",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "foo",
"x": 410,
"y": 240,
"wires": [
[
"0fb7b59456f85d4b"
]
]
},
{
"id": "1baacf69c1df92ac",
"type": "join",
"z": "c5bf60a40630c5e3",
"g": "11cee4e8082393f2",
"name": "Consolidate Channels",
"mode": "auto",
"build": "object",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": true,
"timeout": "",
"count": "",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 420,
"y": 400,
"wires": [
[
"0b7b92b04bceb755"
]
]
},
{
"id": "0b7b92b04bceb755",
"type": "change",
"z": "c5bf60a40630c5e3",
"g": "11cee4e8082393f2",
"name": "Reorganize Message",
"rules": [
{
"t": "set",
"p": "thing.channels",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "delete",
"p": "payload",
"pt": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 420,
"y": 440,
"wires": [
[
"af180c05203f3bf8"
]
]
},
{
"id": "ea1e858d19760df3",
"type": "inject",
"z": "c5bf60a40630c5e3",
"g": "09ec6382357415d1",
"name": "Click here to start",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 380,
"y": 60,
"wires": [
[
"bdf45c1455481f97"
]
]
},
{
"id": "af180c05203f3bf8",
"type": "function",
"z": "c5bf60a40630c5e3",
"g": "4514be5227808dc1",
"name": "Build Node Diagnostic Entities",
"func": "// This node generates sensors that contain the diagnostic values for the device (not the individual sensors)\n\nfunction capitolizeFirst(string) {\n var output = string.replace(/\\w\\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});\n return output;\n}\n\n\nmsg.payload = \"\"\n for (const property in msg.thing.configuration) {\n var baseTopic = global.get(\"mqttDiscoveryTopic\") + \"/sensor/\" + msg.thing.hass.UID_ha + \"/\" + property\n msg.topic = baseTopic + \"/config\"\n \n switch(property){\n case \"deviceType\":\n var name = msg.thing.label + \" Device Type\"\n break;\n case \"deviceInstance\":\n var name = msg.thing.label + \" Device Instance\"\n break;\n case \"capability\":\n var name = msg.thing.label + \" Capability\"\n break;\n case \"productID\":\n var name = msg.thing.label + \" Product ID\"\n break;\n case \"functionName\":\n var name = msg.thing.label + \" Function Name\"\n break;\n case \"functionInstance\":\n var name = msg.thing.label + \" Function Instance\"\n break;\n case \"mac\":\n var name = msg.thing.label + \" MAC Address\"\n break;\n default:\n var name = property\n break;\n }\n\n \n msg.payload = {\n \"name\": name,\n \"object_id\": global.get(\"namePrecursor\") + name,\n \"unique_id\": msg.thing.hass.UID_ha + \"_\" + property,\n \"entity_category\": \"diagnostic\",\n \"state_topic\": baseTopic + \"/state\",\n \"availability\": {\"topic\": msg.thing.hass.availabilityTopic,\n \t\"payload_available\": msg.thing.hass.availabilityTopicOn,\n \t\"payload_not_available\": msg.thing.hass.availabilityTopicOff,\n \t\"value_template\": \"{{ value_json.\" + msg.thing.hass.availabilityTopicAttr + \" }}\", \n },\n \"device\": {\"manufacturer\": global.get(\"deviceManufacturer\"), \n \"via_device\": global.get(\"deviceViaDevice\"),\n \"identifiers\": msg.thing.hass.UID_ha, \n \"name\": msg.thing.label, \n \"model\": global.get(\"deviceModel\") + \": \" + msg.thing.hass.UID_ha,\n \"sw_version\": global.get(\"deviceSWVversion\")\n },\n\n \"enabled_by_default\": true\n \n } \n msg.type = \"entity\"\n node.send(msg)\n \n \n // Send the default values from the config to the MQTT topic for the attribute above\n var msg1 = {}\n msg1.topic = baseTopic + \"/state\"\n var value = msg.thing.configuration[property]\n /* \n\n */\n if (property == \"deviceType\") {\n switch(value) {\n case 10:\n value = \"(\" + value + \") Tank Sensor (Relay Control)\"\n break;\n case 16:\n value = \"(\" + value + \") HVAC Control (HVAC Control)\"\n break;\n case 20:\n value = \"(\" + value + \") Dimmable Light (Lighting Control)\"\n break;\n case 24:\n value = \"(\" + value + \") Generator Genie (HVAC Control)\"\n break;\n case 30:\n value = \"(\" + value + \") Latching Relay (type 2), (Relay Control)\"\n break;\n }\n }\n //msg1.value = value\n //msg1.property = property\n msg1.payload = value\n msg1.type = \"record\"\n msg1.retain = true\n node.send(msg1)\n}\n\nreturn [null,msg]",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 410,
"y": 540,
"wires": [
[
"eedd8594c925dbf3"
],
[
"f3dc76e8144ad4bd"
]
]
},
{
"id": "f3dc76e8144ad4bd",
"type": "switch",
"z": "c5bf60a40630c5e3",
"g": "4514be5227808dc1",
"name": "Process Special Device Types",
"property": "thing.hass.thingTypeUID_ha",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "hvac",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 410,
"y": 580,
"wires": [
[
"098e7e902113652b",
"d445b1bb9cd4ab81"
],
[
"d445b1bb9cd4ab81"
]
]
},
{
"id": "098e7e902113652b",
"type": "function",
"z": "c5bf60a40630c5e3",
"g": "b786722f1abebf90",
"name": "Build HVAC complex entities ",
"func": "// ####################### Begin HVAC Device Configuration #######################\n// Home Assistant can use MQTT Discovery to create a HVAC (referred to as a climate entity).\n// https://www.home-assistant.io/integrations/climate.mqtt/\n// Unlike the other entities, this entity will utilize several different mqtt topics from individual channels\n// to form the Climate entity.\nvar i = msg.thing.UID.replace(/:/g,\"_\")\ni = i.replace(\"-\",\"_\")\n\nvar discoveryBaseTopic = global.get(\"mqttDiscoveryTopic\") + \"/climate/\" + msg.thing.hass.UID_ha + \"/hvac\"\nmsg.topic = discoveryBaseTopic + \"/config\"\n\nmsg.payload = {\n \"name\": msg.thing.label,\n \"object_id\": global.get(\"namePrecursor\") + msg.thing.label,\n \"unique_id\": i,\n \"enabled_by_default\": \"true\",\n \"availability\": { \n \"topic\": msg.thing.hass.availabilityTopic,\n \"payload_available\": msg.thing.hass.availabilityTopicOn,\n \t \"payload_not_available\": msg.thing.hass.availabilityTopicOff,\n \t \"value_template\": \"{{ value_json.\" + msg.thing.hass.availabilityTopicAttr + \" }}\", \n },\n \"device\": {\n \"manufacturer\": global.get(\"deviceManufacturer\"),\n \"via_device\": global.get(\"via_device\"),\n \"identifiers\": msg.thing.hass.UID_ha,\n \"name\": msg.thing.hass.label,\n \"model\": \"OneControl: \"+ msg.thing.hass.UID_ha,\n \"sw_version\": \"1.0\"\n },\n \"action_topic\": \"smarthome/items/\"+i+\"_status/state\",\n \"action_template\": \"{{ value_json.value }}\",\n \"current_temperature_topic\": \"smarthome/items/\"+i+\"_inside_temperature/state\",\n \"current_temperature_template\": \"{{ value_json.value }}\",\n \"fan_mode_command_topic\": \"smarthome/items/\"+i+\"_fan_mode/set\",\n \"fan_mode_state_topic\": \"smarthome/items/\"+i+\"_fan_mode/state\",\n \"fan_mode_state_template\": \"{{ value_json.value }}\",\n \"fan_modes\": [\"auto\", \n \t \"low\", \n \t \"high\"],\n \"hold_command_topic\": \"smarthome/items/\"+i+\"_heat-source/set\",\n \"hold_state_topic\": \"smarthome/items/\"+i+\"_heat-source/state\",\n \"hold_state_template\": \"{{ value_json.value }}\",\n \"hold_modes\": [\"Prefer Heatpump\",\n \"Prefer Gas\"],\n \t \"mode_command_topic\": \"smarthome/items/\"+i+\"_hvac_mode/set\",\n \"mode_state_topic\": \"smarthome/items/\"+i+\"_hvac_mode/state\",\n \t\"mode_state_template\": \"{{ value_json.value }}\",\n \t\"modes\": [\"heat\", \n \t \"cool\",\n \t \"heat_cool\",\n \t \"off\"],\n \t\"min_temp\": 45,\n \t\"max_temp\": 100,\n \t\"precision\": 1,\n \t\"retain\": true,\n \"temperature_command_topic\": \"smarthome/items/\" + i + \"_high_temperature/set\",\n \"temperature_state_topic\": \"smarthome/items/\" + i + \"_high_temperature/state\",\n \"temperature_state_template\": \"{{ value_json.value }}\",\n \"temp_step\": 1\n }\nmsg.type = \"entity\"\nnode.send(msg)\n\ndiscoveryBaseTopic = global.get(\"mqttDiscoveryTopic\") + \"/sensor/\" + msg.thing.hass.UID_ha + \"/device_mode\"\nmsg.topic = discoveryBaseTopic + \"/config\"\nmsg.payload = {\n \"name\": msg.thing.label + \" Device State\",\n \"object_id\": global.get(\"namePrecursor\") + msg.thing.label + \" Device State\",\n \"unique_id\": i + \"_device_state\",\n \"enabled_by_default\": \"true\",\n \"availability\": {\n \t\"topic\": msg.thing.hass.availabilityTopic,\n \t\"payload_available\": \"online\",\n \t\"payload_not_available\": \"offline\",\n \t\"value_template\": \"{{ value_json.status }}\", \n },\n \"device\": {\n \"manufacturer\": global.get(\"deviceManufacturer\"),\n \"via_device\": global.get(\"deviceViaDevice\"),\n \"identifiers\": msg.thing.hass.UID_ha,\n \"name\": msg.thing.hass.label,\n \"model\": global.get(\"deviceModel\"),\n \"sw_version\": global.get(\"deviceSWVersion\"),\n },\n \"entity_category\": \"diagnostic\",\n \"state_topic\": \"smarthome/items/\"+i+\"_status/state\",\n \"value_template\": \"{{ value_json.value }}\"\n}\nmsg.type = \"entity\"\nnode.send(msg)\n\ndiscoveryBaseTopic = global.get(\"mqttDiscoveryTopic\") + \"/select/\" + msg.thing.hass.UID_ha + \"/device_mode\"\nmsg.topic = discoveryBaseTopic + \"/config\"\nmsg.payload = {\n \"name\": msg.thing.label + \" Heat Source Select\",\n \"object_id\": global.get(\"namePrecursor\") + msg.thing.label + \" Heat Source Select\",\n \"unique_id\": i + \"_heat_source_select\",\n \"enabled_by_default\": \"true\",\n \"availability\": {\n \t\"topic\": msg.thing.hass.availabilityTopic,\n \t\"payload_available\": \"online\",\n \t\"payload_not_available\": \"offline\",\n \t\"value_template\": \"{{ value_json.status }}\", \n },\n \"device\": {\n \"manufacturer\": global.get(\"deviceManufacturer\"),\n \"via_device\": global.get(\"deviceViaDevice\"),\n \"identifiers\": msg.thing.hass.UID_ha,\n \"name\": msg.thing.hass.label,\n \"model\": global.get(\"deviceModel\"),\n \"sw_version\": global.get(\"deviceSWVersion\"),\n },\n \"entity_category\": \"diagnostic\",\n \"state_topic\": \"smarthome/items/\"+i+\"_heat-source/state\",\n \"command_topic\": \"smarthome/items/\"+i+\"_heat-source/set\",\n \"options\": [\n \"Prefer Heatpump\", \n \t \"Prefer Gas\"\n \t ],\n}\nmsg.type = \"entity\"\nnode.send(msg)\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 760,
"y": 460,
"wires": [
[
"6fc28ef47b87f702"
]
]
},
{
"id": "0fb7b59456f85d4b",
"type": "function",
"z": "c5bf60a40630c5e3",
"g": "11cee4e8082393f2",
"name": "Pre-Process Channels",
"func": "function capitolizeFirst(string) {\n var output = string.replace(/\\w\\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});\n return output;\n}\nvar msg1 = {}\nmsg1.debug = {}\nvar channel = {}\n\nvar channelRaw = msg.payload\n//msg.payload = {}\nvar channelUID = channelRaw.uid.replace(\"idsmyrv:\",\"\")\nchannelUID = channelUID.replace(\"-thing:\",\"_\")\nchannelUID = channelUID.replace(/-/g,\"_\")\nvar channelTypeUID = channelRaw.channelTypeUID.replace(\"idsmyrv:\",\"\")\nvar channelUID_ha = channelRaw.uid.replace(/:/g,\"_\")\nchannelUID_ha = channelUID_ha.replace(/-/g,\"_\")\n\nmsg.payload.hass = {}\n\nmsg.payload.hass = {\n \"label_ha\": msg.thing.hass.label + \" \" + capitolizeFirst(channelRaw.id),\n \"channelUID_oc\": channelRaw.uid,\n \"channelUID_ha\": channelUID_ha,\n \"id_oc\": channelRaw.id,\n \"valueType_oc\": channelRaw.itemType.toLowerCase(),\n \"channelType_ha\": msg.thing.hass.thingTypeUID_ha +\":\"+channelRaw.id,\n \"kind\": channelRaw.kind.toLowerCase(),\n \"topicItemStateEvent\": \"smarthome/items/\" + channelUID_ha + \"/state\",\n \"topicThingStatusInfoEvent\": \"smarthome/things/\" + msg.thing.UID + \"/status\",\n \"topicItemStateChangedEvent\": \"smarthome/items/\" + channelUID_ha + \"/statechanged\",\n \"topicItemCommandEvent\": \"smarthome/items/\" + channelUID_ha + \"/command\",\n \"topicItemCommandSend\": \"smarthome/items/\" + channelUID_ha + \"/set\"\n } \n\n// Build base discovery content \n\n\nvar basePayload = {\"name\": msg.payload.hass.label_ha,\n \"object_id\": global.get(\"namePrecursor\") + msg.payload.hass.label_ha,\n \"unique_id\": msg.payload.hass.channelUID_ha,\n \"state_topic\": msg.payload.hass.topicItemStateEvent,\n \"value_template\": \"{{ value_json.value }}\", \n \"availability\": {\n \t\"topic\": msg.thing.hass.availabilityTopic,\n \t\"payload_available\": msg.thing.hass.availabilityTopicOn,\n \t\"payload_not_available\": msg.thing.hass.availabilityTopicOff,\n \t\"value_template\": \"{{ value_json.\" + msg.thing.hass.availabilityTopicAttr + \" }}\", \n },\n \"device\": {\n \"manufacturer\": global.get(\"deviceManufacturer\"),\n \"via_device\": global.get(\"deviceViaDevice\"),\n \"identifiers\": msg.thing.hass.UID_ha,\n \"name\": msg.thing.hass.label,\n //\"connections\": [[\"mac\", msg.thing.configuration.mac],[\"foo\",\"bar\"]],\n \"model\": global.get(\"deviceModel\") + \": \" + msg.thing.hass.UID_ha,\n \"sw_version\": global.get(\"deviceSWVersion\")\n }\n }\n\n\n//var channel = {} // Used to add entity-specific attributes to the payload\n\n//Set generic entity types based on OpenHab channel itemTypes \nswitch(msg.payload.hass.channelType_ha){\n case \"light:dimmer\":\n msg.payload.hass.entityType_ha = \"light\"\n break;\n case \"switched-light:switch\":\n msg.payload.hass.entityType_ha = \"light\"\n break;\n default:\n msg.payload.hass.entityType_ha = \"sensor\"\n break;\n}\n\nmsg.payload.hass.discovery = {}\nmsg.payload.hass.attributes = {}\nmsg.payload.hass.discovery.payload = basePayload\nmsg.payload.hass.attributes.payload = msg.thing.configuration\nreturn [msg,msg]\n",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 420,
"y": 280,
"wires": [
[],
[
"02c44407100b5dfe"
]
]
},
{
"id": "02c44407100b5dfe",
"type": "switch",
"z": "c5bf60a40630c5e3",
"g": "11cee4e8082393f2",
"name": "Exclude Special Devices",
"property": "thing.hass.thingTypeUID_ha",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "rgb-light",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 410,
"y": 320,
"wires": [
[],
[
"25ecfdaf34edb547"
]
]
},
{
"id": "25ecfdaf34edb547",
"type": "function",
"z": "c5bf60a40630c5e3",
"g": "11cee4e8082393f2",
"name": "Process Individual Channels",
"func": "var addPayload = {}\n\nif (msg.payload.hass.channelType_ha.includes(\":\") === true ) {\n var channel = msg.payload.hass.channelType_ha.split(\":\")\n var channelType = channel[1]\n} else {\n channel = msg.payload.hass.channelType_ha\n}\n\nvar discoveryPayload = msg.payload.hass.discovery.payload\n\n// Add device additional details as needed based on channel types\nif (channelType.includes(\"voltage\") === true ) {\n addPayload = {\n \"device_class\": \"voltage\",\n \"enabled_by_default\": \"true\"\n }\n }\n\nif (channelType.includes(\"current\") === true ) {\n addPayload = {\n \"device_class\": \"current\",\n \"unit_of_measurement\": \"A\",\n \"enabled_by_default\": \"true\"\n }\n }\n\nif (channelType.includes(\"dimmer\") === true ) {\n var baseTopic_oc = \"smarthome/items/\" + msg.payload.hass.channelUID_ha\n var baseName = msg.thing.hass.UID_oc.replace(/:/g,\"_\")\n baseName = \"smarthome/items/\" + baseName.replace(/-/,\"_\")\n delete msg.payload.hass.discovery.payload.value_template\n \n addPayload = {\n \"state_topic\": baseName + \"_switch/state\",\n \"command_topic\": baseTopic_oc + \"/set\",\n \"brightness_state_topic\": baseName + \"_brightness/state\",\n \"brightness_command_topic\": baseTopic_oc + \"/set\",\n \"payload_on\": \"on\",\n \"payload_off\": \"off\",\n \"brightness_scale\": 100,\n \"on_command_type\": \"last\",\n \"qos\": 0,\n \"effect_state_topic\": baseName + \"_mode/state\",\n \"effect_command_topic\": baseName + \"_mode/set\",\n \"effect_list\": [\"Off\",\"Dimmer\",\"Blink\",\"Swell\"],\n \"enabled_by_default\": \"true\"\n }\n }\n\nif (channelType.includes(\"fault\") === true) {\n msg.payload.hass.entityType_ha = \"binary_sensor\"\n addPayload = {\n \"device_class\": \"problem\",\n \"payload_on\": \"on\",\n \"payload_off\": \"off\",\n \"entity_category\": \"diagnostic\",\n \"enabled_by_default\": \"true\"\n }\n }\n\n\nif (msg.payload.hass.channelType_ha.includes(\"generator:command\") === true) {\n msg.payload.hass.entityType_ha = \"switch\"\n msg.payload.hass.discovery.payload.name = \"Generator Switch\"\n msg.payload.hass.discovery.payload.object_id = global.get(\"namePrecursor\") + msg.payload.hass.discovery.payload.name\n addPayload = {\n \"command_topic\": msg.payload.hass.topicItemCommandSend,\n \"payload_on\": \"on\",\n \"payload_off\": \"off\",\n \"state_on\": \"on\",\n \"state_off\": \"off\",\n \"enabled_by_default\": \"true\"\n }\n }\n\nif (channelType.includes(\"output-disable\") === true) {\n msg.payload.hass.entityType_ha = \"sensor\"\n addPayload = {\n \"entity_category\": \"diagnostic\",\n \"enabled_by_default\": \"true\"\n }\n }\n\n\nif (channelType.includes(\"online\") === true ) {\n msg.payload.hass.entityType_ha = \"binary_sensor\"\n addPayload = {\n \"device_class\": \"connectivity\",\n \"payload_on\": \"on\",\n \"payload_off\": \"off\",\n \"entity_category\": \"diagnostic\",\n \"enabled_by_default\": \"true\"\n }\n }\n \nif (channelType.includes(\"output-disable-cause\") === true ) {\n addPayload = {\n \"entity_category\": \"diagnostic\",\n \"enabled_by_default\": \"true\"\n }\n }\n \nif (channelType.includes(\"percent\") === true ) {\n if (msg.payload.hass.id_oc == \"position\") {\n addPayload = {\n \"unit_of_measurement\": '%',\n \"value_template\": '{{ (((value_json |float)/255)*100)|round(0) }}',\n \"enabled_by_default\": \"true\"\n }\n } else {\n addPayload = {\n \"enabled_by_default\": \"true\"\n }\n }\n }\n\nif (channelType.includes(\"sleep\") === true) {\n msg.payload.hass.entityType_ha = \"number\"\n addPayload = {\n \"command_topic\": msg.payload.hass.topicItemCommandSend,\n \"qos\": 0,\n \"unit_of_measurement\": \"mins.\",\n \"step\": 1,\n \"min\": 0,\n \"max\": 120,\n \"icon\": \"mdi:timer\",\n \"enabled_by_default\": \"true\"\n }\n }\n\nif (channelType.includes(\"switch\") === true &&\n channelType.includes(\"switched-light\") != true) {\n msg.payload.hass.entityType_ha = \"switch\"\n addPayload = {\n \"command_topic\": msg.payload.hass.topicItemCommandSend,\n \"payload_on\": \"on\",\n \"payload_off\": \"off\",\n \"state_on\": \"on\",\n \"state_off\": \"off\",\n \"enabled_by_default\": \"true\"\n }\n }\n\nif (channelType.includes(\"switched-light\") === true) {\n msg.payload.hass.entityType_ha = \"light\"\n addPayload = {\n \"command_topic\": msg.payload.hass.topicItemCommandSend,\n \"payload_on\": \"on\",\n \"payload_off\": \"off\",\n \"state_on\": \"on\",\n \"state_off\": \"off\",\n \"enabled_by_default\": \"true\"\n }\n }\n \nif (channelType.includes(\"tank-level\") === true ) {\n addPayload = {\n \"icon\": \"mdi:water-percent\",\n \"unit_of_measurement\": \"%\",\n \"enabled_by_default\": \"true\"\n }\n }\n\n\nif (channelType.includes(\"temperature\") === true && \n channelType.includes(\"temperature-setpoints\") === false) {\n addPayload = {\n \"device_class\": \"temperature\",\n \"unit_of_measurement\": \"°F\",\n \"enabled_by_default\": \"true\"\n }\n }\n \nif (channelType.includes(\"temperature-setpoints\") === true) {\n addPayload = {\n \"enabled_by_default\": \"false\"\n }\n }\n \n// These sensors are unknown in their purpose, so we create them, but do not enable them unless we want to.\nif (channelType.includes(\"time1\") === true || channelType.includes(\"time2\") === true ) {\n addPayload = {\n \"enabled_by_default\": \"false\"\n }\n }\n\n \nvar discoveryBaseTopic = global.get(\"mqttDiscoveryTopic\") + \"/\" + msg.payload.hass.entityType_ha + \"/\" + msg.thing.hass.UID_ha + \"/\" + msg.payload.hass.id_oc\nmsg.payload.hass.discovery.topic = discoveryBaseTopic + \"/config\"\nmsg.payload.hass.attributes.topic = discoveryBaseTopic + \"/attributes\"\nmsg.payload.hass.discovery.payload = {...discoveryPayload,...addPayload }\n\nvar msg1 = {}\nmsg1.topic = msg.payload.hass.discovery.topic\nmsg1.payload = msg.payload.hass.discovery.payload\nmsg1.type = \"entity\"\nreturn [msg1,msg];\n",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 400,
"y": 360,
"wires": [
[
"2246a7b0e41df251",
"eedd8594c925dbf3"
],
[
"1baacf69c1df92ac"
]
]
},
{
"id": "d445b1bb9cd4ab81",
"type": "function",
"z": "c5bf60a40630c5e3",
"g": "4514be5227808dc1",
"name": "Custom Sensors and Tools",
"func": "// ####################### Begin Online Status Details sensor #######################\n// OneControl provides additional information in the availability messages published, and this informaion\n// is very useful in diagnosing potential connection issues.\n// This sensor displays any additional status details if there are any to report\nvar msg1 = {}\nvar name = msg.thing.label + \" Online Status Details\"\nvar property = \"online_status_details\"\nvar baseTopic = global.get(\"mqttDiscoveryTopic\") + \"/sensor/\" + msg.thing.hass.UID_ha + \"/\" + property\nmsg1.topic = baseTopic + \"/config\"\n\nmsg1.payload = {\n \"name\": name,\n \"object_id\": global.get(\"namePrecursor\") + name,\n \"unique_id\": msg.thing.hass.UID_ha + \" \" + property,\n \"entity_category\": \"diagnostic\",\n \"state_topic\": msg.thing.hass.availabilityTopic,\n \"value_template\": \"{{ value_json.statusDetail }}\",\n \"availability\": {\"topic\": msg.thing.hass.availabilityTopic,\n \t\"payload_available\": msg.thing.hass.availabilityTopicOn,\n \t\"payload_not_available\": msg.thing.hass.availabilityTopicOff,\n \t\"value_template\": \"{{ value_json.\" + msg.thing.hass.availabilityTopicAttr + \" }}\", \n },\n \"device\": {\"manufacturer\": global.get(\"deviceManufacturer\"), \n \"via_device\": global.get(\"deviceViaDevice\"),\n \"identifiers\": msg.thing.hass.UID_ha, \n \"name\": msg.thing.label, \n \"model\": global.get(\"deviceModel\") + \": \" + msg.thing.hass.UID_ha,\n \"sw_version\": global.get(\"deviceSWVersion\")\n },\n \"enabled_by_default\": true\n } \nmsg1.type = \"entity\"\nnode.send(msg1)\n// ####################### End Online Status Details sensor #######################\n\nreturn[null,msg]\n\n",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 420,
"y": 620,
"wires": [
[
"eedd8594c925dbf3"
],
[
"7c688006afafe03e"
]
]
},
{
"id": "66b533eb7bb555b6",
"type": "catch",
"z": "c5bf60a40630c5e3",
"g": "4979df7953c906ee",
"name": "Capture Errors",
"scope": null,
"uncaught": false,
"x": 720,
"y": 600,
"wires": [
[
"879a7280e4ff88f2"
]
]
},
{
"id": "879a7280e4ff88f2",
"type": "debug",
"z": "c5bf60a40630c5e3",
"g": "4979df7953c906ee",
"name": "Errors - Full Payload",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 760,
"y": 660,
"wires": []
},
{
"id": "6fc28ef47b87f702",
"type": "function",
"z": "c5bf60a40630c5e3",
"g": "2ec83346dffc7d94",
"name": "Value Cleanup",
"func": "function capitolizeFirst(string) {\n var output = string.replace(/\\w\\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});\n return output;\n}\nif (msg.type == \"entity\") {\n if (typeof msg.payload.name !== 'undefined') {\n if (msg.payload.name.includes(\"-\") === true ){\n msg.payload.name = msg.payload.name.replace(\"-\",\" \")\n msg.payload.name = capitolizeFirst(msg.payload.name)\n }\n }\n}\n\nif (global.get(\"mqttPublish\") == true) {\n if (global.get(\"mqttDeleteAll\") == true) {\n msg.payload = null\n msg.retain = true\n msg.qos= 1\n }\n if (global.get(\"mqttRetain\") == true) {\n msg.retain = true\n }\n switch(msg.type) { \n case \"entity\":\n if (global.get(\"mqttRecordsOnly\") == false) {\n node.send(msg)\n } \n break;\n default:\n node.send(msg)\n break;\n }\n}\n// ############################## Write out entities to file if enabled #####################\nvar msg1 = msg\nif(msg1.topic.includes(\"/config\") === true &&\n global.get(\"filesCreate\") === true && \n msg1.type == \"entity\") {\n var i = msg1.topic.split(\"/\")\n var name = msg1.payload.object_id.replace(/ /g,\"_\")\n msg1.filename = global.get(\"filesSaveTo\") + msg1.payload.device.name + \"/\" + i[1] + \"/\" + msg1.payload.name\n if (global.get(\"filesNoDiscovery\") == true) {\n delete msg1.payload.device\n delete msg1.payload.enabled_by_default\n }\n return [null,msg1];\n }\n",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1060,
"y": 340,
"wires": [
[
"4a241eecd05a027a"
],
[
"99f937e3894a08b8",
"273da8d4173943bb"
]
]
},
{
"id": "e0aac92236e32259",
"type": "function",
"z": "c5bf60a40630c5e3",
"g": "6858fb2384f7f246",
"name": "Process Configuration",
"func": "/**\n OneControl Auto Discovery into Home Assistant\n \n This process will integrate your Lippert OneControl components into Home Assistance\n\t(http://www.home-assistant.io)\n \n Use this file to set the bahavior of the process of pulling devices from the OneControl system\n*/\n\n\n// You can use this tool for many purposes, and if you are conservative in your approach, you would like to review \n// the code before connecting it to your environment.\n// By default, the monitoring flow connects to the OneControl cloud gateway as soon as the flow is deployed. This ensures\n// that every time a change is made and deployed the connection to the event feed is re-established automatically. A trigger\n// node is available for manually kicking off the connection for manual control.\n// default:\n// eventsGetStream = true\nvar eventsGetStream = true;\n\n// As this tool starts, it subscribes to the MQTT topics that are used for the processing of commands and events, \n// and if a command is meant to be sent to OneControl, it will do so automatically. If you are working to troubleshoot \n// or review what is happening before sending it to OneControl, you will likely want to prevent this from occuring until you\n// prepared for it to be done.\n// Note: This will disable the actual transmission to OneControl, but NOT the event processing. This will allow you to see what would\n// be sent if/once it is enabled.\n// default:\n// eventsSendStream = true\nvar eventsSendStream = true;\n\n\n// When the information is pulled from the OneControl system, you have the option to write the information\n// to files on the local system, as both YAML and JSON. These can be used to help troubleshoot, or you can \n// us the YAML output as the config files for Home Assistant. Set to \"true\" to have the output files written\n// to disk. If files exist, they will be overwritten.\n// ** NOTE ** These files are NOT needed for this process to work, and are for troubleshooting/stand alone use.\n// default:\n// filesCreate = false\nvar filesCreate = true;\n\n// This is where you define the destination for the files if you are using the tool \n// default: \n// filesSaveTo = '/config/OneControl/'\nvar filesSaveTo = '/config/OneControl/';\n\n// When files are saved, they are saved as YAML and JSON, but include the attributes needed for Discovery, and\n// cannot be used for static YAML configuration without certain sections removed. Set this to true to remove\n// the discovery-related sections.\n// ** NOTE ** \n// You will still need to use the \"OneControl - Command and Event Stream\" flow to process events to align with the \n// MQTT topics that are part of the configuration files\n// default:\n// filesNoDiscovery = false\nvar filesNoDiscovery = false;\n\n// Often when you make changes, you may need to remove all the entities created.\n// This option will enable the process to remove all entities created in previous\n// run AS LONG AS NO OTHER SETTINGS HAVE CHANGED (this depends on the deiscovery\n// topic to be the same).\n// Note: sendToMQTT must also be enabled\n// default:\n// mqttDeleteAll = false;\nvar mqttDeleteAll = false;\n\n// Home Assistant requires the definition of the topic used for discovery. \n// For more info on what is needed, review the Home Assistant documentation here:\n// https://www.home-assistant.io/docs/mqtt/discovery/\n// This value needs to match what is entered into your configuration.yaml file\n// configuration.yaml example:\n// mqtt:\n// discovery: true\n// discovery_prefix: 'homeassistant'\n//\n// default:\n// mqttDiscoveryTopic = 'homeassistant'\nvar mqttDiscoveryTopic = 'homeassistant';\n\n// When you initially create the entities in Home Assistant, it can take a long\n// time before an availability message is published from OneControl, sometimes \n// upwards of 30 minutes. This is because OneControl publishes changes in real\n// time, but non-change status messages much less frequently. This can be frustrating\n// when initially creating the entities.\n// Enable this setting to generate an \"online\" message when you do the initial \n// installation, which will show the entitied as \"online\" immediately. If the\n// entities are truly offline, you will not be able to run the discovery process\n// without an error, so enabling this is low (but not no) risk. Please note\n// that this will only occur once at the time the discovery process is run.\n// If you enable this, the device's \"Online Status Details\" sensor value will be\n// 'Initial Discovery' until OneControl publishes an official message. It is not uncommon\n// to see the online entity listed as \"Disconnected\" until this first message is received.\n// default: \n// mqttInitialAvail = true\nvar mqttInitialAvail = true;\n\n// When you initially create the entities in Home Assistant, it can take a long\n// time before a state update is published, marking the Home Assistant entity with\n// the value of \"Unknown\". This setting enables a flow that will connect to OneControl\n// and get the current state and populate it right away.\n// default: \n// mqttInitialState = true\nvar mqttInitialState = true;\n\n// If you do not want to send the configuration to the MQTT server, set this to \"false\"\n// default: \n// mqttPublish = false\nvar mqttPublish = true;\n\n// If you want to run this script to only generate the availability records as well as the diagnostic info,\n// set this to true. This is helpful if you need to publish availability info to activate entities that\n// are still in an unknown state\n// default: \n// mqttRecordsOnly = false\nvar mqttRecordsOnly = false;\n\n// If you want to have MQTT discovery messages retained between restarts, set this option to \"true\"\n// If you do not set this to true, your Home Assistant OneControl entities will be in an error state until you\n// run the discovery script again. This is due to how Home Assistant stores entity information.\n// default: \n// mqttRetain = true\nvar mqttRetain = true;\n\n// Part of the discovery output is the definition of the manufacturer the component.\n// default: \n// deviceManufacturer = 'Lippert Components'\nvar deviceManufacturer = 'Lippert Components';\n\n// Part of the discovery output is the definition of the device that is used to \n// connect to the individual nodes.\n// default:\n// deviceViaDevice = 'OneControl Gateway';\nvar deviceViaDevice = 'OneControl Gateway';\n\n// Part of the discovery output is the definition of the model the component.\n// default:\n// model = 'OneControl';\nvar model = 'OneControl';\n\n// when the Home Assistant entity is created, you can prepend this string to the\n// entityID: 'sensor.example' would become 'sensor.namePresursor_example'\n// default:\n// namePrecursor= 'OneControl '\nvar namePrecursor = 'OneControl ';\n\n\n\n/* ############ Do not change anything below this line ############ */\nvar Release_Version = '2022.01.18a'\n\nglobal.set(\"eventsGetStream\",eventsGetStream);\nglobal.set(\"eventsSendStream\",eventsSendStream);\n\nglobal.set(\"filesCreate\",filesCreate);\nglobal.set(\"filesSaveTo\",filesSaveTo);\nglobal.set(\"filesNoDiscovery\",filesNoDiscovery);\n\nglobal.set(\"mqttDeleteAll\",mqttDeleteAll);\nglobal.set(\"mqttDiscoveryTopic\",mqttDiscoveryTopic);\nglobal.set(\"mqttInitialAvail\",mqttInitialAvail);\nglobal.set(\"mqttInitialState\",mqttInitialState);\nglobal.set(\"mqttPublish\",mqttPublish);\nglobal.set(\"mqttRecordsOnly\",mqttRecordsOnly);\nglobal.set(\"mqttRetain\",mqttRetain);\n\n\n\nglobal.set(\"deviceManufacturer\",deviceManufacturer);\nglobal.set(\"deviceSWVersion\",Release_Version);\n\nglobal.set(\"deviceViaDevice\",deviceViaDevice);\nglobal.set(\"deviceModel\",model);\nglobal.set(\"namePrecursor\",namePrecursor);\n\n\nreturn msg;\n/*\n * Copyright Robert Perciaccante\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n**/",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1260,
"y": 120,
"wires": [
[
"aa1ffe397c27678d"
]
]
},
{
"id": "a80200c65e78f34a",
"type": "inject",
"z": "c5bf60a40630c5e3",
"g": "6858fb2384f7f246",
"name": "Load Config",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"payloadType": "date",
"x": 1070,
"y": 120,
"wires": [
[
"e0aac92236e32259"
]
]
},
{
"id": "aa1ffe397c27678d",
"type": "debug",
"z": "c5bf60a40630c5e3",
"g": "6858fb2384f7f246",
"name": "Debug",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1450,
"y": 120,
"wires": []
},
{
"id": "888e1201759d2203",
"type": "debug",
"z": "c5bf60a40630c5e3",
"g": "2ec83346dffc7d94",
"name": "Debug",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1450,
"y": 480,
"wires": []
},
{
"id": "273da8d4173943bb",
"type": "yaml",
"z": "c5bf60a40630c5e3",
"g": "2ec83346dffc7d94",
"property": "payload",
"name": "",
"x": 1230,
"y": 360,
"wires": [
[
"dffd7703ab060e9f"
]
]
},
{
"id": "11af832c02c64601",
"type": "file",
"z": "c5bf60a40630c5e3",
"g": "2ec83346dffc7d94",
"name": "",
"filename": "filename",
"filenameType": "msg",
"appendNewline": false,
"createDir": true,
"overwriteFile": "true",
"encoding": "none",
"x": 1440,
"y": 440,
"wires": [
[
"888e1201759d2203"
]
]
},
{
"id": "9be463bbf9a8f997",
"type": "function",
"z": "c5bf60a40630c5e3",
"g": "2ec83346dffc7d94",
"name": "JSON Filename",
"func": "msg.filename = msg.filename +\".json\"\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1420,
"y": 400,
"wires": [
[
"11af832c02c64601"
]
]
},
{
"id": "99f937e3894a08b8",
"type": "json",
"z": "c5bf60a40630c5e3",
"g": "2ec83346dffc7d94",
"name": "",
"property": "payload",
"action": "",
"pretty": true,
"x": 1230,
"y": 400,
"wires": [
[
"9be463bbf9a8f997"
]
]
},
{
"id": "dffd7703ab060e9f",
"type": "function",
"z": "c5bf60a40630c5e3",
"g": "2ec83346dffc7d94",
"name": "YAML Filename",
"func": "msg.filename = msg.filename +\".yaml\"\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1420,
"y": 360,
"wires": [
[
"11af832c02c64601"
]
]
},
{
"id": "6a2e6e770864cdd0",
"type": "debug",
"z": "c5bf60a40630c5e3",
"g": "2ec83346dffc7d94",
"name": "Debug",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1390,
"y": 320,
"wires": []
},
{
"id": "f11ec4beb8586b8f",
"type": "mqtt out",
"z": "c5bf60a40630c5e3",
"g": "2ec83346dffc7d94",
"name": "",
"topic": "",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "4410210f.6939c",
"x": 1390,
"y": 280,
"wires": []
},
{
"id": "3e2a20b42543032b",
"type": "comment",
"z": "c5bf60a40630c5e3",
"g": "2ec83346dffc7d94",
"name": "Data Publishing",
"info": "",
"x": 1240,
"y": 220,
"wires": []
},
{
"id": "45a56438708b01c9",
"type": "comment",
"z": "c5bf60a40630c5e3",
"g": "6858fb2384f7f246",
"name": "Load Configuration Options for Process",
"info": "",
"x": 1230,
"y": 60,
"wires": []
},
{
"id": "98f4ba26adf91fe6",
"type": "function",
"z": "c5bf60a40630c5e3",
"g": "09ec6382357415d1",
"name": "Normalize Node Records",
"func": "var msg1 = {}\n\nmsg1.payload = {}\n/* Loop through incoming payload to rename the individual things so they can be better processed later */\n\nfor (var i = 0; i < msg.payload.length; i++) {\n var thing = {}\n \n var thingTypeUID = msg.payload[i].thingTypeUID.replace(\"idsmyrv:\",\"\")\n thingTypeUID = thingTypeUID.replace(\"-thing\",\"\")\n \n var thingUID = msg.payload[i].UID.replace(\"-thing:\",\"_\")\n thingUID = thingUID.replace(\"idsmyrv:\",\"\")\n thingUID = thingUID.replace(/:/g,\"_\")\n thingUID = thingUID.replace(/-/g,\"_\")\n \n /*\n // This uses the _online channel as source of availability\n availTopic = msg.payload[i].UID.replace(/:/g,\"_\")\n availTopic = availTopic.replace(/-/g,\"_\") + \"_online\"\n availTopic = \"smarthome/items/\" + availTopic + \"/state\"\n availTopicOn = \"on\"\n availTopicOff = \"off\"\n availAttr = \"value\"\n */\n \n // This uses the device online state for availability\n var availTopic = \"smarthome/things/\" + msg.payload[i].UID + \"/status\"\n var availTopicOn = \"online\"\n var availTopicOff = \"offline\"\n var availAttr = \"status\"\n \n \n var label = msg.payload[i].label.replace(\" Thing\",\"\")\n label = label.replace(\"OneControl \",\"\")\n\n //thing.hass = {}\n msg1.thing = msg.payload[i]\n msg1.thing.hass = {\"label\": label,\n \"thingConfig_OC\": msg.payload[i].configuration,\n \"UID_oc\": msg.payload[i].UID,\n \"UID_ha\": thingUID,\n \"thingTypeUID_oc\": msg.payload[i].thingTypeUID,\n \"thingTypeUID_ha\": thingTypeUID,\n \"thingChannelCount\": msg.payload[i].channels.length,\n \"availabilityTopic\": availTopic,\n \"availabilityTopicOn\": availTopicOn,\n \"availabilityTopicOff\": availTopicOff,\n \"availabilityTopicAttr\": availAttr,\n \"stateTopic\": global.get(\"mqttDiscoveryTopic\") +\"/binary_sensor/\" + thingUID + \"/status\"\n }\n \n msg1.payload = msg.payload[i].channels\n /* Send each thing record as a new message to split up the array and process the things individually */\n \n node.send(msg1)\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 410,
"y": 140,
"wires": [
[
"f5a3506e1a122e6b"
]
]
},
{
"id": "4a241eecd05a027a",
"type": "delay",
"z": "c5bf60a40630c5e3",
"g": "2ec83346dffc7d94",
"name": "Delay 1/2 sec",
"pauseType": "delay",
"timeout": "500",
"timeoutUnits": "milliseconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 1240,
"y": 300,
"wires": [
[
"6a2e6e770864cdd0",
"f11ec4beb8586b8f"
]
]
},
{
"id": "4efa180cc4812cc4",
"type": "function",
"z": "c5bf60a40630c5e3",
"g": "4514be5227808dc1",
"name": "Set Initial Availability (If enabled)",
"func": " \n// ####################### Begin Startup Availability Message Publishing #######################\n// This section is used by the 'startupAvailMsg' option. When this is set to true, this code will\n// send a dummy available payload to trigger the availability for the entities created in this tool.\n if (global.get(\"mqttInitialAvail\") === true) {\n var msg1 = {}\n msg1.payload = '{\"status\":\"' + msg.thing.hass.availabilityTopicOn + '\",\"statusDetail\":\"Initial Discovery\"}'\n msg1.topic = msg.thing.hass.availabilityTopic\n msg1.retain = true\n msg1.qos = 1\n msg1.type = \"record\"\n \n }\n// ####################### End Startup Availability Message Publishing #######################\nreturn [msg1,msg]",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 410,
"y": 700,
"wires": [
[
"eedd8594c925dbf3"
],
[]
]
},
{
"id": "7c688006afafe03e",
"type": "delay",
"z": "c5bf60a40630c5e3",
"g": "4514be5227808dc1",
"name": "Meter message rate",
"pauseType": "delay",
"timeout": "2",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,