From da15236ace9dbf72be80315ac4ab846e20c4e1ee Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Wed, 24 Jan 2024 13:33:19 -0500 Subject: [PATCH] Add timer-finished function for stairwell --- .../stairwell/timer-finished.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 second-floor-lighting/stairwell/timer-finished.js diff --git a/second-floor-lighting/stairwell/timer-finished.js b/second-floor-lighting/stairwell/timer-finished.js new file mode 100644 index 0000000..b22f5f2 --- /dev/null +++ b/second-floor-lighting/stairwell/timer-finished.js @@ -0,0 +1,32 @@ +const states = global.get('homeassistant.homeAssistant.states') +const earlyNightMode = states['binary_sensor.early_night_mode'].state +const nightMode = states['input_boolean.night_mode'].state +const goodnight = states['input_boolean.goodnight'].state +const masterBedroomSleep = states['input_boolean.master_bedroom_sleeping'].state + +let hallwayScene = {} +let hallwayAction = {} + +if (goodnight === 'on') { + hallwayAction = 'off' +} else if (masterBedroomSleep === 'off' && (earlyNightMode === 'on' || nightMode === 'on')) { + hallwayAction = 'on' + hallwayScene = 'Nightlight' +} else { + hallwayAction = 'off' +} + +msg.hallway = hallwayAction + +// Turn off Stairwell LED Strip +node.send([msg,null]) + +// Hallway actions +if (hallwayAction === 'on') { + msg.scene = hallwayScene + node.status({fill:'green',shape:'dot',text:'Hallway ' + hallwayScene}) + node.send([null,null,msg]) +} else if (hallwayAction === 'off') { + node.status({fill:'green',shape:'dot',text:'Hallway Off'}) + node.send([null,msg,null]) +} \ No newline at end of file