Add motion-detected and shower mode functions for upstairs bathroom
This commit is contained in:
67
second-floor-lighting/upstairs-bathroom/shower-mode.js
Normal file
67
second-floor-lighting/upstairs-bathroom/shower-mode.js
Normal file
@ -0,0 +1,67 @@
|
||||
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 {
|
||||
if (kallenOvernight === 'off') {
|
||||
if (nightMode === 'on') {
|
||||
scene = 'Single Nightlight'
|
||||
} else {
|
||||
scene = 'Nightlight'
|
||||
}
|
||||
} else {
|
||||
scene = 'Adaptive'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 -----")
|
Reference in New Issue
Block a user