Rename floor-based folders
This commit is contained in:
37
second-floor/master-bedroom/master-bedroom.js
Normal file
37
second-floor/master-bedroom/master-bedroom.js
Normal file
@ -0,0 +1,37 @@
|
||||
const states = global.get('homeassistant.homeAssistant.states')
|
||||
const lights = states['light.master_bedroom_lights'].state
|
||||
const duration = states['input_number.master_bedroom_lights_off_delay'].state
|
||||
const lux = parseInt(states['sensor.master_bedroom_illuminance'].state)
|
||||
const threshold = parseInt(states['input_number.master_bedroom_lux_threshold'].state)
|
||||
const masterBedroomSleep = states['input_boolean.master_bedroom_sleeping'].state
|
||||
const kallenBedroomSleep = states['input_boolean.kallen_sleeping'].state
|
||||
const peopleSleeping = (masterBedroomSleep === 'on' || kallenBedroomSleep === 'on')
|
||||
const nightMode = states['input_boolean.night_mode'].state
|
||||
const payload = msg.payload
|
||||
const newDuration = duration * 60
|
||||
|
||||
if (peopleSleeping === false && nightMode === 'off') {
|
||||
if (payload === 'on') {
|
||||
if (lux <= threshold && lights === 'off') {
|
||||
node.status({fill:'green',shape:'dot',text:'Turning lights on'})
|
||||
node.send([msg,msg,null])
|
||||
} else {
|
||||
if (lights === 'on') {
|
||||
node.status({fill:'red',shape:'ring',text:'Lights already on'})
|
||||
node.send([null,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,null,msg])
|
||||
} else {
|
||||
node.status({fill:"red",shape:"ring",text:"Lights already off"})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
node.status({fill:'red',shape:'ring',text:'Blocked (Sleeping)'})
|
||||
}
|
Reference in New Issue
Block a user