Fix light-level-based sunset lighting triggers

This commit is contained in:
2024-01-17 17:16:07 -05:00
parent d644e3d8e0
commit 07a69b985f
2 changed files with 21 additions and 10 deletions

View File

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

View File

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