Files
HA-NerdFlows-Functions/second-floor-lighting/upstairs-bathroom/timer-finished.js

33 lines
1.1 KiB
JavaScript

const states = global.get('homeassistant.homeAssistant.states')
const showerMode = states['input_boolean.shower_mode'].state
const earlyNightMode = states['binary_sensor.early_night_mode'].state
const kallenOvernight = states['input_boolean.kallen_overnight'].state
const nightMode = states['input_boolean.night_mode'].state
const masterBedroomSleep = states['input_boolean.master_bedroom_sleeping'].state
let scene = {}
let late = {}
if (nightMode === 'on' || (earlyNightMode === 'on' && masterBedroomSleep === 'on')) {
late = true
scene = 'Single Nightlight'
} else {
late = false
scene = 'Nightlight'
}
if (showerMode === 'off') {
if (earlyNightMode === 'off') {
node.send([null,null,msg])
node.status({fill:'green',shape:'dot',text:'Lights Off'})
} else {
msg.option = scene
node.send([null,msg,null])
if (late === true && kallenOvernight === 'on') {
node.send([msg,null,null])
}
node.status({fill:'green',shape:'dot',text:'Scene set to ' + scene})
}
} else {
node.status({fill:'red',shape:'ring',text:'Blocked'})
}