36
first-floor-lighting/living-room/processing.js
Normal file
36
first-floor-lighting/living-room/processing.js
Normal file
@ -0,0 +1,36 @@
|
||||
const states = global.get('homeassistant.homeAssistant.states')
|
||||
const peoplePresent = states['binary_sensor.people_present'].state
|
||||
const vacationMode = states['input_boolean.vacation_mode'].state
|
||||
const nightMode = states['input_boolean.night_mode'].state
|
||||
const kallenSleeping = states['input_boolean.kallen_sleeping'].state
|
||||
const kallenOvernight = states['input_boolean.kallen_overnight'].state
|
||||
const duration = states['input_number.living_room_lights_off_delay'].state
|
||||
const newDuration = duration * 60
|
||||
const topic = msg.topic
|
||||
const payload = msg.payload
|
||||
|
||||
let block = {}
|
||||
|
||||
if ((peoplePresent === 'on' && vacationMode === 'off' && nightMode === 'on') && (kallenSleeping === 'on' || kallenOvernight === 'on')) {
|
||||
block = false
|
||||
} else {
|
||||
block = true
|
||||
}
|
||||
|
||||
if (topic === 'motion' && block === false) {
|
||||
if (payload === 'on') {
|
||||
node.status({fill:'green',shape:'dot',text:'Motion On'})
|
||||
node.send([msg,null,null])
|
||||
} else if (payload === 'off') {
|
||||
msg.duration = newDuration
|
||||
node.status({fill:'red',shape:'ring',text:'Motion Off'})
|
||||
node.send([null,msg,null])
|
||||
}
|
||||
} else if (topic === 'timer') {
|
||||
if (payload === 'finished') {
|
||||
node.status({fill:'green',shape:'dot',text:'Timer Finished'})
|
||||
node.send([null,null,msg])
|
||||
}
|
||||
} else if (block === true) {
|
||||
node.status({fill:'red',shape:'ring',text:'Blocked'})
|
||||
}
|
Reference in New Issue
Block a user