Fix issues with lux threshold conditions

This commit is contained in:
2024-01-16 12:11:28 -05:00
parent a882871842
commit d644e3d8e0
5 changed files with 16 additions and 12 deletions

View File

@ -1,8 +1,8 @@
const states = global.get('homeassistant.homeAssistant.states') const states = global.get('homeassistant.homeAssistant.states')
const lights = states['light.downstairs_bathroom_lights'].state const lights = states['light.downstairs_bathroom_lights'].state
const duration = states['input_number.downstairs_bathroom_lights_off_delay'].state const duration = states['input_number.downstairs_bathroom_lights_off_delay'].state
const lux = states['sensor.downstairs_bathroom_illuminance'].state const lux = parseInt(states['sensor.downstairs_bathroom_illuminance'].state)
const threshold = states['input_number.downstairs_bathroom_lux_threshold'].state const threshold = parseInt(states['input_number.downstairs_bathroom_lux_threshold'].state)
const payload = msg.payload const payload = msg.payload
const newDuration = duration * 60 const newDuration = duration * 60

View File

@ -23,7 +23,7 @@ if (topic === 'motion' && block === false) {
node.send([msg,null,null]) node.send([msg,null,null])
} else if (payload === 'off') { } else if (payload === 'off') {
msg.duration = newDuration msg.duration = newDuration
node.status({fill:'red',shape:'ring',text:'Motion Off'}) node.status({fill:'red',shape:'ring',text:parseInt(duration) + ' minutes'})
node.send([null,msg,null]) node.send([null,msg,null])
} }
} else if (topic === 'timer') { } else if (topic === 'timer') {

View File

@ -1,8 +1,8 @@
const states = global.get('homeassistant.homeAssistant.states') const states = global.get('homeassistant.homeAssistant.states')
const lights = states['light.emma_bedroom_light'].state const lights = states['light.emma_bedroom_light'].state
const duration = states['input_number.emma_bedroom_lights_off_delay'].state const duration = states['input_number.emma_bedroom_lights_off_delay'].state
const lux = states['sensor.emma_bedroom_illuminance'].state const lux = parseInt(states['sensor.emma_bedroom_illuminance'].state)
const threshold = states['input_number.emma_bedroom_lux_threshold'].state const threshold = parseInt(states['input_number.emma_bedroom_lux_threshold'].state)
const sleeping = states['input_boolean.emma_sleeping'].state const sleeping = states['input_boolean.emma_sleeping'].state
const payload = msg.payload const payload = msg.payload
const newDuration = duration * 60 const newDuration = duration * 60

View File

@ -1,20 +1,24 @@
const states = global.get('homeassistant.homeAssistant.states') const states = global.get('homeassistant.homeAssistant.states')
const lights = states['light.stairwell_led_strip'].state const stairwellLights = states['light.stairwell_led_strip'].state
const hallwayLights = states['light.hallway_overhead'].state
const earlyNightMode = states['binary_sensor.early_night_mode'].state
const nightMode = states['input_boolean.night_mode'].state
const goodnight = states['input_boolean.goodnight'].state
const duration = states['input_number.stairwell_lights_off_delay'].state const duration = states['input_number.stairwell_lights_off_delay'].state
const lux = states['sensor.stairwell_bottom_illuminance'].state const lux = parseInt(states['sensor.stairwell_bottom_illuminance'].state)
const threshold = states['input_number.stairwell_lux_threshold'].state const threshold = parseInt(states['input_number.stairwell_lux_threshold'].state)
const payload = msg.payload const payload = msg.payload
const newDuration = duration * 60 const newDuration = duration * 60
if (payload === 'on') { if (payload === 'on') {
if (lux <= threshold || lights === 'on') { if (lux <= threshold || stairwellLights === 'on') {
node.status({fill:'green',shape:'dot',text:'Lights On'}) node.status({fill:'green',shape:'dot',text:'Lights On'})
node.send([msg,null]) node.send([msg,null])
} else { } else {
node.status({fill:'red',shape:'ring',text:'Too bright'}) node.status({fill:'red',shape:'ring',text:'Too bright'})
} }
} else if (payload === 'off') { } else if (payload === 'off') {
if (lights === 'on') { if (stairwellLights === 'on') {
msg.duration = newDuration msg.duration = newDuration
node.status({fill:"green",shape:"dot",text:parseInt(duration) + ' minutes'}) node.status({fill:"green",shape:"dot",text:parseInt(duration) + ' minutes'})
node.send([null,msg]) node.send([null,msg])

View File

@ -1,8 +1,8 @@
const states = global.get('homeassistant.homeAssistant.states') const states = global.get('homeassistant.homeAssistant.states')
const lights = states['light.upstairs_bathroom_lights'].state const lights = states['light.upstairs_bathroom_lights'].state
const duration = states['input_number.upstairs_bathroom_motion_off_delay'].state const duration = states['input_number.upstairs_bathroom_motion_off_delay'].state
const lux = states['sensor.upstairs_bathroom_illuminance'].state const lux = parseInt(states['sensor.upstairs_bathroom_illuminance'].state)
const threshold = states['input_number.upstairs_bathroom_lux_threshold'].state const threshold = parseInt(states['input_number.upstairs_bathroom_lux_threshold'].state)
const showerMode = states['input_boolean.shower_mode'].state const showerMode = states['input_boolean.shower_mode'].state
const payload = msg.payload const payload = msg.payload
const newDuration = duration * 60 const newDuration = duration * 60