Make sunset lighting depend on light level instead of weather

This commit is contained in:
2024-01-14 19:11:55 -05:00
parent d6d131c1ff
commit 417240c613
2 changed files with 26 additions and 15 deletions

View File

@ -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'})
}

View File

@ -8,10 +8,11 @@ const holidayHold = states['input_boolean.holiday_mode_hold'].state
const currentHoliday = states['input_select.holiday_animation'].state const currentHoliday = states['input_select.holiday_animation'].state
const holiday = currentHoliday.toLowerCase() const holiday = currentHoliday.toLowerCase()
const sunsetLights = states['input_boolean.sunset_lights_on'].state 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 vacation = states['input_boolean.vacation_mode'].state
const upBathOcc = states['binary_sensor.upstairs_bathroom_occupied'].state const upBathOcc = states['binary_sensor.upstairs_bathroom_occupied'].state
const deskLights = states['light.tina_desk_lights'].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 adaptiveSleep = flow.get("adaptiveSleep", "diskCon")
const selScenesMain = flow.get("selScenesMain", "diskCon") const selScenesMain = flow.get("selScenesMain", "diskCon")
const selScenesTinaDesk = flow.get("selScenesTinaDesk", "diskCon") const selScenesTinaDesk = flow.get("selScenesTinaDesk", "diskCon")
@ -26,7 +27,7 @@ let topic = {}
let delay = {} let delay = {}
let eventCall = {} let eventCall = {}
if (payload == 0 || payload === 'weather') { if (payload == 0) {
time = "night" time = "night"
eventCall = "on" eventCall = "on"
} else if (payload == 1) { } else if (payload == 1) {
@ -34,15 +35,13 @@ if (payload == 0 || payload === 'weather') {
eventCall = "off" 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 topic = msg.topic
} }
if (topic === 'timer-finished' || topic === 'manual-trigger') { if (topic === 'timer-finished' || topic === 'manual-trigger' || topic === 'lux') {
delay = 'off' delay = 'off'
} else if (topic === 'weather') { } else if (lux > luxThreshold) {
delay = 'off'
} else if (weather === 'sunny' || weather === 'clear-night') {
delay = 'on' delay = 'on'
} else { } else {
delay = 'off' delay = 'off'
@ -95,17 +94,17 @@ if (sunsetLights === 'off') {
sunsetStatus = "Skipped" sunsetStatus = "Skipped"
} else { } else {
notifyTitle = "Sunset Lights On" notifyTitle = "Sunset Lights On"
if (topic === 'weather') { if (topic === 'timer-finished') {
notifyMsg = "Lights on, delay cancelled due to weather change"
sunsetStatus = "Weather Change"
} else if (topic === 'timer-finished') {
notifyMsg = "Lights on because timer was finished manually" notifyMsg = "Lights on because timer was finished manually"
sunsetStatus = "Manual Trigger" sunsetStatus = "Manual Trigger"
} else if (topic === 'lux') {
notifyMsg = "Lights on because light level dropped below threshold"
sunsetStatus = "Light Level Trigger"
} else if (delay === 'on') { } else if (delay === 'on') {
notifyMsg = "Lights on after delay due to clear weather" notifyMsg = "Lights on after delay due to sufficient light"
sunsetStatus = "Delayed" sunsetStatus = "Delayed"
} else if (delay === 'off') { } else if (delay === 'off') {
notifyMsg = "Lights on early due to cloudy weather" notifyMsg = "Lights on early due to low light"
sunsetStatus = "Early" sunsetStatus = "Early"
} }
} }
@ -311,7 +310,8 @@ node.log("lightsOff: " + lightsOff)
node.log("holidayMode: " + holidayMode) node.log("holidayMode: " + holidayMode)
node.log("eventCall: " + eventCall) node.log("eventCall: " + eventCall)
if (time === 'night') { if (time === 'night') {
node.log("weather: " + weather) node.log("lux: " + lux)
node.log("luxThreshold: " + luxThreshold)
node.log("delay: " + delay) node.log("delay: " + delay)
node.log("sunsetStatus: " + sunsetStatus) node.log("sunsetStatus: " + sunsetStatus)
} }
@ -344,7 +344,7 @@ if (vacation === 'off') {
if (delay === 'on') { if (delay === 'on') {
node.send([null,sendTimer,null,null]) node.send([null,sendTimer,null,null])
} else { } else {
if (topic === 'weather') { if (topic === 'lux') {
node.send([null,sendTimerCancel,null,null]) node.send([null,sendTimerCancel,null,null])
} }
node.send([null,null,[sendFirstFloorScene,sendSecondFloorScene],sendExtraLights]) node.send([null,null,[sendFirstFloorScene,sendSecondFloorScene],sendExtraLights])