Motion lighting for more rooms

This commit is contained in:
2024-02-08 22:14:42 -05:00
parent e58ee15b31
commit fc12a017dd
5 changed files with 87 additions and 2 deletions

View File

@ -0,0 +1,29 @@
const states = global.get('homeassistant.homeAssistant.states')
const lights = states['light.kallen_bedroom_lights'].state
const duration = states['input_number.kallen_bedroom_lights_off_delay'].state
const lux = parseInt(states['sensor.kallen_bedroom_illuminance'].state)
const threshold = parseInt(states['input_number.kallen_bedroom_lux_threshold'].state)
const sleeping = states['input_boolean.kallen_sleeping'].state
const payload = msg.payload
const newDuration = duration * 60
if (sleeping === 'off') {
if (payload === 'on') {
if (lux <= threshold || lights === 'on') {
node.status({fill:'green',shape:'dot',text:'Lights On'})
node.send([msg,null])
} else {
node.status({fill:'red',shape:'ring',text:'Too bright'})
}
} else if (payload === 'off') {
if (lights === 'on') {
msg.duration = newDuration
node.status({fill:"green",shape:"dot",text:parseInt(duration) + ' minutes'})
node.send([null,msg])
} else {
node.status({fill:"red",shape:"ring",text:"Lights already off"})
}
}
} else {
node.status({fill:'red',shape:'ring',text:'Blocked (Sleeping)'})
}