From 07a69b985fceddfe42e473e22f3c5bc10219eec2 Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Wed, 17 Jan 2024 17:16:07 -0500 Subject: [PATCH] Fix light-level-based sunset lighting triggers --- time-based/light-level-filter.js | 17 ++++++++++++----- time-based/processing.js | 14 +++++++++----- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/time-based/light-level-filter.js b/time-based/light-level-filter.js index e4a62d3..fa05b1e 100644 --- a/time-based/light-level-filter.js +++ b/time-based/light-level-filter.js @@ -1,11 +1,18 @@ const states = global.get('homeassistant.homeAssistant.states') -const luxThreshold = states['input_number.living_room_lux_threshold'].state +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 payload = msg.payload +const level = msg.level +const room = msg.room -if (timer === 'active' && payload <= luxThreshold) { - node.status({fill:'green',shape:'dot',text:'Sent'}) - node.send(msg) +if (timer === 'active') { + if (room === 'living-room' && level <= luxThresholdLivingRoom) { + node.status({fill:'green',shape:'dot',text:'Sent (Living Room)'}) + node.send(msg) + } else if (room === 'stairwell-bottom' && level <= luxThresholdStairwell) { + node.status({fill:'green',shape:'dot',text:'Sent (Stairwell Bottom)'}) + node.send(msg) + } } else { node.status({fill:'red',shape:'ring',text:'Blocked'}) } \ No newline at end of file diff --git a/time-based/processing.js b/time-based/processing.js index f80608d..fb5edd6 100644 --- a/time-based/processing.js +++ b/time-based/processing.js @@ -11,8 +11,10 @@ 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 lux = states['sensor.living_room_illuminance'].state -const luxThreshold = states['input_number.living_room_lux_threshold'].state +const luxLivingRoom = states['sensor.living_room_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") @@ -41,7 +43,7 @@ if (msg.topic === 'timer-finished' || msg.topic === 'manual-trigger' || msg.topi if (topic === 'timer-finished' || topic === 'manual-trigger' || topic === 'lux') { delay = 'off' -} else if (lux > luxThreshold) { +} else if (luxLivingRoom > luxThresholdLivingRoom && luxStairwell > luxThresholdStairwell) { delay = 'on' } else { delay = 'off' @@ -310,8 +312,10 @@ node.log("lightsOff: " + lightsOff) node.log("holidayMode: " + holidayMode) node.log("eventCall: " + eventCall) if (time === 'night') { - node.log("lux: " + lux) - node.log("luxThreshold: " + luxThreshold) + node.log("luxLivingRoom: " + luxLivingRoom) + node.log("luxThresholdLivingRoom: " + luxThresholdLivingRoom) + node.log("luxStairwell: " + luxStairwell) + node.log("luxThresholdStairwell: " + luxThresholdStairwell) node.log("delay: " + delay) node.log("sunsetStatus: " + sunsetStatus) }