Add motion-detected and shower mode functions for upstairs bathroom

This commit is contained in:
2024-01-13 19:56:21 -05:00
parent c3f8a65d5d
commit b99b13df51
2 changed files with 109 additions and 0 deletions

View File

@ -0,0 +1,42 @@
const states = global.get('homeassistant.homeAssistant.states')
const lights = states['light.upstairs_bathroom_lights'].state
const duration = states['input_number.upstairs_bathroom_motion_off_delay'].state
const lux = states['sensor.upstairs_bathroom_illuminance'].state
const threshold = states['input_number.upstairs_bathroom_lux_threshold'].state
const showerMode = states['input_boolean.shower_mode'].state
const payload = msg.payload
const newDuration = duration * 60
let timerCancel = {
"payload": "stop"
}
if (showerMode === 'off') {
if (payload === 'on') {
node.send([null,null,timerCancel])
if (lux <= threshold || lights === 'on') {
node.status({fill:'green',shape:'dot',text:'Lights On'})
node.send([msg,null,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,msg,null])
} else {
node.status({fill:"red",shape:"ring",text:"Lights already off"})
}
}
}
node.log("----- Upstairs Bathroom Motion Parameters Start -----")
node.log("Upstairs Bathroom payload: " + payload)
node.log("Upstairs Bathroom lights: " + lights)
node.log("Upstairs Bathroom duration: " + duration)
node.log("Upstairs Bathroom newDuration: " + newDuration)
node.log("Upstairs Bathroom lux: " + lux)
node.log("Upstairs Bathroom threshold: " + threshold)
node.log("Upstairs Bathroom showerMode: " + showerMode)
node.log("----- Upstairs Bathroom Motion Parameters End -----")

View 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 -----")