diff --git a/climate/master-bedroom/processing.js b/climate/master-bedroom/processing.js index 44585b5..7faa32f 100644 --- a/climate/master-bedroom/processing.js +++ b/climate/master-bedroom/processing.js @@ -23,6 +23,7 @@ const danger = states['binary_sensor.heat_warning'].attributes.danger const meltdown = states['input_boolean.meltdown_protocol'].state const coolingActive = states['input_boolean.master_bedroom_cooling_on'].state const echoDotDND = 'switch.basement_echo_dot_do_not_disturb_switch' +const currentMode = states['input_select.current_climate_mode_master_bedroom'].state node.log("Master Bedroom Climate: Constants Set") // Define some entity IDs @@ -47,14 +48,13 @@ let setAcFan = 'auto' let setEco = 'auto' let setHvac = 'cool' let setFan = [] -let setCool = [] +let setMode = [] +let validNight = ['Night Mode','Bedtime Mode'] let setSleep = [] let setPeople = [] let setDisplay = 'turn_on' let time = [] let echoDotService = [] -let setBriefing = [] -let setBriefingDelay = [] let type = msg.type let topic = msg.topic let isWakeup = context.get("isWakeup") @@ -65,15 +65,18 @@ if (type === 'sleep' && payload === 'off') { setDisplay = 'turn_on' echoDotService = 'turn_off' setPeople = 'turn_on' - if (coolingActive === 'on') { + if (validNight.includes(currentMode)) { time = 'night' + setMode = 'Night Mode' } else { time = 'day' + setMode = 'Day Mode' } } else if (type === 'sleep' && payload === 'on') { setDisplay = 'turn_off' echoDotService = 'turn_on' time = 'bedtime' + setMode = 'Bedtime Mode' } else { time = msg.time } @@ -82,20 +85,9 @@ if (topic === 'mrbedroom-wakeup') { setSleep = 'turn_off' } -// Setup TTS briefing -if (topic === 'mrbedroom-wakeup') { - setBriefing = "master_bedroom_wakeup_briefing" - setBriefingDelay = 60000 -} else if (type === 'sleep' && payload === 'off') { - setBriefing = "master_bedroom_wakeup_briefing" - setBriefingDelay = 15000 -} - // Day Time if (time === 'day') { - if (type === 'auto') { - setCool = 'turn_off' - } + setMode = 'Day Mode' if (earlyNight === 'off') { setFan = "turn_off" if (ac === 'on') { @@ -141,10 +133,7 @@ if (time === 'day') { } // Night Time } else if (time === 'night') { - // If this is being run at scheduled time, turn on input_boolean.master_bedroom_cooling_on - if (type === 'auto') { - setCool = 'turn_on' - } + setMode = 'Night Mode' // Decide temperature if (type === 'sleep' && payload === 'off') { setTemp = dayTemp @@ -175,6 +164,7 @@ if (time === 'day') { } // Bed Time } else if (time === 'bedtime') { + setMode = 'Bedtime Mode' setPeople = 'turn_off' if (ac === 'on') { setTemp = bedTemp @@ -209,13 +199,15 @@ let sendFan = { } } -let sendCool = { +let sendMode = { "payload": { - "action": `input_boolean.${setCool}`, + "action": "input_select.select_option", "target": { - "entity_id": ["input_boolean.master_bedroom_cooling_on"] + "entity_id": ["input_select.current_climate_mode_master_bedroom"] }, - "data": {} + "data": { + "option": setMode + } } } @@ -256,13 +248,6 @@ let notify = { "fanmode": fanMode } -let sendBriefing = { - "payload": { - "action": `script.${setBriefing}`, - }, - "delay": setBriefingDelay -} - let sendHvac = { "payload": { "action": "climate.set_hvac_mode", @@ -329,12 +314,10 @@ node.log(`setAcFan: ${setAcFan}`) node.log(`setEco: ${setEco}`) node.log(`setHvac: ${setHvac}`) node.log(`setFan: ${setFan}`) -node.log(`setCool: ${setCool}`) +node.log(`setMode: ${setMode}`) node.log(`setSleep: ${setSleep}`) node.log(`setPeople: ${setPeople}`) node.log(`setDisplay: ${setDisplay}`) -node.log(`setBriefing: ${setBriefing}`) -node.log(`setBriefingDelay: ${setBriefingDelay}`) node.log(`time: ${time}`) node.log(`type: ${type}`) node.log(`topic: ${topic}`) @@ -342,9 +325,9 @@ node.log("----- Master Bedroom Climate: End Parameters -----") // If this was an automated trigger, set the cooling context for the bedroom accordingly. -if (type === 'auto' && time != 'bedtime') { - node.send([null, null, sendCool, null, null]) - node.log("Master Bedroom Climate: Cooling Context Set") +if (type === 'auto') { + node.send([null, null, sendMode, null]) + node.log("Master Bedroom Climate: Cooling Mode Context Set") } // Automated responses @@ -359,36 +342,35 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null]) node.log("Master Bedroom Climate: Auto/Cooling") } else if (topic === 'mrbedroom-bedtime') { - node.send([null, null, sendPeople, null, null]) + node.send([null, null, sendPeople, null]) node.status({ fill: "green", shape: "dot", text: "Bedtime" }) node.log("Master Bedroom Climate: Auto/Bedtime") if (ac === 'on') { - node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null, null]) + node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null]) node.log("Master Bedroom Climate: Auto/Bedtime/AC") } if (fanMode === 'fan') { - node.send([null, sendFan, null, null, null]) + node.send([null, sendFan, null, null]) node.log("Master Bedroom Climate: Auto/Bedtime/Fan") } } else if (topic === 'mrbedroom-fan' && fanMode === 'Fan') { node.status({ fill: "green", shape: "dot", text: "Fan Schedule" }) - node.send([null, sendFan, null, null, null]) + node.send([null, sendFan, null, null]) node.log("Master Bedroom Climate: Auto/Fan") } else if (topic === 'mrbedroom-wakeup') { - node.send([null, null, null, null, sendBriefing]) node.status({ fill: "green", shape: "dot", text: "Wakeup Schedule" }) node.log("Master Bedroom Climate: Auto/Wakeup") if (sleeping === 'off') { context.set("isWakeup", false) - node.send([null, sendFan, null, null, null]) + node.send([null, sendFan, null, null]) node.log("Master Bedroom Climate: Auto/Wakeup/Sleep Off") if (ac === 'on') { - node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null, null]) + node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null]) node.log("Master Bedroom Climate: Auto/Wakeup/AC On") } } else if (sleeping === 'on') { context.set("isWakeup", true) - node.send([null, null, sendSleep, null, null]) + node.send([null, null, sendSleep, null]) node.log("Master Bedroom Climate: Auto/Wakeup/Sleep On") } } @@ -398,26 +380,26 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o node.log("Master Bedroom Climate: Manual") if (time === 'night') { node.status({ fill: "blue", shape: "dot", text: "Manual Night" }) - node.send([null, sendFan, null, null, null]) + node.send([null, sendFan, null, null]) node.log("Master Bedroom Climate: Manual/Night") if (ac === 'on') { - node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null, null]) + node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null]) node.log("Master Bedroom Climate: Manual/Night/AC") } } else if (time === 'day') { node.status({ fill: "blue", shape: "dot", text: "Manual Day" }) - node.send([null, sendFan, null, null, null]) + node.send([null, sendFan, null, null]) node.log("Master Bedroom Climate: Manual/Day") if (ac === 'on') { - node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null, null]) + node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null]) node.log("Master Bedroom Climate: Manual/Day/AC") } } else if (time === 'bedtime') { node.status({ fill: "blue", shape: "dot", text: "Manual Bedtime" }) - node.send([null, sendFan, null, null, null]) + node.send([null, sendFan, null, null]) node.log("Master Bedroom Climate: Manual/Bedtime") if (ac === 'on') { - node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null, null]) + node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null]) node.log("Master Bedroom Climate: Manual/Bedtime/AC") } } @@ -425,28 +407,25 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o // Sleep Switch Responses } else if (type === 'sleep') { if (payload === 'off') { - node.send([null, null, sendPeople, null, null]) + node.send([null, null, sendPeople, null]) } node.log("Master Bedroom Climate: Sleep") if (time === 'bedtime') { node.status({ fill: "blue", shape: "dot", text: "Sleep" }) - node.send([null, sendFan, [sendEchoDotDND,sendPeople], null, null]) + node.send([null, sendFan, [sendEchoDotDND,sendPeople], null]) node.log("Master Bedroom Climate: Sleep/Bedtime") if (ac === 'on') { - node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null, null]) + node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null]) node.log("Master Bedroom Climate: Sleep/Bedtime/AC") } } else { node.status({ fill: "blue", shape: "dot", text: "Wakeup" }) - node.send([null, sendFan, sendEchoDotDND, null, null]) + node.send([null, sendFan, sendEchoDotDND, null]) node.log("Master Bedroom Climate: Sleep/Day") if (ac === 'on') { - node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null, null]) + node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null]) node.log(`Master Bedroom Climate: Sleep/${convertToTitleCase(time)}/AC`) } - if (time === 'day' && isWakeup === false) { - node.send([null, null, null, null, sendBriefing]) - } } context.set("isWakeup", false) } else if (meltdown === 'on') {