From 237ad152beb06ab529c78a6443a7835e45372291 Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Tue, 13 Feb 2024 15:59:39 -0500 Subject: [PATCH] Auto shower mode --- .../upstairs-bathroom/auto-shower-mode.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 second-floor-lighting/upstairs-bathroom/auto-shower-mode.js diff --git a/second-floor-lighting/upstairs-bathroom/auto-shower-mode.js b/second-floor-lighting/upstairs-bathroom/auto-shower-mode.js new file mode 100644 index 0000000..afd35b9 --- /dev/null +++ b/second-floor-lighting/upstairs-bathroom/auto-shower-mode.js @@ -0,0 +1,25 @@ +const states = global.get('homeassistant.homeAssistant.states') +const showerMode = states['input_boolean.shower_mode'].state +const tempChange = parseFloat(msg.payload) + +let action = {} + +if (tempChange < 0) { + action = 'off' +} else if (tempChange >= 5.0) { + action = 'on' +} else { + action = 'none' +} + +let actionMsg = { + 'action': 'turn_' + action +} + +if ((action === 'on' && showerMode === 'off') || (action === 'off' && showerMode === 'on')) { + node.status({fill:'green',shape:'dot',text:'Shower Mode ' + action}) + node.send(actionMsg) +} else { + node.status({fill:'red',shape:'ring',text:'No action taken'}) + return null +} \ No newline at end of file