From 417240c6130cbda0b5eaafbccfd37d8823912ab0 Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Sun, 14 Jan 2024 19:11:55 -0500 Subject: [PATCH] Make sunset lighting depend on light level instead of weather --- time-based/light-level-filter.js | 11 +++++++++++ time-based/processing.js | 30 +++++++++++++++--------------- 2 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 time-based/light-level-filter.js diff --git a/time-based/light-level-filter.js b/time-based/light-level-filter.js new file mode 100644 index 0000000..e4a62d3 --- /dev/null +++ b/time-based/light-level-filter.js @@ -0,0 +1,11 @@ +const states = global.get('homeassistant.homeAssistant.states') +const luxThreshold = states['input_number.living_room_lux_threshold'].state +const timer = states['timer.sunset_lighting_timer'].state +const payload = msg.payload + +if (timer === 'active' && payload <= luxThreshold) { + node.status({fill:'green',shape:'dot',text:'Sent'}) + 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 20d0dd5..f80608d 100644 --- a/time-based/processing.js +++ b/time-based/processing.js @@ -8,10 +8,11 @@ const holidayHold = states['input_boolean.holiday_mode_hold'].state const currentHoliday = states['input_select.holiday_animation'].state const holiday = currentHoliday.toLowerCase() const sunsetLights = states['input_boolean.sunset_lights_on'].state -const weather = states['weather.iron_nerd_weather_station'].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 adaptiveSleep = flow.get("adaptiveSleep", "diskCon") const selScenesMain = flow.get("selScenesMain", "diskCon") const selScenesTinaDesk = flow.get("selScenesTinaDesk", "diskCon") @@ -26,7 +27,7 @@ let topic = {} let delay = {} let eventCall = {} -if (payload == 0 || payload === 'weather') { +if (payload == 0) { time = "night" eventCall = "on" } else if (payload == 1) { @@ -34,15 +35,13 @@ if (payload == 0 || payload === 'weather') { eventCall = "off" } -if (msg.topic === 'timer-finished' || msg.topic === 'manual-trigger' || msg.topic === 'weather') { +if (msg.topic === 'timer-finished' || msg.topic === 'manual-trigger' || msg.topic === 'lux') { topic = msg.topic } -if (topic === 'timer-finished' || topic === 'manual-trigger') { +if (topic === 'timer-finished' || topic === 'manual-trigger' || topic === 'lux') { delay = 'off' -} else if (topic === 'weather') { - delay = 'off' -} else if (weather === 'sunny' || weather === 'clear-night') { +} else if (lux > luxThreshold) { delay = 'on' } else { delay = 'off' @@ -95,17 +94,17 @@ if (sunsetLights === 'off') { sunsetStatus = "Skipped" } else { notifyTitle = "Sunset Lights On" - if (topic === 'weather') { - notifyMsg = "Lights on, delay cancelled due to weather change" - sunsetStatus = "Weather Change" - } else if (topic === 'timer-finished') { + 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 clear weather" + notifyMsg = "Lights on after delay due to sufficient light" sunsetStatus = "Delayed" } else if (delay === 'off') { - notifyMsg = "Lights on early due to cloudy weather" + notifyMsg = "Lights on early due to low light" sunsetStatus = "Early" } } @@ -311,7 +310,8 @@ node.log("lightsOff: " + lightsOff) node.log("holidayMode: " + holidayMode) node.log("eventCall: " + eventCall) if (time === 'night') { - node.log("weather: " + weather) + node.log("lux: " + lux) + node.log("luxThreshold: " + luxThreshold) node.log("delay: " + delay) node.log("sunsetStatus: " + sunsetStatus) } @@ -344,7 +344,7 @@ if (vacation === 'off') { if (delay === 'on') { node.send([null,sendTimer,null,null]) } else { - if (topic === 'weather') { + if (topic === 'lux') { node.send([null,sendTimerCancel,null,null]) } node.send([null,null,[sendFirstFloorScene,sendSecondFloorScene],sendExtraLights])