59 lines
2.0 KiB
JavaScript
59 lines
2.0 KiB
JavaScript
const states = global.get('homeassistant.homeAssistant.states')
|
|
const occupied = states['binary_sensor.upstairs_bathroom_occupied'].state
|
|
const earlyNightMode = states['binary_sensor.early_night_mode'].state
|
|
const nightMode = states['input_boolean.night_mode'].state
|
|
const kallenOvernight = states['input_boolean.kallen_overnight'].state
|
|
const motion = states['binary_sensor.upstairs_bathroom_motion'].state
|
|
const payload = msg.payload
|
|
|
|
let timerCancel = {
|
|
"payload": "stop"
|
|
}
|
|
|
|
let scene = {}
|
|
if (payload === 'on') {
|
|
scene = 'Bright'
|
|
} else {
|
|
if (motion === 'on') {
|
|
scene = 'Adaptive'
|
|
} else {
|
|
scene = 'Single Nightlight'
|
|
}
|
|
}
|
|
|
|
if (payload === 'on') {
|
|
msg.scene = scene
|
|
node.status({fill:'green',shape:'dot',text:'Shower Mode On'})
|
|
node.send([timerCancel,msg,null])
|
|
} else if (payload === 'off') {
|
|
node.send([timerCancel,null,null])
|
|
if (motion === 'on') {
|
|
msg.scene = scene
|
|
node.status({fill:'green',shape:'dot',text:'Lights Adaptive'})
|
|
node.send([null,msg,null])
|
|
} else if (earlyNightMode === 'on') {
|
|
if (kallenOvernight === 'on') {
|
|
node.status({fill:'green',shape:'dot',text:'Lights Off'})
|
|
node.send([null,null,msg])
|
|
} else {
|
|
msg.scene = scene
|
|
node.status({fill:'green',shape:'dot',text:'Scene Set'})
|
|
node.send([null,msg,null])
|
|
}
|
|
} else {
|
|
node.status({fill:'green',shape:'dot',text:'Lights Off'})
|
|
node.send([null,null,msg])
|
|
}
|
|
}
|
|
|
|
node.log("----- Upstairs Bathroom Shower Mode Parameters Start -----")
|
|
node.log("Upstairs Bathroom payload: " + payload)
|
|
node.log("Upstairs Bathroom scene: " + scene)
|
|
if (payload === 'off') {
|
|
node.log("Upstairs Bathroom occupied: " + occupied)
|
|
node.log("Upstairs Bathroom earlyNightMode: " + earlyNightMode)
|
|
node.log("Upstairs Bathroom nightMode: " + nightMode)
|
|
node.log("Upstairs Bathroom kallenOvernight: " + kallenOvernight)
|
|
node.log("Upstairs Bathroom motion: " + motion)
|
|
}
|
|
node.log("----- Upstairs Bathroom Shower Mode Parameters End -----") |