Fix timer not being canceled when motion is detected again

This commit is contained in:
2025-02-23 22:54:21 -05:00
parent 0cf6f2be52
commit 98f30818f5

View File

@ -1218,8 +1218,8 @@
], ],
"x": 14, "x": 14,
"y": 859, "y": 859,
"w": 792, "w": 612,
"h": 202 "h": 262
}, },
{ {
"id": "550e5b2d99316b12", "id": "550e5b2d99316b12",
@ -1851,8 +1851,8 @@
], ],
"x": 894, "x": 894,
"y": 739, "y": 739,
"w": 792, "w": 612,
"h": 202 "h": 262
}, },
{ {
"id": "0f7fdf39e4400032", "id": "0f7fdf39e4400032",
@ -2041,9 +2041,9 @@
"fa7c83f1dece9741" "fa7c83f1dece9741"
], ],
"x": 14, "x": 14,
"y": 1079, "y": 1139,
"w": 972, "w": 792,
"h": 262 "h": 322
}, },
{ {
"id": "5c1df7492351b925", "id": "5c1df7492351b925",
@ -2064,9 +2064,9 @@
"5524e8ba9b5545be" "5524e8ba9b5545be"
], ],
"x": 894, "x": 894,
"y": 959, "y": 1019,
"w": 792, "w": 612,
"h": 202 "h": 262
}, },
{ {
"id": "505e378279011759", "id": "505e378279011759",
@ -2087,9 +2087,9 @@
"81129efa6676b58e" "81129efa6676b58e"
], ],
"x": 894, "x": 894,
"y": 1179, "y": 1299,
"w": 792, "w": 612,
"h": 202 "h": 262
}, },
{ {
"id": "fba69dfc80829db7", "id": "fba69dfc80829db7",
@ -10640,7 +10640,7 @@
"output_location": "", "output_location": "",
"output_location_type": "none", "output_location_type": "none",
"x": 530, "x": 530,
"y": 1020, "y": 1080,
"wires": [ "wires": [
[] []
] ]
@ -10849,8 +10849,8 @@
"z": "eff21041cc941fef", "z": "eff21041cc941fef",
"g": "8aee4d340a136bac", "g": "8aee4d340a136bac",
"name": "Delay", "name": "Delay",
"func": "const states = global.get('homeassistant.homeAssistant.states')\nconst lights = states['light.downstairs_bathroom_lights'].state\nconst duration = states['input_number.downstairs_bathroom_lights_off_delay'].state\nconst lux = parseInt(states['sensor.downstairs_bathroom_illuminance'].state)\nconst threshold = parseInt(states['input_number.downstairs_bathroom_lux_threshold'].state)\nconst payload = msg.payload\nconst newDuration = duration * 60\n\nif (payload === 'on') {\n if (lux <= threshold && lights === 'off') {\n node.status({fill:'green',shape:'dot',text:'Turning lights on'})\n node.send([msg,null])\n } else {\n if (lights === 'on') {\n node.status({fill:'red',shape:'ring',text:'Lights already on'})\n } else {\n node.status({fill:'red',shape:'ring',text:'Too bright'})\n }\n }\n} else if (payload === 'off') {\n if (lights === 'on') {\n msg.duration = newDuration\n node.status({fill:\"green\",shape:\"dot\",text:parseInt(duration) + ' minutes'})\n node.send([null,msg])\n } else {\n node.status({fill:\"red\",shape:\"ring\",text:\"Lights already off\"})\n }\n}", "func": "const states = global.get('homeassistant.homeAssistant.states')\nconst lights = states['light.downstairs_bathroom_lights'].state\nconst duration = states['input_number.downstairs_bathroom_lights_off_delay'].state\nconst lux = parseInt(states['sensor.downstairs_bathroom_illuminance'].state)\nconst threshold = parseInt(states['input_number.downstairs_bathroom_lux_threshold'].state)\nconst payload = msg.payload\nconst newDuration = duration * 60\n\nif (payload === 'on') {\n if (lux <= threshold && lights === 'off') {\n node.status({fill:'green',shape:'dot',text:'Turning lights on'})\n node.send([msg,msg,null])\n } else {\n if (lights === 'on') {\n node.status({fill:'red',shape:'ring',text:'Lights already on'})\n node.send([null,msg,null])\n } else {\n node.status({fill:'red',shape:'ring',text:'Too bright'})\n }\n }\n} else if (payload === 'off') {\n if (lights === 'on') {\n msg.duration = newDuration\n node.status({fill:\"green\",shape:\"dot\",text:parseInt(duration) + ' minutes'})\n node.send([null,null,msg])\n } else {\n node.status({fill:\"red\",shape:\"ring\",text:\"Lights already off\"})\n }\n}",
"outputs": 2, "outputs": 3,
"timeout": "", "timeout": "",
"noerr": 0, "noerr": 0,
"initialize": "", "initialize": "",
@ -10862,10 +10862,18 @@
[ [
"b281061a4b08d2eb" "b281061a4b08d2eb"
], ],
[
"41a8d5ef20cf55d7"
],
[ [
"b7d94cd0e420c650" "b7d94cd0e420c650"
] ]
], ],
"outputLabels": [
"Lights On",
"Cancel Timer",
"Start Timer"
],
"icon": "node-red/timer.svg" "icon": "node-red/timer.svg"
}, },
{ {
@ -10895,7 +10903,7 @@
"domain": "timer", "domain": "timer",
"service": "start", "service": "start",
"x": 530, "x": 530,
"y": 960, "y": 1020,
"wires": [ "wires": [
[] []
] ]
@ -10926,8 +10934,8 @@
"blockInputOverrides": false, "blockInputOverrides": false,
"domain": "timer", "domain": "timer",
"service": "cancel", "service": "cancel",
"x": 710, "x": 530,
"y": 900, "y": 960,
"wires": [ "wires": [
[] []
] ]
@ -10953,7 +10961,7 @@
} }
], ],
"x": 120, "x": 120,
"y": 1020, "y": 1080,
"wires": [ "wires": [
[ [
"5123a607588fa737" "5123a607588fa737"
@ -11045,9 +11053,7 @@
"x": 520, "x": 520,
"y": 900, "y": 900,
"wires": [ "wires": [
[ []
"41a8d5ef20cf55d7"
]
] ]
}, },
{ {
@ -11876,7 +11882,7 @@
} }
], ],
"x": 110, "x": 110,
"y": 1180, "y": 1240,
"wires": [ "wires": [
[ [
"7c4cc52be117251f" "7c4cc52be117251f"
@ -11892,23 +11898,31 @@
"z": "eff21041cc941fef", "z": "eff21041cc941fef",
"g": "ab4dbcc968a1d346", "g": "ab4dbcc968a1d346",
"name": "Delay", "name": "Delay",
"func": "const states = global.get('homeassistant.homeAssistant.states')\nconst lights = states['light.mud_room_overhead'].state\nconst selScene = states['input_text.mud_room_selected_scene'].state\nconst duration = states['input_number.mud_room_lights_off_delay'].state\nconst lux = parseInt(states['sensor.mud_room_illuminance'].state)\nconst threshold = parseInt(states['input_number.mud_room_lux_threshold'].state)\nconst payload = msg.payload\nconst newDuration = duration * 60\n\nif (payload === 'on') {\n if (lux <= threshold && (lights === 'off' || selScene === 'Nightlight')) {\n node.status({fill:'green',shape:'dot',text:'Turning lights on'})\n node.send([msg,null])\n } else {\n if (lights === 'on') {\n node.status({fill:'red',shape:'ring',text:'Lights already on'})\n } else {\n node.status({fill:'red',shape:'ring',text:'Too bright'})\n }\n }\n} else if (payload === 'off') {\n if (lights === 'on') {\n msg.duration = newDuration\n node.status({fill:\"green\",shape:\"dot\",text:parseInt(duration) + ' minutes'})\n node.send([null,msg])\n } else {\n node.status({fill:\"red\",shape:\"ring\",text:\"Lights already off\"})\n }\n}", "func": "const states = global.get('homeassistant.homeAssistant.states')\nconst lights = states['light.mud_room_overhead'].state\nconst selScene = states['input_text.mud_room_selected_scene'].state\nconst duration = states['input_number.mud_room_lights_off_delay'].state\nconst lux = parseInt(states['sensor.mud_room_illuminance'].state)\nconst threshold = parseInt(states['input_number.mud_room_lux_threshold'].state)\nconst payload = msg.payload\nconst newDuration = duration * 60\n\nif (payload === 'on') {\n if (lux <= threshold && (lights === 'off' || selScene === 'Nightlight')) {\n node.status({fill:'green',shape:'dot',text:'Turning lights on'})\n node.send([msg,msg,null])\n } else {\n if (lights === 'on') {\n node.status({fill:'red',shape:'ring',text:'Lights already on'})\n node.send([null,msg,null])\n } else {\n node.status({fill:'red',shape:'ring',text:'Too bright'})\n }\n }\n} else if (payload === 'off') {\n if (lights === 'on') {\n msg.duration = newDuration\n node.status({fill:\"green\",shape:\"dot\",text:parseInt(duration) + ' minutes'})\n node.send([null,null,msg])\n } else {\n node.status({fill:\"red\",shape:\"ring\",text:\"Lights already off\"})\n }\n}",
"outputs": 2, "outputs": 3,
"timeout": "", "timeout": "",
"noerr": 0, "noerr": 0,
"initialize": "", "initialize": "",
"finalize": "", "finalize": "",
"libs": [], "libs": [],
"x": 270, "x": 270,
"y": 1180, "y": 1240,
"wires": [ "wires": [
[ [
"67d04dc394a23636" "67d04dc394a23636"
], ],
[
"ddae3391e8b78cb8"
],
[ [
"0c70e666ebfcd6c1" "0c70e666ebfcd6c1"
] ]
], ],
"outputLabels": [
"Lights On",
"Cancel Timer",
"Start Timer"
],
"icon": "node-red/timer.svg" "icon": "node-red/timer.svg"
}, },
{ {
@ -11938,11 +11952,9 @@
"domain": "input_select", "domain": "input_select",
"service": "select_option", "service": "select_option",
"x": 700, "x": 700,
"y": 1120, "y": 1180,
"wires": [ "wires": [
[ []
"ddae3391e8b78cb8"
]
] ]
}, },
{ {
@ -11971,8 +11983,8 @@
"blockInputOverrides": false, "blockInputOverrides": false,
"domain": "timer", "domain": "timer",
"service": "cancel", "service": "cancel",
"x": 890, "x": 530,
"y": 1120, "y": 1240,
"wires": [ "wires": [
[] []
] ]
@ -12004,7 +12016,7 @@
"domain": "timer", "domain": "timer",
"service": "start", "service": "start",
"x": 530, "x": 530,
"y": 1180, "y": 1300,
"wires": [ "wires": [
[] []
] ]
@ -12036,7 +12048,7 @@
"domain": "light", "domain": "light",
"service": "turn_on", "service": "turn_on",
"x": 520, "x": 520,
"y": 1120, "y": 1180,
"wires": [ "wires": [
[ [
"a7cd304d11f25e60" "a7cd304d11f25e60"
@ -12072,7 +12084,7 @@
"output_location": "", "output_location": "",
"output_location_type": "none", "output_location_type": "none",
"x": 530, "x": 530,
"y": 1300, "y": 1420,
"wires": [ "wires": [
[] []
] ]
@ -12098,7 +12110,7 @@
} }
], ],
"x": 120, "x": 120,
"y": 1240, "y": 1360,
"wires": [ "wires": [
[ [
"5d9a85d3534d83e6" "5d9a85d3534d83e6"
@ -12137,7 +12149,7 @@
"entity_location": "data", "entity_location": "data",
"override_data": "msg", "override_data": "msg",
"x": 330, "x": 330,
"y": 1240, "y": 1360,
"wires": [ "wires": [
[ [
"fa7c83f1dece9741" "fa7c83f1dece9741"
@ -12174,7 +12186,7 @@
"domain": "input_select", "domain": "input_select",
"service": "select_option", "service": "select_option",
"x": 540, "x": 540,
"y": 1240, "y": 1360,
"wires": [ "wires": [
[] []
] ]
@ -13453,7 +13465,7 @@
"output_location": "", "output_location": "",
"output_location_type": "none", "output_location_type": "none",
"x": 1410, "x": 1410,
"y": 900, "y": 960,
"wires": [ "wires": [
[] []
] ]
@ -13464,8 +13476,8 @@
"z": "5e238cbbe6d612c9", "z": "5e238cbbe6d612c9",
"g": "ba738e13229c781b", "g": "ba738e13229c781b",
"name": "Delay", "name": "Delay",
"func": "const states = global.get('homeassistant.homeAssistant.states')\nconst lights = states['light.emma_bedroom_light'].state\nconst duration = states['input_number.emma_bedroom_lights_off_delay'].state\nconst lux = parseInt(states['sensor.emma_bedroom_illuminance'].state)\nconst threshold = parseInt(states['input_number.emma_bedroom_lux_threshold'].state)\nconst sleeping = states['input_boolean.emma_sleeping'].state\nconst payload = msg.payload\nconst newDuration = duration * 60\n\nif (sleeping === 'off') {\n if (payload === 'on') {\n if (lux <= threshold && lights === 'off') {\n node.status({fill:'green',shape:'dot',text:'Turning lights on'})\n node.send([msg,null])\n } else {\n if (lights === 'off') {\n node.status({fill:'red',shape:'ring',text:'Lights already on'})\n } else {\n node.status({fill:'red',shape:'ring',text:'Too bright'})\n }\n }\n } else if (payload === 'off') {\n if (lights === 'on') {\n msg.duration = newDuration\n node.status({fill:\"green\",shape:\"dot\",text:parseInt(duration) + ' minutes'})\n node.send([null,msg])\n } else {\n node.status({fill:\"red\",shape:\"ring\",text:\"Lights already off\"})\n }\n }\n} else {\n node.status({fill:'red',shape:'ring',text:'Blocked (Sleeping)'})\n}", "func": "const states = global.get('homeassistant.homeAssistant.states')\nconst lights = states['light.emma_bedroom_light'].state\nconst duration = states['input_number.emma_bedroom_lights_off_delay'].state\nconst lux = parseInt(states['sensor.emma_bedroom_illuminance'].state)\nconst threshold = parseInt(states['input_number.emma_bedroom_lux_threshold'].state)\nconst sleeping = states['input_boolean.emma_sleeping'].state\nconst payload = msg.payload\nconst newDuration = duration * 60\n\nif (sleeping === 'off') {\n if (payload === 'on') {\n if (lux <= threshold && lights === 'off') {\n node.status({fill:'green',shape:'dot',text:'Turning lights on'})\n node.send([msg,msg,null])\n } else {\n if (lights === 'on') {\n node.status({fill:'red',shape:'ring',text:'Lights already on'})\n node.send([null,msg,null])\n } else {\n node.status({fill:'red',shape:'ring',text:'Too bright'})\n }\n }\n } else if (payload === 'off') {\n if (lights === 'on') {\n msg.duration = newDuration\n node.status({fill:\"green\",shape:\"dot\",text:parseInt(duration) + ' minutes'})\n node.send([null,null,msg])\n } else {\n node.status({fill:\"red\",shape:\"ring\",text:\"Lights already off\"})\n }\n }\n} else {\n node.status({fill:'red',shape:'ring',text:'Blocked (Sleeping)'})\n}",
"outputs": 2, "outputs": 3,
"timeout": "", "timeout": "",
"noerr": 0, "noerr": 0,
"initialize": "", "initialize": "",
@ -13477,10 +13489,18 @@
[ [
"440fc7142e7345d4" "440fc7142e7345d4"
], ],
[
"b058c2262ac522ff"
],
[ [
"55c893b1d3009fed" "55c893b1d3009fed"
] ]
], ],
"outputLabels": [
"Lights On",
"Cancel Timer",
"Start Timer"
],
"icon": "node-red/timer.svg" "icon": "node-red/timer.svg"
}, },
{ {
@ -13510,7 +13530,7 @@
"domain": "timer", "domain": "timer",
"service": "start", "service": "start",
"x": 1410, "x": 1410,
"y": 840, "y": 900,
"wires": [ "wires": [
[] []
] ]
@ -13541,8 +13561,8 @@
"blockInputOverrides": false, "blockInputOverrides": false,
"domain": "timer", "domain": "timer",
"service": "cancel", "service": "cancel",
"x": 1590, "x": 1410,
"y": 780, "y": 840,
"wires": [ "wires": [
[] []
] ]
@ -13568,7 +13588,7 @@
} }
], ],
"x": 1000, "x": 1000,
"y": 900, "y": 960,
"wires": [ "wires": [
[ [
"cef61cdb2808ce5a" "cef61cdb2808ce5a"
@ -13660,9 +13680,7 @@
"x": 1400, "x": 1400,
"y": 780, "y": 780,
"wires": [ "wires": [
[ []
"b058c2262ac522ff"
]
] ]
}, },
{ {
@ -13697,7 +13715,7 @@
"entity_location": "data", "entity_location": "data",
"override_data": "msg", "override_data": "msg",
"x": 1210, "x": 1210,
"y": 900, "y": 960,
"wires": [ "wires": [
[ [
"c3f2a4aa281295ce" "c3f2a4aa281295ce"
@ -13996,7 +14014,7 @@
"output_location": "", "output_location": "",
"output_location_type": "none", "output_location_type": "none",
"x": 1410, "x": 1410,
"y": 1120, "y": 1240,
"wires": [ "wires": [
[] []
] ]
@ -14007,23 +14025,31 @@
"z": "5e238cbbe6d612c9", "z": "5e238cbbe6d612c9",
"g": "5c1df7492351b925", "g": "5c1df7492351b925",
"name": "Delay", "name": "Delay",
"func": "const states = global.get('homeassistant.homeAssistant.states')\nconst lights = states['light.kallen_bedroom_lights'].state\nconst duration = states['input_number.kallen_bedroom_lights_off_delay'].state\nconst lux = parseInt(states['sensor.kallen_bedroom_illuminance'].state)\nconst threshold = parseInt(states['input_number.kallen_bedroom_lux_threshold'].state)\nconst sleeping = states['input_boolean.kallen_sleeping'].state\nconst payload = msg.payload\nconst newDuration = duration * 60\n\nif (sleeping === 'off') {\n if (payload === 'on') {\n if (lux <= threshold && lights === 'off') {\n node.status({fill:'green',shape:'dot',text:'Turning lights on'})\n node.send([msg,null])\n } else {\n if (lights === 'off') {\n node.status({fill:'red',shape:'ring',text:'Lights already on'})\n } else {\n node.status({fill:'red',shape:'ring',text:'Too bright'})\n }\n }\n } else if (payload === 'off') {\n if (lights === 'on') {\n msg.duration = newDuration\n node.status({fill:\"green\",shape:\"dot\",text:parseInt(duration) + ' minutes'})\n node.send([null,msg])\n } else {\n node.status({fill:\"red\",shape:\"ring\",text:\"Lights already off\"})\n }\n }\n} else {\n node.status({fill:'red',shape:'ring',text:'Blocked (Sleeping)'})\n}", "func": "const states = global.get('homeassistant.homeAssistant.states')\nconst lights = states['light.kallen_bedroom_lights'].state\nconst duration = states['input_number.kallen_bedroom_lights_off_delay'].state\nconst lux = parseInt(states['sensor.kallen_bedroom_illuminance'].state)\nconst threshold = parseInt(states['input_number.kallen_bedroom_lux_threshold'].state)\nconst sleeping = states['input_boolean.kallen_sleeping'].state\nconst payload = msg.payload\nconst newDuration = duration * 60\n\nif (sleeping === 'off') {\n if (payload === 'on') {\n if (lux <= threshold && lights === 'off') {\n node.status({fill:'green',shape:'dot',text:'Turning lights on'})\n node.send([msg,msg,null])\n } else {\n if (lights === 'on') {\n node.status({fill:'red',shape:'ring',text:'Lights already on'})\n node.send([null,msg,null])\n } else {\n node.status({fill:'red',shape:'ring',text:'Too bright'})\n }\n }\n } else if (payload === 'off') {\n if (lights === 'on') {\n msg.duration = newDuration\n node.status({fill:\"green\",shape:\"dot\",text:parseInt(duration) + ' minutes'})\n node.send([null,null,msg])\n } else {\n node.status({fill:\"red\",shape:\"ring\",text:\"Lights already off\"})\n }\n }\n} else {\n node.status({fill:'red',shape:'ring',text:'Blocked (Sleeping)'})\n}",
"outputs": 2, "outputs": 3,
"timeout": "", "timeout": "",
"noerr": 0, "noerr": 0,
"initialize": "", "initialize": "",
"finalize": "", "finalize": "",
"libs": [], "libs": [],
"x": 1150, "x": 1150,
"y": 1060, "y": 1120,
"wires": [ "wires": [
[ [
"5524e8ba9b5545be" "5524e8ba9b5545be"
], ],
[
"bbe9fd4eff4e6a04"
],
[ [
"9a8f53db7d3ed3b7" "9a8f53db7d3ed3b7"
] ]
], ],
"outputLabels": [
"Lights On",
"Cancel Timer",
"Start Timer"
],
"icon": "node-red/timer.svg" "icon": "node-red/timer.svg"
}, },
{ {
@ -14053,7 +14079,7 @@
"domain": "timer", "domain": "timer",
"service": "start", "service": "start",
"x": 1410, "x": 1410,
"y": 1060, "y": 1180,
"wires": [ "wires": [
[] []
] ]
@ -14084,8 +14110,8 @@
"blockInputOverrides": false, "blockInputOverrides": false,
"domain": "timer", "domain": "timer",
"service": "cancel", "service": "cancel",
"x": 1590, "x": 1410,
"y": 1000, "y": 1120,
"wires": [ "wires": [
[] []
] ]
@ -14111,7 +14137,7 @@
} }
], ],
"x": 1000, "x": 1000,
"y": 1120, "y": 1240,
"wires": [ "wires": [
[ [
"0b5424aadc3479f7" "0b5424aadc3479f7"
@ -14164,7 +14190,7 @@
} }
], ],
"x": 990, "x": 990,
"y": 1060, "y": 1120,
"wires": [ "wires": [
[ [
"4954c509d4d697e2" "4954c509d4d697e2"
@ -14206,7 +14232,7 @@
"entity_location": "data", "entity_location": "data",
"override_data": "msg", "override_data": "msg",
"x": 1210, "x": 1210,
"y": 1120, "y": 1240,
"wires": [ "wires": [
[ [
"f3824e4c7e202605" "f3824e4c7e202605"
@ -14241,11 +14267,9 @@
"domain": "input_select", "domain": "input_select",
"service": "select_option", "service": "select_option",
"x": 1400, "x": 1400,
"y": 1000, "y": 1060,
"wires": [ "wires": [
[ []
"bbe9fd4eff4e6a04"
]
] ]
}, },
{ {
@ -14277,7 +14301,7 @@
"output_location": "", "output_location": "",
"output_location_type": "none", "output_location_type": "none",
"x": 1410, "x": 1410,
"y": 1340, "y": 1520,
"wires": [ "wires": [
[] []
] ]
@ -14288,23 +14312,31 @@
"z": "5e238cbbe6d612c9", "z": "5e238cbbe6d612c9",
"g": "505e378279011759", "g": "505e378279011759",
"name": "Delay", "name": "Delay",
"func": "const states = global.get('homeassistant.homeAssistant.states')\nconst lights = states['light.master_bedroom_lights'].state\nconst duration = states['input_number.master_bedroom_lights_off_delay'].state\nconst lux = parseInt(states['sensor.master_bedroom_illuminance'].state)\nconst threshold = parseInt(states['input_number.master_bedroom_lux_threshold'].state)\nconst masterBedroomSleep = states['input_boolean.master_bedroom_sleeping'].state\nconst kallenBedroomSleep = states['input_boolean.kallen_sleeping'].state\nconst peopleSleeping = (masterBedroomSleep === 'on' || kallenBedroomSleep === 'on')\nconst nightMode = states['input_boolean.night_mode'].state\nconst payload = msg.payload\nconst newDuration = duration * 60\n\nif (peopleSleeping === false && nightMode === 'off') {\n if (payload === 'on') {\n if (lux <= threshold && lights === 'off') {\n node.status({fill:'green',shape:'dot',text:'Turning lights on'})\n node.send([msg,null])\n } else {\n if (lights === 'off') {\n node.status({fill:'red',shape:'ring',text:'Lights already on'})\n } else {\n node.status({fill:'red',shape:'ring',text:'Too bright'})\n }\n }\n } else if (payload === 'off') {\n if (lights === 'on') {\n msg.duration = newDuration\n node.status({fill:\"green\",shape:\"dot\",text:parseInt(duration) + ' minutes'})\n node.send([null,msg])\n } else {\n node.status({fill:\"red\",shape:\"ring\",text:\"Lights already off\"})\n }\n }\n} else {\n node.status({fill:'red',shape:'ring',text:'Blocked (Sleeping)'})\n}", "func": "const states = global.get('homeassistant.homeAssistant.states')\nconst lights = states['light.master_bedroom_lights'].state\nconst duration = states['input_number.master_bedroom_lights_off_delay'].state\nconst lux = parseInt(states['sensor.master_bedroom_illuminance'].state)\nconst threshold = parseInt(states['input_number.master_bedroom_lux_threshold'].state)\nconst masterBedroomSleep = states['input_boolean.master_bedroom_sleeping'].state\nconst kallenBedroomSleep = states['input_boolean.kallen_sleeping'].state\nconst peopleSleeping = (masterBedroomSleep === 'on' || kallenBedroomSleep === 'on')\nconst nightMode = states['input_boolean.night_mode'].state\nconst payload = msg.payload\nconst newDuration = duration * 60\n\nif (peopleSleeping === false && nightMode === 'off') {\n if (payload === 'on') {\n if (lux <= threshold && lights === 'off') {\n node.status({fill:'green',shape:'dot',text:'Turning lights on'})\n node.send([msg,msg,null])\n } else {\n if (lights === 'on') {\n node.status({fill:'red',shape:'ring',text:'Lights already on'})\n node.send([null,msg,null])\n } else {\n node.status({fill:'red',shape:'ring',text:'Too bright'})\n }\n }\n } else if (payload === 'off') {\n if (lights === 'on') {\n msg.duration = newDuration\n node.status({fill:\"green\",shape:\"dot\",text:parseInt(duration) + ' minutes'})\n node.send([null,null,msg])\n } else {\n node.status({fill:\"red\",shape:\"ring\",text:\"Lights already off\"})\n }\n }\n} else {\n node.status({fill:'red',shape:'ring',text:'Blocked (Sleeping)'})\n}",
"outputs": 2, "outputs": 3,
"timeout": "", "timeout": "",
"noerr": 0, "noerr": 0,
"initialize": "", "initialize": "",
"finalize": "", "finalize": "",
"libs": [], "libs": [],
"x": 1150, "x": 1150,
"y": 1280, "y": 1400,
"wires": [ "wires": [
[ [
"81129efa6676b58e" "81129efa6676b58e"
], ],
[
"f14572686bbbbf9e"
],
[ [
"31686303c43971c7" "31686303c43971c7"
] ]
], ],
"outputLabels": [
"Lights On",
"Cancel Timer",
"Start Timer"
],
"icon": "node-red/timer.svg" "icon": "node-red/timer.svg"
}, },
{ {
@ -14334,7 +14366,7 @@
"domain": "timer", "domain": "timer",
"service": "start", "service": "start",
"x": 1410, "x": 1410,
"y": 1280, "y": 1460,
"wires": [ "wires": [
[] []
] ]
@ -14365,8 +14397,8 @@
"blockInputOverrides": false, "blockInputOverrides": false,
"domain": "timer", "domain": "timer",
"service": "cancel", "service": "cancel",
"x": 1590, "x": 1410,
"y": 1220, "y": 1400,
"wires": [ "wires": [
[] []
] ]
@ -14392,7 +14424,7 @@
} }
], ],
"x": 1000, "x": 1000,
"y": 1340, "y": 1520,
"wires": [ "wires": [
[ [
"4a431478798a51c8" "4a431478798a51c8"
@ -14445,7 +14477,7 @@
} }
], ],
"x": 990, "x": 990,
"y": 1280, "y": 1400,
"wires": [ "wires": [
[ [
"3063e6a5b5c3f677" "3063e6a5b5c3f677"
@ -14487,7 +14519,7 @@
"entity_location": "data", "entity_location": "data",
"override_data": "msg", "override_data": "msg",
"x": 1210, "x": 1210,
"y": 1340, "y": 1520,
"wires": [ "wires": [
[ [
"e270c73896a1a50c" "e270c73896a1a50c"
@ -14522,11 +14554,9 @@
"domain": "input_select", "domain": "input_select",
"service": "select_option", "service": "select_option",
"x": 1400, "x": 1400,
"y": 1220, "y": 1340,
"wires": [ "wires": [
[ []
"f14572686bbbbf9e"
]
] ]
}, },
{ {