From 9f415eb232ffb39f078942ade667493b2be9863e Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Tue, 27 May 2025 21:24:51 -0400 Subject: [PATCH 1/4] Rework light level filter node home_automation/HA-NerdFlows#32 --- time-based/light-level-filter.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/time-based/light-level-filter.js b/time-based/light-level-filter.js index fa05b1e..78823c4 100644 --- a/time-based/light-level-filter.js +++ b/time-based/light-level-filter.js @@ -1,18 +1,27 @@ const states = global.get('homeassistant.homeAssistant.states') const luxThresholdLivingRoom = states['input_number.living_room_lux_threshold'].state const luxThresholdStairwell = states['input_number.stairwell_lux_threshold'].state -const timer = states['timer.sunset_lighting_timer'].state +const luxThresholdOutdoor = states['input_number.sunset_lights_outdoor_lux_threshold'].state +const evening = states['binary_sensor.evening'].state +const triggered = states['input_boolean.sunset_lights_triggered'].state const level = msg.level const room = msg.room -if (timer === 'active') { +if (evening === 'on' && triggered === 'off') { if (room === 'living-room' && level <= luxThresholdLivingRoom) { node.status({fill:'green',shape:'dot',text:'Sent (Living Room)'}) - node.send(msg) + node.send([msg,msg]) } else if (room === 'stairwell-bottom' && level <= luxThresholdStairwell) { node.status({fill:'green',shape:'dot',text:'Sent (Stairwell Bottom)'}) - node.send(msg) + node.send([msg,msg]) + } else if (room === 'outdoor' && level <= luxThresholdOutdoor) { + node.status({fill:'green',shape:'dot',text:'Sent (Outdoor)'}) + node.send([msg,msg]) } +} else if (evening === 'off') { + node.status({fill:'red',shape:'ring',text:'Not Evening'}) +} else if (triggered === 'on') { + node.status({fill:'red',shape:'ring',text:'Already Triggered'}) } else { - node.status({fill:'red',shape:'ring',text:'Blocked'}) + node.status({fill:'red',shape:'ring',text:'No Action'}) } \ No newline at end of file From c99f12528949356b261579f549b7ddacf1baf2f7 Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Tue, 27 May 2025 21:25:37 -0400 Subject: [PATCH 2/4] Add sunset lights triggered boolean to the booleanOff variable home_automation/HA-NerdFlows#32 --- time-based/processing-start.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/time-based/processing-start.js b/time-based/processing-start.js index a7b6898..0e670fa 100644 --- a/time-based/processing-start.js +++ b/time-based/processing-start.js @@ -64,7 +64,8 @@ const booleanOff = [ "input_boolean.give_me_darkness", "input_boolean.goodnight", "input_boolean.kallen_computer_updates", - "input_boolean.night_mode" + "input_boolean.night_mode", + "input_boolean.sunset_lights_triggered" ] //! ---------- NIGHT MODE ---------- From 054b498f515b16adaf0adcb3f0908641791595ec Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Tue, 27 May 2025 21:25:56 -0400 Subject: [PATCH 3/4] Rework main processing node for sunset lighting flow home_automation/HA-NerdFlows#32 --- time-based/processing.js | 93 +++++++++++----------------------------- 1 file changed, 24 insertions(+), 69 deletions(-) diff --git a/time-based/processing.js b/time-based/processing.js index 698c616..288acb0 100644 --- a/time-based/processing.js +++ b/time-based/processing.js @@ -11,22 +11,18 @@ const sunsetLights = states['input_boolean.sunset_lights_on'].state const vacation = states['input_boolean.vacation_mode'].state const upBathOcc = states['binary_sensor.upstairs_bathroom_occupied'].state const deskLights = states['light.tina_desk_lights'].state -const luxLivingRoom = states['sensor.living_room_front_illuminance'].state -const luxThresholdLivingRoom = states['input_number.living_room_lux_threshold'].state -const luxStairwell = states['sensor.stairwell_bottom_illuminance'].state -const luxThresholdStairwell = states['input_number.stairwell_lux_threshold'].state const adaptiveSleep = flow.get("adaptiveSleep", "diskCon") const selScenesMain = flow.get("selScenesMain", "diskCon") const selScenesTinaDesk = flow.get("selScenesTinaDesk", "diskCon") const booleanOff = flow.get("booleanOff", "diskCon") +const triggered = states['input_boolean.sunset_lights_triggered'].state const payload = msg.payload +const topic = msg.topic node.log("Time-based Automations: Constants Set") // Set a few important variables let time = {} -let topic = {} -let delay = {} let eventCall = {} if (payload == 0) { @@ -37,17 +33,6 @@ if (payload == 0) { eventCall = "off" } -if (msg.topic === 'timer-finished' || msg.topic === 'manual-trigger' || msg.topic === 'lux') { - topic = msg.topic -} - -if (topic === 'timer-finished' || topic === 'manual-trigger' || topic === 'lux') { - delay = 'off' -} else if (luxLivingRoom > luxThresholdLivingRoom && luxStairwell > luxThresholdStairwell) { - delay = 'on' -} else { - delay = 'off' -} node.log("Time-based Automations: Main variables defined") // ---------- Configuration ---------- @@ -96,19 +81,8 @@ if (sunsetLights === 'off') { sunsetStatus = "Skipped" } else { notifyTitle = "Sunset Lights On" - if (topic === 'timer-finished') { - notifyMsg = "Lights on because timer was finished manually" - sunsetStatus = "Manual Trigger" - } else if (topic === 'lux') { - notifyMsg = "Lights on because light level dropped below threshold" - sunsetStatus = "Light Level Trigger" - } else if (delay === 'on') { - notifyMsg = "Lights on after delay due to sufficient light" - sunsetStatus = "Delayed" - } else if (delay === 'off') { - notifyMsg = "Lights on early due to low light" - sunsetStatus = "Early" - } + notifyMsg = "It's getting dark, evening lighting is now active" + sunsetStatus = "Light Level Trigger" } // Holiday Settings @@ -125,6 +99,17 @@ if (holidayMode === 'on') { node.log("Time-based Automations: Decision Logic Complete") // ---------- Service Calls ---------- + +let sendTriggered = { + "payload": { + "action": "input_boolean.turn_on", + "target": { + "entity_id": ["input_boolean.sunset_lights_triggered"] + }, + "data": {} + } +} + let sendLights = { "payload": { "action": "light.turn_off", @@ -199,28 +184,6 @@ let sendHoliday = { } } -let sendTimer = { - "payload": { - "action": "timer.start", - "target": { - "entity_id": timerEntity - }, - "data": { - "duration": timerDuration - } - } -} - -let sendTimerCancel = { - "payload": { - "action": "timer.cancel", - "target": { - "entity_id": timerEntity - }, - "data": {} - } -} - let sendNotifyPhone = { "payload": { "action": "script.text_notify", @@ -298,11 +261,6 @@ node.log("lightsOff: " + lightsOff) node.log("holidayMode: " + holidayMode) node.log("eventCall: " + eventCall) if (time === 'night') { - node.log("luxLivingRoom: " + luxLivingRoom) - node.log("luxThresholdLivingRoom: " + luxThresholdLivingRoom) - node.log("luxStairwell: " + luxStairwell) - node.log("luxThresholdStairwell: " + luxThresholdStairwell) - node.log("delay: " + delay) node.log("sunsetStatus: " + sunsetStatus) } if (holidayMode === 'on') { @@ -324,18 +282,13 @@ if (vacation === 'off') { } }, 5000) } else if (time === "night") { - node.status({fill:"green",shape:"dot",text:"Sunset Flow"}) - node.send([null,sendAdaptive,null,null]) - if (holidayMode === 'on') { - setTimeout(() => { - node.send([null,sendHoliday,null,null]) - }, 1000) - } - if (delay === 'on') { - node.send([null,sendTimer,null,null]) - } else { - if (topic === 'lux') { - node.send([null,sendTimerCancel,null,null]) + if (triggered === 'off') { + node.status({fill:"green",shape:"dot",text:"Sunset Flow"}) + node.send([null,[sendAdaptive,sendTriggered],null,null]) + if (holidayMode === 'on') { + setTimeout(() => { + node.send([null,sendHoliday,null,null]) + }, 1000) } node.send([null,null,[sendFirstFloorScene,sendSecondFloorScene],sendExtraLights]) if (deskLights === 'on') { @@ -344,6 +297,8 @@ if (vacation === 'off') { if (topic != 'manual-trigger') { node.send([[sendNotifyPhone,sendNotifyTV],null,null,null]) } + } else { + node.status({fill:'green',shape:'dot',text:'Sunset Flow (Already Triggered)'}) } } } From ba7af1addf17c772c57a4dd6169609a130e8241c Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Thu, 29 May 2025 17:30:44 -0400 Subject: [PATCH 4/4] Use early night mode instead of evening, lights were triggering early home_automation/HA-NerdFlows#32 --- time-based/light-level-filter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/time-based/light-level-filter.js b/time-based/light-level-filter.js index 78823c4..fe903ea 100644 --- a/time-based/light-level-filter.js +++ b/time-based/light-level-filter.js @@ -2,12 +2,12 @@ const states = global.get('homeassistant.homeAssistant.states') const luxThresholdLivingRoom = states['input_number.living_room_lux_threshold'].state const luxThresholdStairwell = states['input_number.stairwell_lux_threshold'].state const luxThresholdOutdoor = states['input_number.sunset_lights_outdoor_lux_threshold'].state -const evening = states['binary_sensor.evening'].state +const earlyNight = states['binary_sensor.early_night_mode'].state const triggered = states['input_boolean.sunset_lights_triggered'].state const level = msg.level const room = msg.room -if (evening === 'on' && triggered === 'off') { +if (earlyNight === 'on' && triggered === 'off') { if (room === 'living-room' && level <= luxThresholdLivingRoom) { node.status({fill:'green',shape:'dot',text:'Sent (Living Room)'}) node.send([msg,msg]) @@ -18,7 +18,7 @@ if (evening === 'on' && triggered === 'off') { node.status({fill:'green',shape:'dot',text:'Sent (Outdoor)'}) node.send([msg,msg]) } -} else if (evening === 'off') { +} else if (earlyNight === 'off') { node.status({fill:'red',shape:'ring',text:'Not Evening'}) } else if (triggered === 'on') { node.status({fill:'red',shape:'ring',text:'Already Triggered'})