diff --git a/motion-lights/downstairs-bathroom.js b/motion-lights/downstairs-bathroom.js new file mode 100644 index 0000000..6aa09c4 --- /dev/null +++ b/motion-lights/downstairs-bathroom.js @@ -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"}) + } +} \ No newline at end of file diff --git a/motion-lights/stairwell.js b/motion-lights/stairwell.js new file mode 100644 index 0000000..b8570d3 --- /dev/null +++ b/motion-lights/stairwell.js @@ -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"}) + } +} \ No newline at end of file