-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflows.json
More file actions
5527 lines (5527 loc) · 241 KB
/
Copy pathflows.json
File metadata and controls
5527 lines (5527 loc) · 241 KB
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": "tab-hm",
"type": "tab",
"label": "House Mode",
"disabled": false,
"info": "House Mode orchestrator (STATE-ONLY). Occupancy Home/Away/Sleeping + storm/maintenance/guest overlays. Sleeping = 23:00\u201307:00 + adult home + 20m no-activity (motion/presence, any light on-off, any dimmer press) + TVs off + sitting-room lights off. Wake = first activity from 06:00 (2h re-entry block). No tag. No consumers wired yet."
},
{
"id": "tab-cam",
"type": "tab",
"label": "Camera Concierge",
"disabled": false,
"info": ""
},
{
"id": "5a86c1a3371ffe9e",
"type": "tab",
"label": "Heating Control",
"disabled": false,
"info": "DRAFT 18-06-2026 - DISABLED. Schedule + presence -> climate.netatmo_smart_thermostat via HomeKit. Set Netatmo native schedule to flat night baseline before enabling. Away->night 19.5, 24h-empty->away 12 (input_boolean.heating_extended_away toggle, defaults ON). 30-min heartbeat re-assert. See project_heating_nodered memory."
},
{
"id": "096ff268dc7bd2f0",
"type": "tab",
"label": "House Alarm",
"disabled": false,
"info": "House alarm: armed/disarmed by house_mode (Away\u2192arm_away, Sleeping\u2192arm_night, Home\u2192disarm). Alarm state notifications for House+Shed to all people. Shed auto-arm = NFC 2h re-arm (see Alarm NFC Tags flow). Battery low alerts (residents). Built 19-06-2026, updated 30-06-2026."
},
{
"id": "657e6b8b07b4cdf7",
"type": "tab",
"label": "Alarm NFC Tags",
"disabled": false,
"info": "Front-door NFC -> disarm house + TTS. Back-door NFC -> disarm shed for 2h then auto re-arm + TTS (each). Built 19-06-2026."
},
{
"id": "tab-ih",
"type": "tab",
"label": "Infra Health & Alerts",
"disabled": false,
"info": "Consolidated infra health + backup/Zabbix alerts (migrated from HA 28-06-2026). Group A: ih-watch->ih-engine. Group B: 4 http-in. All -> ih-send (type-prefix + quiet-hours 22-07 + 07:00 flush)."
},
{
"id": "tab-iw",
"type": "tab",
"label": "Infra Watchdog",
"disabled": false,
"info": ""
},
{
"id": "tab-pc",
"type": "tab",
"label": "Person Config",
"disabled": false,
"info": "Household person config: House Mode role + notification toggles, single source for hm-cfg/aa-cfg/camera/heating/hm-notify consumers.",
"env": []
},
{
"id": "sf-seed-watch",
"type": "subflow",
"name": "seed: entity -> context (self-heal)",
"info": "Reads one entity out of an ha-get-entities array (msg.payload) and stores it into flow/global context, warning only when the stored value CHANGES (so a 120s self-heal re-seed doesn't spam the log). Three modes: 'raw' (store the state string, with an optional fallback), 'boolean' (store state==='on'), 'timestamped' (store {state, at:<ms from last_changed>} -- returns null if the entity isn't found, since there's nothing usable to seed). Replaces the three hand-copied seed functions that used to live in Camera Concierge (house_mode, front_door) and Infra Health (maintenance_mode).",
"category": "",
"in": [
{
"x": 60,
"y": 60,
"wires": [
{
"id": "sf-seed-watch-fn"
}
]
}
],
"out": [],
"env": [
{
"name": "entityId",
"type": "str",
"value": "",
"ui": {
"type": "input",
"opts": {
"types": [
"str"
]
}
}
},
{
"name": "scope",
"type": "str",
"value": "flow",
"ui": {
"type": "select",
"opts": {
"opts": [
{
"v": "flow"
},
{
"v": "global"
}
]
}
}
},
{
"name": "key",
"type": "str",
"value": "",
"ui": {
"type": "input",
"opts": {
"types": [
"str"
]
}
}
},
{
"name": "mode",
"type": "str",
"value": "raw",
"ui": {
"type": "select",
"opts": {
"opts": [
{
"v": "raw"
},
{
"v": "boolean"
},
{
"v": "timestamped"
}
]
}
}
},
{
"name": "fallback",
"type": "str",
"value": "",
"ui": {
"type": "input",
"opts": {
"types": [
"str"
]
}
}
},
{
"name": "logTag",
"type": "str",
"value": "",
"ui": {
"type": "input",
"opts": {
"types": [
"str"
]
}
}
}
],
"meta": {},
"color": "#DDAA99"
},
{
"id": "sf-dispatch-notify",
"type": "subflow",
"name": "dispatch: notify (person_config)",
"info": "Filters global.person_config for entries where env.flagName is truthy and notify_service is set, and emits one message per target with `action` set to that target's notify service (all other msg fields passed through unchanged). Replaces the identical hand-copied dispatch functions that used to live in each tab -- fixes the 24-08-2026 bug where the flat-array return (outputs:1) silently dropped every recipient after the first.",
"category": "",
"in": [
{
"x": 60,
"y": 60,
"wires": [
{
"id": "sf-dispatch-get"
}
]
}
],
"out": [
{
"x": 300,
"y": 60,
"wires": [
{
"id": "sf-dispatch-fn",
"port": 0
}
]
}
],
"env": [
{
"name": "flagName",
"type": "str",
"value": "",
"ui": {
"type": "input",
"opts": {
"types": [
"str"
]
}
}
}
],
"meta": {},
"color": "#DDAA99"
},
{
"id": "ha-server",
"type": "server",
"name": "Home Assistant",
"version": 5,
"addon": false,
"rejectUnauthorizedCerts": false,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true,
"heartbeat": true,
"heartbeatInterval": 30,
"areaSelector": "friendly",
"deviceSelector": "friendly",
"entitySelector": "friendly",
"statusSeparator": "at: ",
"statusYear": "hidden",
"statusMonth": "short",
"statusDay": "numeric",
"statusHourCycle": "h23",
"statusTimeFormat": "h:m",
"enableGlobalContextStore": false
},
{
"id": "tls-insecure",
"type": "tls-config",
"name": "insecure (self-signed)",
"cert": "",
"key": "",
"ca": "",
"certname": "",
"keyname": "",
"caname": "",
"servername": "",
"verifyservercert": false
},
{
"id": "mqtt-frigate",
"type": "mqtt-broker",
"name": "Frigate MQTT",
"broker": "${MQTT_HOST}",
"port": "1883",
"clientid": "node-red-cam",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true
},
{
"id": "pc-ui-base",
"type": "ui-base",
"name": "Household Dashboard",
"path": "/dashboard",
"includeClientData": true,
"acceptsClientConfig": [
"ui-notification",
"ui-control"
],
"showPathInSidebar": false,
"headerContent": "page",
"navigationStyle": "default",
"titleBarStyle": "default",
"showReconnectNotification": true,
"notificationDisplayTime": 1,
"showDisconnectNotification": true,
"allowInstall": false
},
{
"id": "pc-ui-theme",
"type": "ui-theme",
"name": "Default",
"colors": {
"surface": "#ffffff",
"primary": "#0094CE",
"bgPage": "#eeeeee",
"groupBg": "#ffffff",
"groupOutline": "#cccccc"
},
"sizes": {
"density": "default",
"pagePadding": "12px",
"groupGap": "12px",
"groupBorderRadius": "4px",
"widgetGap": "12px"
}
},
{
"id": "pc-ui-page",
"type": "ui-page",
"name": "Household Config",
"ui": "pc-ui-base",
"path": "/household",
"icon": "home",
"layout": "grid",
"theme": "pc-ui-theme",
"breakpoints": [
{
"name": "Default",
"px": "0",
"cols": "3"
},
{
"name": "Tablet",
"px": "576",
"cols": "6"
},
{
"name": "Small Desktop",
"px": "768",
"cols": "9"
},
{
"name": "Desktop",
"px": "1024",
"cols": "12"
}
],
"order": 99,
"className": "",
"visible": "true",
"disabled": "false"
},
{
"id": "pc-ui-group",
"type": "ui-group",
"name": "People",
"page": "pc-ui-page",
"width": "12",
"height": "1",
"order": 1,
"showTitle": true,
"className": "",
"visible": "true",
"disabled": "false"
},
{
"id": "sf-seed-watch-fn",
"type": "function",
"z": "sf-seed-watch",
"name": "seed",
"func": "const scopeCtx = env.get('scope') === 'global' ? global : flow;\nconst key = env.get('key');\nconst entityId = env.get('entityId');\nconst mode = env.get('mode');\nconst logTag = env.get('logTag');\nconst fallback = env.get('fallback') || null;\n\nconst ents = Array.isArray(msg.payload) ? msg.payload : [];\nconst e = ents.find(x => x.entity_id === entityId);\n\nlet value, display;\nif (mode === 'boolean') {\n value = !!e && e.state === 'on';\n display = value ? 'on' : 'off';\n} else if (mode === 'timestamped') {\n if (!e) return null;\n const at = e.last_changed ? Date.parse(e.last_changed) : Date.now();\n value = { state: e.state, at: at };\n display = e.state;\n} else {\n value = e ? e.state : fallback;\n display = value;\n}\n\nconst prev = scopeCtx.get(key);\nscopeCtx.set(key, value);\n\nconst prevDisplay = (mode === 'timestamped') ? (prev && prev.state) : prev;\nif (prevDisplay === undefined || prevDisplay !== display) {\n node.warn(logTag + ' seeded: ' + display);\n}\nreturn null;\n",
"outputs": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 180,
"y": 60,
"wires": []
},
{
"id": "sf-dispatch-get",
"type": "ha-get-entities",
"z": "sf-dispatch-notify",
"name": "presence states",
"server": "ha-server",
"version": 3,
"rules": [],
"outputType": "array",
"outputEmptyResults": true,
"outputLocationType": "msg",
"outputLocation": "pcEntities",
"outputResultsCount": 1,
"output_type": "array",
"output_empty_results": true,
"output_location_type": "msg",
"output_location": "pcEntities",
"output_results_count": 1,
"x": 180,
"y": 120,
"wires": [
[
"sf-dispatch-fn"
]
]
},
{
"id": "sf-dispatch-fn",
"type": "function",
"z": "sf-dispatch-notify",
"name": "dispatch",
"func": "const PC = global.get('person_config') || {};\nconst flagName = env.get('flagName');\n// Presence for people with \"Only when home\" on. Same rule as the alarm notify\n// engine (na-fn homeP): person entity is home OR their phone ping is on.\nconst ents = Array.isArray(msg.pcEntities) ? msg.pcEntities : [];\ndelete msg.pcEntities;\nconst S = function(id){ const e = ents.find(function(x){ return x.entity_id === id; }); return e && e.state; };\nconst isHome = function(pid, c){ return S(pid) === 'home' || (!!c.ping && S(c.ping) === 'on'); };\nconst skipped = [];\nconst targets = Object.keys(PC).filter(function(pid){\n var c = PC[pid];\n if (!(c && c[flagName] && c.notify_service)) return false;\n if (c.only_when_home && !isHome(pid, c)) { skipped.push(c.name || pid); return false; }\n return true;\n}).map(function(pid){ return PC[pid].notify_service; });\nif (skipped.length) node.warn('[dispatch ' + flagName + '] only when home, not home: ' + skipped.join(', '));\nif (!targets.length) return null;\nreturn [targets.map(function(t){ return Object.assign({}, msg, { action: t }); })];",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 180,
"y": 60,
"wires": [
[]
]
},
{
"id": "hm-presence",
"type": "server-state-changed",
"z": "tab-hm",
"name": "indoor motion",
"server": "ha-server",
"version": 6,
"outputs": 1,
"exposeAsEntityConfig": "",
"entities": {
"entity": [
"binary_sensor.hallway_motion_sensor_occupancy",
"binary_sensor.landing_motion_sensor_occupancy",
"binary_sensor.sitting_room_presence_occupancy",
"binary_sensor.office_presence_occupancy"
],
"substring": "",
"regex": ""
},
"outputInitially": false,
"stateType": "str",
"ifState": "",
"ifStateType": "str",
"ifStateOperator": "is",
"outputOnlyOnStateChange": true,
"for": 0,
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": true,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "eid",
"propertyType": "msg",
"value": "",
"valueType": "entityId"
},
{
"property": "topic",
"propertyType": "msg",
"value": "presence",
"valueType": "str"
},
{
"property": "evt",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
}
],
"entityidfiltertype": "list",
"x": 150,
"y": 120,
"wires": [
[
"hm-pres-get",
"hm-engine"
]
]
},
{
"id": "hm-lights",
"type": "server-state-changed",
"z": "tab-hm",
"name": "all lights (activity)",
"server": "ha-server",
"version": 6,
"outputs": 1,
"exposeAsEntityConfig": "",
"entities": {
"entity": [
"light.hallway",
"light.landing",
"light.aoife_bedroom",
"light.office",
"light.colm_bedroom",
"light.cian_bedroom",
"light.sitting_room",
"light.kitchen",
"light.downstairs",
"light.upstairs",
"light.sitting_room_tv_lightstrip",
"light.kitchen_tv_lightstrip",
"light.olivia_bedside",
"light.landing_1",
"light.colm_ceiling",
"light.cian_ceiling",
"light.kitchen_1",
"light.kitchen_2",
"light.kitchen_3",
"light.office_ceiling",
"light.hallway_1",
"light.aoife_ceiling",
"light.colm_bedside",
"light.sitting_room_stand",
"light.sitting_room_lamp"
],
"substring": "",
"regex": ""
},
"outputInitially": false,
"stateType": "str",
"ifState": "",
"ifStateType": "str",
"ifStateOperator": "is",
"outputOnlyOnStateChange": true,
"for": 0,
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": true,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "eid",
"propertyType": "msg",
"value": "",
"valueType": "entityId"
},
{
"property": "topic",
"propertyType": "msg",
"value": "lights",
"valueType": "str"
},
{
"property": "evt",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
}
],
"entityidfiltertype": "list",
"x": 160,
"y": 300,
"wires": [
[
"hm-engine"
]
]
},
{
"id": "hm-dimmers",
"type": "server-state-changed",
"z": "tab-hm",
"name": "dimmer presses",
"server": "ha-server",
"version": 6,
"outputs": 1,
"exposeAsEntityConfig": "",
"entities": {
"entity": [
"input_text.colm_bedroom_dimmer_helper_last_controller_event",
"input_text.sitting_room_dimmer_helper_last_controller_event",
"input_text.kitchen_dimmer_helper_last_controller_event",
"input_text.office_dimmer_helper_last_controller_event"
],
"substring": "",
"regex": ""
},
"outputInitially": false,
"stateType": "str",
"ifState": "",
"ifStateType": "str",
"ifStateOperator": "is",
"outputOnlyOnStateChange": true,
"for": 0,
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": true,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "eid",
"propertyType": "msg",
"value": "",
"valueType": "entityId"
},
{
"property": "topic",
"propertyType": "msg",
"value": "dimmer",
"valueType": "str"
},
{
"property": "evt",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
}
],
"entityidfiltertype": "list",
"x": 160,
"y": 380,
"wires": [
[
"hm-engine"
]
]
},
{
"id": "hm-tv",
"type": "server-state-changed",
"z": "tab-hm",
"name": "tvs (level)",
"server": "ha-server",
"version": 6,
"outputs": 1,
"exposeAsEntityConfig": "",
"entities": {
"entity": [
"binary_sensor.lg_tv_online",
"binary_sensor.samsung_tv_online"
],
"substring": "",
"regex": ""
},
"outputInitially": false,
"stateType": "str",
"ifState": "",
"ifStateType": "str",
"ifStateOperator": "is",
"outputOnlyOnStateChange": true,
"for": 0,
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": true,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "eid",
"propertyType": "msg",
"value": "",
"valueType": "entityId"
},
{
"property": "topic",
"propertyType": "msg",
"value": "tv",
"valueType": "str"
},
{
"property": "evt",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
}
],
"entityidfiltertype": "list",
"x": 140,
"y": 460,
"wires": [
[
"hm-engine"
]
]
},
{
"id": "hm-storm",
"type": "server-state-changed",
"z": "tab-hm",
"name": "met eireann level",
"server": "ha-server",
"version": 6,
"outputs": 1,
"exposeAsEntityConfig": "",
"entities": {
"entity": [
"sensor.met_eireann_warning_level"
],
"substring": "",
"regex": ""
},
"outputInitially": false,
"stateType": "str",
"ifState": "",
"ifStateType": "str",
"ifStateOperator": "is",
"outputOnlyOnStateChange": true,
"for": 0,
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": true,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "eid",
"propertyType": "msg",
"value": "",
"valueType": "entityId"
},
{
"property": "topic",
"propertyType": "msg",
"value": "storm",
"valueType": "str"
}
],
"entityidfiltertype": "list",
"x": 160,
"y": 540,
"wires": [
[
"hm-engine"
]
]
},
{
"id": "hm-manual",
"type": "server-state-changed",
"z": "tab-hm",
"name": "manual changes",
"server": "ha-server",
"version": 6,
"outputs": 1,
"exposeAsEntityConfig": "",
"entities": {
"entity": [
"input_select.house_mode",
"input_boolean.storm_mode",
"input_boolean.maintenance_mode"
],
"substring": "",
"regex": ""
},
"outputInitially": false,
"stateType": "str",
"ifState": "",
"ifStateType": "str",
"ifStateOperator": "is",
"outputOnlyOnStateChange": true,
"for": 0,
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": true,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "eid",
"propertyType": "msg",
"value": "",
"valueType": "entityId"
},
{
"property": "topic",
"propertyType": "msg",
"value": "manual",
"valueType": "str"
},
{
"property": "ent",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"entityidfiltertype": "list",
"x": 160,
"y": 620,
"wires": [
[
"hm-engine"
]
]
},
{
"id": "hm-seed-inj",
"type": "inject",
"z": "tab-hm",
"name": "seed on deploy",
"props": [
{
"p": "topic",
"v": "tick",
"vt": "str"
}
],
"repeat": "120",
"crontab": "",
"once": true,
"onceDelay": "5",
"topic": "tick",
"x": 120,
"y": 720,
"wires": [
[
"hm-cfg"
]
]
},
{
"id": "hm-get",
"type": "ha-get-entities",
"z": "tab-hm",
"name": "all entities",
"server": "ha-server",
"version": 3,
"rules": [],
"outputType": "array",
"outputEmptyResults": true,
"outputLocationType": "msg",
"outputLocation": "payload",
"outputResultsCount": 1,
"output_type": "array",
"output_empty_results": true,
"output_location_type": "msg",
"output_location": "payload",
"output_results_count": 1,
"x": 720,
"y": 720,
"wires": [
[
"hm-engine"
]
]
},
{
"id": "hm-tick",
"type": "inject",
"z": "tab-hm",
"name": "tick 2m",
"props": [
{
"p": "topic",
"v": "tick",
"vt": "str"
}
],
"repeat": "120",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "tick",
"x": 340,
"y": 800,
"wires": [
[
"hm-get"
]
]
},
{
"id": "hm-engine",
"type": "function",
"z": "tab-hm",
"name": "Mode engine",
"func": "\nconst NR='32733c512f63453f895a569740484151';\nconst RESIDENTS=flow.get('residents')||[];\nconst GUESTS=flow.get('guests')||[];\nconst INDOOR=['binary_sensor.hallway_motion_sensor_occupancy','binary_sensor.landing_motion_sensor_occupancy','binary_sensor.sitting_room_presence_occupancy','binary_sensor.office_presence_occupancy'];\nconst AWAY_MS=20*60*1000, OCC_LOOKBACK=15*60*1000, SLEEP_MS=20*60*1000, MAINT_MS=4*3600*1000, HOLD_MS=4*3600*1000, WAKE_BLOCK_MS=2*3600*1000;\nconst WAKE_FROM=360; // 06:00 in minutes\n// 03-08-2026: the wake test had only a LOWER bound, so ANY indoor motion from 06:00\n// to 23:59 woke the house from Sleeping and disarmed the night alarm. It bit on 02-08\n// at 22:49, logged absurdly as 'morning activity'. Hence a 23:00 cut-off,\n// keeping a late-evening grace hour and accepting that 22:20-23:00 can still wake.\nconst WAKE_UNTIL=1380; // 23:00 in minutes\nconst NIGHT_LO=1320, NIGHT_HI=420; // 22:00 .. 07:00\n// the people half is derived from the configured residents/guests, so adding\n// someone in the environment is enough - nothing here needs editing.\nconst PEOPLE_ENTS=RESIDENTS.concat(GUESTS).reduce(function(a,p){if(p.person)a.push(p.person);if(p.ping)a.push(p.ping);return a;},[]);\nconst WATCH=PEOPLE_ENTS.concat(['binary_sensor.lg_tv_online','binary_sensor.samsung_tv_online','light.sitting_room','sensor.met_eireann_warning_level','input_select.house_mode','input_boolean.storm_mode','input_boolean.maintenance_mode']).concat(INDOOR);\nfunction nowMs(){return Date.now();}\nfunction dub(){return new Date().toLocaleString('en-IE',{timeZone:'Europe/Dublin',hour12:false});}\nfunction mins(){var d=new Date();return parseInt(d.toLocaleString('en-IE',{timeZone:'Europe/Dublin',hour:'2-digit',hour12:false}),10)*60+parseInt(d.toLocaleString('en-IE',{timeZone:'Europe/Dublin',minute:'2-digit'}),10);}\nvar st=flow.get('st')||{};\nfunction residentHome(){return RESIDENTS.some(function(r){return st[r.person]==='home'||st[r.ping]==='on';});}\nfunction guestHome(){return GUESTS.some(function(g){return st[g.person]==='home'||st[g.ping]==='on';});}\nfunction anyoneHome(){return residentHome()||guestHome();}\nfunction indoorAny(){return INDOOR.some(function(e){return st[e]==='on';});}\nfunction indoorRecent(){return (nowMs()-(flow.get('lastIndoorMotion')||0))<OCC_LOOKBACK;}\nfunction mode(){return flow.get('mode')||st['input_select.house_mode']||'Home';}\nfunction holdActive(){return (flow.get('manual_until')||0)>nowMs();}\nfunction clrAway(){var t=context.get('awayTimer');if(t){clearTimeout(t);context.set('awayTimer',null);}}\nfunction scheduleAway(delay){context.set('awayTimer',setTimeout(attemptAway,delay));}\nfunction attemptAway(){\n context.set('awayTimer',null);\n // guest_mode blocks Away entirely: someone is home who has no tracked phone,\n // in the house and set guest_mode, but only maintenance_mode was checked here, so the\n // house went Away 20m later and pushed a false notification. The House Alarm already\n // honoured guest_mode and correctly refused to arm \u2014 this brings the orchestrator in line.\n if(anyoneHome()||st['input_boolean.guest_mode']==='on'||st['input_boolean.maintenance_mode']==='on'||holdActive()){return;}\n if(indoorAny()||indoorRecent()){node.warn('[house-mode] away deferred: indoor motion - retry 20m');scheduleAway(AWAY_MS);return;}\n if(mode()!=='Away') emitMode('Away','all residents left (20m)');\n}\nfunction nightWindow(){var m=mins(); return m>=NIGHT_LO || m<NIGHT_HI;}\nfunction quietLevel(){return st['binary_sensor.lg_tv_online']!=='on' && st['binary_sensor.samsung_tv_online']!=='on' && !indoorAny() && st['light.sitting_room']!=='on';}\nfunction emitMode(opt,reason){\n if(mode()===opt)return;\n flow.set('mode',opt); flow.set('last_auto',opt); st['input_select.house_mode']=opt; flow.set('st',st);\n node.send([{entity:'input_select.house_mode',option:opt},null,null,{payload:'House mode \u2192 '+opt+' ('+reason+')'},{payload:dub()+' MODE '+opt+' ('+reason+')\\n'},{payload:reason}]);\n}\nfunction emitOverlay(id,on,reason){\n var ent='input_boolean.'+id; if((st[ent]==='on')===on)return;\n st[ent]=on?'on':'off'; flow.set('st',st);\n node.send([null, on?{entity:ent}:null, on?null:{entity:ent}, {payload:(on?'Overlay ON: ':'Overlay OFF: ')+id+' ('+reason+')'}, {payload:dub()+' OVERLAY '+id+'='+(on?'on':'off')+' ('+reason+')\\n'}, null]);\n}\n// Shared by all three activity paths below (get-entities seed, presence\n// fast-path, light/tv/dimmer path) -- used to be copy-pasted three times,\n// which is how the 23:00 cut-off bug (02-08-2026) nearly happened twice.\nfunction tryWake(sourceEnt){\n if(mode()==='Sleeping' && mins()>=WAKE_FROM && mins()<WAKE_UNTIL){\n flow.set('sleep_block_until', nowMs()+WAKE_BLOCK_MS);\n emitMode('Home','morning activity ('+(sourceEnt||T)+')');\n }\n}\nfunction evaluate(){\n var warn=(st['sensor.met_eireann_warning_level']||'none').toString().toLowerCase();\n emitOverlay('storm_mode',(warn==='orange'||warn==='red'),'Met \u00c9ireann '+warn);\n if(st['input_boolean.maintenance_mode']==='on'){var ms=flow.get('maint_since'); if(ms&&nowMs()-ms>MAINT_MS) emitOverlay('maintenance_mode',false,'4h auto-expire');}\n if(st['input_boolean.maintenance_mode']==='on'){ clrAway(); if(mode()==='Away') emitMode('Home','maintenance active'); return; }\n if(holdActive()){clrAway();return;}\n var m=mode(); if(m==='Sleeping')return;\n if(!anyoneHome()){\n if(!context.get('awayTimer')) scheduleAway(AWAY_MS);\n return;\n }\n clrAway();\n if(m==='Away'){ emitMode('Home','resident returned'); return; }\n var la=flow.get('last_activity'); if(la===undefined){flow.set('last_activity',nowMs()); la=nowMs();}\n if (T === 'tick' && m === 'Home' && nightWindow()) {\n var lastDiagLog = context.get('lastSleepDiag') || 0;\n if (nowMs() - lastDiagLog > 5*60*1000) {\n context.set('lastSleepDiag', nowMs());\n node.warn('[sleep-diag] resident=' + residentHome() + ' quiet=' + quietLevel() + ' idleMin=' + Math.round((nowMs()-la)/60000) + ' blockUntil=' + (flow.get('sleep_block_until') ? new Date(flow.get('sleep_block_until')).toISOString() : 'none'));\n }\n }\n if(m==='Home' && residentHome() && nightWindow() && quietLevel() && (nowMs()-la>=SLEEP_MS) && nowMs()>(flow.get('sleep_block_until')||0)){\n emitMode('Sleeping','quiet 20m, no activity (22:00\u201307:00)');\n }\n}\n\n// --- dispatch handlers (24-08-2026 split -- one named function per msg shape,\n// called from the thin router at the bottom in the exact order/short-circuit\n// pattern the inline version used. evaluate()/attemptAway()/emitMode() etc.\n// above are untouched. ---\nfunction seedFromArray(){\n var want={}; WATCH.forEach(function(w){want[w]=1;});\n msg.payload.forEach(function(e){ if(e&&e.entity_id&&want[e.entity_id]) st[e.entity_id]=e.state; });\n if(INDOOR.some(function(e){return st[e]==='on';})) flow.set('lastIndoorMotion',nowMs());\n flow.set('st',st);\n if(T==='presence'){\n var indoorFired=INDOOR.indexOf(msg.eid)>=0&&st[msg.eid]==='on';\n if(indoorFired){ flow.set('last_activity',nowMs()); flow.set('lastIndoorMotion',nowMs()); tryWake(msg.eid); }\n } else if(T!=='tick'){ flow.set('mode', flow.get('mode')||st['input_select.house_mode']||'Home'); flow.set('last_activity',nowMs()); }\n evaluate();\n}\nfunction handlePresenceFastPath(){\n // FAST-PATH (23-07-2026, issue #4): indoor motion -> immediate wake, bypassing the get-entities round-trip.\n // Read from eventData (entityId/entityState valueTypes are flaky on this palette).\n var Dp=(msg.evt&&msg.evt.entity_id)?msg.evt:null;\n var pent=Dp?Dp.entity_id:msg.eid;\n var pstt=Dp&&Dp.new_state?Dp.new_state.state:msg.payload;\n if(INDOOR.indexOf(pent)>=0 && pstt==='on'){\n st[pent]='on'; flow.set('st',st);\n flow.set('lastIndoorMotion',nowMs());\n flow.set('last_activity',nowMs());\n tryWake(pent);\n }\n}\nfunction handleActivity(){\n // activity = any light change, any dimmer press, or an indoor sensor turning on\n var Da=(msg.evt&&msg.evt.entity_id)?msg.evt:null;\n var aent=Da?Da.entity_id:msg.eid;\n flow.set('last_activity',nowMs());\n tryWake(aent);\n}\nfunction handleManual(){\n var uid=(msg.ent&&msg.ent.context&&msg.ent.context.user_id)||null;\n if(uid===NR) return;\n if(msg.eid==='input_select.house_mode'){ flow.set('mode',msg.payload); flow.set('manual_until',nowMs()+HOLD_MS); node.send([null,null,null,null,{payload:dub()+' MANUAL house_mode='+msg.payload+' (hold 4h)\\n'},{payload:'changed by hand'}]); }\n else if(msg.eid==='input_boolean.maintenance_mode'){ flow.set('maint_since', msg.payload==='on'?nowMs():null); }\n}\n\nvar T=msg.topic;\n// seed from ha-get-entities (array)\nif(Array.isArray(msg.payload)){ seedFromArray(); return null; }\nif(msg.eid && !Array.isArray(msg.payload)){ st[msg.eid]=msg.payload; flow.set('st',st); }\nif(T==='presence' && !Array.isArray(msg.payload)){ handlePresenceFastPath(); return null; }\nvar act=(T==='lights')||(T==='tv')||(T==='dimmer');\nif(act){ handleActivity(); }\nfunction reconcileEntity(){\n // 23-09-2026: an HA Core restart reset input_select.house_mode to its configured\n // 'initial' (Home) via a restore_state race -- hm-engine's own flow.mode (in NR's\n // context, which survives an HA-only restart) stayed correct the whole time, but\n // nothing ever pushed that correction back onto the entity, so heating/camera\n // concierge (which read the raw entity) acted on the wrong value for hours.\n // This mirrors the House Alarm tab's existing aa-reconcile-fn pattern.\n var entVal = st['input_select.house_mode'];\n var internal = flow.get('mode');\n if(internal && entVal && entVal!==internal && !holdActive()){\n node.warn('[house-mode] RECONCILE: entity='+entVal+' internal='+internal+' -- correcting entity to match internal state');\n node.send([{entity:'input_select.house_mode',option:internal},null,null,{payload:'House mode entity drifted to '+entVal+' -- corrected back to '+internal},{payload:dub()+' RECONCILE entity='+entVal+' -> '+internal+'\\n'},null]);\n }\n}\nif(T==='tick'){ reconcileEntity(); evaluate(); return null; }\nif(T==='manual'){ handleManual(); return null; }\nevaluate();\nreturn null;\n",
"outputs": 6,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1150,
"y": 400,
"wires": [
[
"hm-set-mode"
],
[
"hm-overlay-on"
],
[
"hm-overlay-off"
],
[
"hm-notify-dispatch"
],
[
"hm-logfile"
],
[
"hm-reason"
]
]
},
{
"id": "hm-set-mode",
"type": "api-call-service",
"z": "tab-hm",
"name": "set house_mode",
"server": "ha-server",
"version": 5,
"debugenabled": false,
"action": "input_select.select_option",
"areaId": [],
"deviceId": [],
"entityId": [],
"data": "{\"entity_id\": msg.entity, \"option\": msg.option}",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 2010,
"y": 300,
"wires": [
[]
]
},
{
"id": "hm-overlay-on",
"type": "api-call-service",
"z": "tab-hm",
"name": "overlay turn_on",
"server": "ha-server",
"version": 5,
"debugenabled": false,
"action": "input_boolean.turn_on",
"areaId": [],
"deviceId": [],
"entityId": [],
"data": "{\"entity_id\": msg.entity}",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 2000,
"y": 360,
"wires": [
[]
]
},
{
"id": "hm-overlay-off",
"type": "api-call-service",
"z": "tab-hm",
"name": "overlay turn_off",
"server": "ha-server",
"version": 5,
"debugenabled": false,
"action": "input_boolean.turn_off",
"areaId": [],
"deviceId": [],