Downstairs bathroom and stairwell motion lighting functions

This commit is contained in:
2024-11-30 19:26:35 -05:00
parent 672c0c258a
commit 844680454d
2 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,24 @@
const states = global.get('homeassistant.homeAssistant.states')
const lights = states['light.downstairs_bathroom_lights'].state
const duration = states['input_number.downstairs_bathroom_lights_off_delay'].state
const lux = states['sensor.downstairs_bathroom_illuminance'].state
const threshold = states['input_number.downstairs_bathroom_lux_threshold'].state
const payload = msg.payload
const newDuration = duration * 60
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"})
}
}

View File

@ -0,0 +1,24 @@
const states = global.get('homeassistant.homeAssistant.states')
const lights = states['light.stairwell_led_strip'].state
const duration = states['input_number.stairwell_lights_off_delay'].state
const lux = states['sensor.stairwell_bottom_illuminance'].state
const threshold = states['input_number.stairwell_lux_threshold'].state
const payload = msg.payload
const newDuration = duration * 60
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"})
}
}