Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
4029a7992f
|
|||
d4bf2e3f23
|
|||
5d8f69e4f4
|
|||
0b64c61cd1
|
|||
b6c0ac0713
|
|||
bff29b48e9
|
|||
bc1ed66b56
|
|||
fefc52bd01
|
|||
b626b5b5e8
|
|||
408b85bf6a
|
|||
ba56bd08f4
|
|||
b0870578ef
|
|||
da63c34b3d
|
|||
ae17ad6969
|
|||
7a957572c8
|
@ -4,8 +4,10 @@ const ac = global.get('emmaBedroom.aircon.installed', "diskCon")
|
||||
const lastMode = flow.get("emmaBedroom.lastMode", "diskCon")
|
||||
const bedTemp = states['input_number.emma_bedroom_bedtime_temp'].state
|
||||
|
||||
const airconEntity = ["climate.emma_bedroom_aircon"]
|
||||
|
||||
let setTemp = bedTemp
|
||||
let setEco = 'none'
|
||||
let setEco = 'turn_off'
|
||||
let setHvac = 'cool'
|
||||
let setAcFan = 'High'
|
||||
|
||||
@ -13,7 +15,7 @@ let sendHvac = {
|
||||
"payload": {
|
||||
"action": "climate.set_hvac_mode",
|
||||
"target": {
|
||||
"entity_id": ["climate.emma_bedroom_aircon"]
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"hvac_mode": setHvac
|
||||
@ -25,7 +27,7 @@ let sendTemp = {
|
||||
"payload": {
|
||||
"action": "climate.set_temperature",
|
||||
"target": {
|
||||
"entity_id": ["climate.emma_bedroom_aircon"]
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"temperature": setTemp
|
||||
@ -35,13 +37,11 @@ let sendTemp = {
|
||||
|
||||
let sendEco = {
|
||||
"payload": {
|
||||
"action": "climate.set_preset_mode",
|
||||
"action": `switch.${setEco}`,
|
||||
"target": {
|
||||
"entity_id": ["climate.emma_bedroom_aircon"]
|
||||
"entity_id": ["switch.emma_bedroom_aircon_eco_mode"]
|
||||
},
|
||||
"data": {
|
||||
"preset_mode": setEco
|
||||
}
|
||||
"data": {}
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ let sendAcFan = {
|
||||
"payload": {
|
||||
"action": "climate.set_fan_mode",
|
||||
"target": {
|
||||
"entity_id": ["climate.emma_bedroom_aircon"]
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"fan_mode": setAcFan
|
||||
@ -64,7 +64,7 @@ let reset = {
|
||||
if (toggle === 'on') {
|
||||
node.status({fill:"red",shape:"dot",text:"DANGER MODE ACTIVE"})
|
||||
if (ac === 'on') {
|
||||
node.send([[sendHvac,sendTemp,sendEco,sendTemp],null])
|
||||
node.send([[sendHvac,sendTemp,sendAcFan,sendEco],null])
|
||||
}
|
||||
} else {
|
||||
node.status({fill:"green",shape:"dot",text:"Danger Mode Off"})
|
||||
|
@ -22,9 +22,10 @@ node.log("Emma Bedroom Climate: Constants Set")
|
||||
|
||||
// Define reusable constants
|
||||
|
||||
const emmaBedroomAircon = "climate.emma_bedroom_aircon"
|
||||
const emmaBedroomWhiteNoise = "input_boolean.white_noise_emma_bedroom"
|
||||
const airconEntity = ["climate.emma_bedroom_aircon"]
|
||||
const whiteNoiseEntity = ["input_boolean.white_noise_emma_bedroom"]
|
||||
const validSchedModesAC = ['AC', 'Fan']
|
||||
const peopleIDs = ["input_boolean.emma_awake"]
|
||||
|
||||
// Helper function to convert a string to title case
|
||||
|
||||
@ -37,13 +38,14 @@ function convertToTitleCase(str) {
|
||||
|
||||
// init variables
|
||||
|
||||
let setTemp = []
|
||||
let setEco = []
|
||||
let setHvac = []
|
||||
let setTemp = dayTemp
|
||||
let setAcFan = 'auto'
|
||||
let setEco = 'turn_on'
|
||||
let setHvac = 'cool'
|
||||
let setCool = []
|
||||
let setSleep = []
|
||||
let setPeople = []
|
||||
let setDisplay = []
|
||||
let setDisplay = 'turn_on'
|
||||
let setWhiteNoise = "turn_off"
|
||||
let time = []
|
||||
let type = msg.type
|
||||
@ -80,15 +82,15 @@ if (time === 'day') {
|
||||
if (ac === 'on') {
|
||||
if (danger === 'Extreme') {
|
||||
setTemp = nightTemp
|
||||
setEco = "eco"
|
||||
setEco = "turn_on"
|
||||
setHvac = "cool"
|
||||
} else if (hotDay === 'on' || heatWarning === 'on') {
|
||||
setTemp = dayTemp
|
||||
setEco = "eco"
|
||||
setEco = "turn_on"
|
||||
setHvac = "cool"
|
||||
} else {
|
||||
setTemp = nightTemp
|
||||
setEco = "eco"
|
||||
setEco = "turn_on"
|
||||
setHvac = "off"
|
||||
}
|
||||
}
|
||||
@ -107,9 +109,9 @@ if (time === 'day') {
|
||||
setHvac = 'off'
|
||||
}
|
||||
if (hotDay === 'on') {
|
||||
setEco = 'none'
|
||||
setEco = 'turn_off'
|
||||
} else {
|
||||
setEco = 'eco'
|
||||
setEco = 'turn_on'
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -129,9 +131,9 @@ if (time === 'day') {
|
||||
}
|
||||
// Decide eco mode
|
||||
if (sleeping === 'on') {
|
||||
setEco = 'none'
|
||||
setEco = 'turn_off'
|
||||
} else {
|
||||
setEco = 'eco'
|
||||
setEco = 'turn_on'
|
||||
}
|
||||
// Decide HVAC mode
|
||||
if (schedMode === 'AC') {
|
||||
@ -146,11 +148,13 @@ if (time === 'day') {
|
||||
setPeople = 'turn_off'
|
||||
if (ac === 'on') {
|
||||
setTemp = bedTemp
|
||||
setEco = 'none'
|
||||
setEco = 'turn_off'
|
||||
if (schedMode === 'AC') {
|
||||
setHvac = 'cool'
|
||||
setDisplay = 'turn_off'
|
||||
} else if (schedMode === 'Fan') {
|
||||
setHvac = "fan_only"
|
||||
setDisplay = 'turn_off'
|
||||
} else if (schedMode === 'White Noise') {
|
||||
setWhiteNoise = 'turn_on'
|
||||
if (ac === 'on') {
|
||||
@ -189,7 +193,7 @@ let sendPeople = {
|
||||
"payload": {
|
||||
"action": `input_boolean.${setPeople}`,
|
||||
"target": {
|
||||
"entity_id": ["input_boolean.emma_awake"]
|
||||
"entity_id": peopleIDs
|
||||
},
|
||||
"data": {}
|
||||
}
|
||||
@ -209,7 +213,7 @@ let sendWhiteNoise = {
|
||||
"payload": {
|
||||
"action": `input_boolean.${setWhiteNoise}`,
|
||||
"target": {
|
||||
"entity_id": emmaBedroomWhiteNoise
|
||||
"entity_id": whiteNoiseEntity
|
||||
},
|
||||
"data": {}
|
||||
}
|
||||
@ -225,7 +229,7 @@ let sendHvac = {
|
||||
"payload": {
|
||||
"action": "climate.set_hvac_mode",
|
||||
"target": {
|
||||
"entity_id": emmaBedroomAircon
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"hvac_mode": setHvac
|
||||
@ -237,7 +241,7 @@ let sendTemp = {
|
||||
"payload": {
|
||||
"action": "climate.set_temperature",
|
||||
"target": {
|
||||
"entity_id": emmaBedroomAircon
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"temperature": setTemp
|
||||
@ -247,13 +251,11 @@ let sendTemp = {
|
||||
|
||||
let sendEco = {
|
||||
"payload": {
|
||||
"action": "climate.set_preset_mode",
|
||||
"action": `switch.${setEco}`,
|
||||
"target": {
|
||||
"entity_id": emmaBedroomAircon
|
||||
"entity_id": ["switch.emma_bedroom_aircon_eco_mode"]
|
||||
},
|
||||
"data": {
|
||||
"preset_mode": setEco
|
||||
}
|
||||
"data": {}
|
||||
}
|
||||
}
|
||||
|
||||
@ -261,20 +263,41 @@ let sendAcFan = {
|
||||
"payload": {
|
||||
"action": "climate.set_fan_mode",
|
||||
"target": {
|
||||
"entity_id": emmaBedroomAircon
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"fan_mode": "auto"
|
||||
"fan_mode": setAcFan
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
node.log("Emma Bedroom Climate: Message Payloads Defined")
|
||||
|
||||
// Send some parameters to flow context for use in other nodes
|
||||
|
||||
if (setHvac.length > 0) {
|
||||
flow.set('emmaBedroom.airconHvacMode',setHvac,'diskCon')
|
||||
}
|
||||
|
||||
if (setEco.length > 0) {
|
||||
flow.set('emmaBedroom.airconEco',setEco,'diskCon')
|
||||
}
|
||||
|
||||
if (setTemp.length > 0) {
|
||||
flow.set('emmaBedroom.airconTargetTemp',setTemp,'diskCon')
|
||||
}
|
||||
|
||||
if (setDisplay.length > 0) {
|
||||
flow.set('emmaBedroom.airconDisplay',setDisplay,'diskCon')
|
||||
}
|
||||
|
||||
flow.set('emmaBedroom.airconFanMode',setAcFan,'diskCon')
|
||||
|
||||
// Log the parameters that were chosen, for debugging purposes
|
||||
|
||||
node.log("----- Emma Bedroom Climate: Set Parameters -----")
|
||||
node.log(`setTemp: ${setTemp}`)
|
||||
node.log(`setAcFan: ${setAcFan}`)
|
||||
node.log(`setEco: ${setEco}`)
|
||||
node.log(`setHvac: ${setHvac}`)
|
||||
node.log(`setCool: ${setCool}`)
|
||||
@ -301,14 +324,14 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
||||
} else {
|
||||
if (topic === 'emmabedroom-cooling' && ac === 'on') {
|
||||
node.status({ fill: "green", shape: "dot", text: "Cooling Schedule" })
|
||||
node.send([[sendHvac, sendTemp, sendEco, sendAcFan], null, null])
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null])
|
||||
node.log("Emma Bedroom Climate: Auto/Cooling")
|
||||
} else if (topic === 'emmabedroom-bedtime') {
|
||||
node.send([null, sendPeople, null])
|
||||
node.status({ fill: "green", shape: "dot", text: "Bedtime" })
|
||||
node.log("Emma Bedroom Climate: Auto/Bedtime")
|
||||
if (validSchedModesAC.includes(schedMode) && ac === 'on') {
|
||||
node.send([[sendHvac, sendTemp, sendEco, sendAcFan], null, null])
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null])
|
||||
node.log("Emma Bedroom Climate: Auto/Bedtime/AC")
|
||||
} else if (schedMode === 'White Noise') {
|
||||
node.send([null, sendWhiteNoise, null])
|
||||
@ -322,7 +345,7 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
||||
node.send([null, sendWhiteNoise, null])
|
||||
node.log("Emma Bedroom Climate: Auto/Wakeup/Sleep Off")
|
||||
if (ac === 'on') {
|
||||
node.send([[sendHvac, sendTemp, sendEco, sendAcFan], null, null])
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null])
|
||||
node.log("Emma Bedroom Climate: Auto/Wakeup/AC On")
|
||||
}
|
||||
} else if (sleeping === 'on') {
|
||||
@ -339,7 +362,7 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
||||
node.status({ fill: "blue", shape: "dot", text: "Manual Night" })
|
||||
node.log("Emma Bedroom Climate: Manual/Night")
|
||||
if (ac === 'on') {
|
||||
node.send([[sendHvac, sendTemp, sendEco, sendAcFan], null, null])
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null])
|
||||
node.log("Emma Bedroom Climate: Manual/Night/AC")
|
||||
}
|
||||
} else if (time === 'day') {
|
||||
@ -347,14 +370,14 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
||||
node.send([null, sendWhiteNoise, null])
|
||||
node.log("Emma Bedroom Climate: Manual/Day")
|
||||
if (ac === 'on') {
|
||||
node.send([[sendHvac, sendTemp, sendEco, sendAcFan], null, null])
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null])
|
||||
node.log("Emma Bedroom Climate: Manual/Day/AC")
|
||||
}
|
||||
} else if (time === 'bedtime') {
|
||||
node.status({ fill: "blue", shape: "dot", text: "Manual Bedtime" })
|
||||
node.log("Emma Bedroom Climate: Manual/Bedtime")
|
||||
if (validSchedModesAC.includes(schedMode) && ac === 'on') {
|
||||
node.send([[sendHvac, sendTemp, sendEco, sendAcFan], null, null])
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null])
|
||||
node.log("Emma Bedroom Climate: Manual/Bedtime/AC")
|
||||
} else if (schedMode === 'White Noise') {
|
||||
node.send([null, sendWhiteNoise, null])
|
||||
@ -373,7 +396,7 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
||||
node.send([null, [sendPeople, sendWhiteNoise], null])
|
||||
node.log("Emma Bedroom Climate: Sleep/Bedtime")
|
||||
if (ac === 'on') {
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendEco, sendAcFan], null, null])
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null])
|
||||
node.log("Emma Bedroom Climate: Sleep/Bedtime/AC")
|
||||
}
|
||||
} else {
|
||||
@ -381,7 +404,7 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
||||
node.send([null, sendWhiteNoise, null])
|
||||
node.log("Emma Bedroom Climate: Sleep/Day")
|
||||
if (ac === 'on') {
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendEco, sendAcFan], null, null])
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null])
|
||||
node.log(`Emma Bedroom Climate: Sleep/${convertToTitleCase(time)}/AC`)
|
||||
}
|
||||
}
|
||||
|
21
climate/emma-bedroom/set-temp-vars.js
Normal file
21
climate/emma-bedroom/set-temp-vars.js
Normal file
@ -0,0 +1,21 @@
|
||||
const topic = msg.topic
|
||||
const payload = msg.payload
|
||||
const lastMode = flow.get('emmaBedroom.lastMode', 'diskCon')
|
||||
|
||||
if (topic === 'daytemp') {
|
||||
flow.set('emmaBedroom.dayTemp', payload, 'diskCon')
|
||||
} else if (topic === 'nighttemp') {
|
||||
flow.set("emmaBedroom.nightTemp", payload, "diskCon")
|
||||
} else if (topic === 'bedtemp') {
|
||||
flow.set("emmaBedroom.bedTemp", payload, "diskCon")
|
||||
}
|
||||
|
||||
if (lastMode === 'day') {
|
||||
flow.set('emmaBedroom.airconTargetTemp', flow.get('emmaBedroom.dayTemp', 'diskCon'), 'diskCon')
|
||||
} else if (lastMode === 'night') {
|
||||
flow.set('emmaBedroom.airconTargetTemp', flow.get('emmaBedroom.nightTemp', 'diskCon'), 'diskCon')
|
||||
} else if (lastMode === 'bedtime') {
|
||||
flow.set('emmaBedroom.airconTargetTemp', flow.get('emmaBedroom.bedTemp', 'diskCon'), 'diskCon')
|
||||
}
|
||||
|
||||
node.status({fill:'green',shape:'dot',text:`Set ${topic} to ${payload}`})
|
151
climate/emma-bedroom/watchdog.js
Normal file
151
climate/emma-bedroom/watchdog.js
Normal file
@ -0,0 +1,151 @@
|
||||
const states = global.get('homeassistant.homeAssistant.states')
|
||||
const sleeping = states['input_boolean.emma_sleeping'].state
|
||||
|
||||
if (sleeping !== 'on') {
|
||||
node.status({fill:'red',shape:'ring',text:'Emma not sleeping, watchdog disabled'})
|
||||
return null
|
||||
}
|
||||
|
||||
const airconEntity = ['climate.emma_bedroom_aircon']
|
||||
|
||||
// Gather relevant attributes from the aircon entity
|
||||
|
||||
const airconState = msg.payload.state
|
||||
const airconAttributes = msg.payload.attributes
|
||||
const airconEco = airconAttributes['eco_mode']
|
||||
const airconTargetTemp = airconAttributes['temperature']
|
||||
const airconFanMode = airconAttributes['fan_mode']
|
||||
const airconDisplay = airconAttributes['screen_display']
|
||||
|
||||
// Gather the last explicitly sent configuration from the context
|
||||
|
||||
const airconHvacCfg = flow.get('emmaBedroom.airconHvacMode', 'diskCon')
|
||||
const airconEcoCfg = flow.get('emmaBedroom.airconEco', 'diskCon')
|
||||
const airconTargetTempCfg = parseFloat(flow.get('emmaBedroom.airconTargetTemp', 'diskCon'))
|
||||
const airconFanModeCfg = flow.get('emmaBedroom.airconFanMode', 'diskCon')
|
||||
const airconDisplayCfg = flow.get('emmaBedroom.airconDisplay', 'diskCon')
|
||||
|
||||
// Compare the current state with the last sent configuration
|
||||
|
||||
let ecoMatch = {}
|
||||
let displayMatch = {}
|
||||
let counter = 0
|
||||
|
||||
let sendDisplay = {
|
||||
"payload": {
|
||||
"action": `switch.${airconDisplayCfg}`,
|
||||
"target": {
|
||||
"entity_id": ["switch.emma_bedroom_aircon_display"]
|
||||
},
|
||||
"data": {}
|
||||
}
|
||||
}
|
||||
|
||||
let sendHvac = {
|
||||
"payload": {
|
||||
"action": "climate.set_hvac_mode",
|
||||
"target": {
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"hvac_mode": airconHvacCfg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let sendTemp = {
|
||||
"payload": {
|
||||
"action": "climate.set_temperature",
|
||||
"target": {
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"temperature": airconTargetTempCfg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let sendEco = {
|
||||
"payload": {
|
||||
"action": `switch.${airconEcoCfg}`,
|
||||
"target": {
|
||||
"entity_id": ["switch.emma_bedroom_aircon_eco_mode"]
|
||||
},
|
||||
"data": {}
|
||||
}
|
||||
}
|
||||
|
||||
let sendAcFan = {
|
||||
"payload": {
|
||||
"action": "climate.set_fan_mode",
|
||||
"target": {
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"fan_mode": airconFanModeCfg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fix hvac mode if mismatch
|
||||
|
||||
if (airconState != airconHvacCfg) {
|
||||
node.log(`Emma Bedroom Aircon HVAC mode mismatch: ${airconState} vs ${airconHvacCfg}`)
|
||||
node.send(sendHvac)
|
||||
counter += 1
|
||||
}
|
||||
|
||||
// Fix eco mode if mismatch
|
||||
|
||||
if (airconEco === false && airconEcoCfg === 'turn_off') {
|
||||
ecoMatch = true
|
||||
} else if (airconEco === true && airconEcoCfg === 'turn_on') {
|
||||
ecoMatch = true
|
||||
} else {
|
||||
ecoMatch = false
|
||||
}
|
||||
|
||||
if (ecoMatch === false) {
|
||||
node.log(`Emma Bedroom Aircon Eco mode mismatch: ${airconEco} vs ${airconEcoCfg}`)
|
||||
node.send(sendEco)
|
||||
counter += 1
|
||||
}
|
||||
|
||||
// Fix target temperature if mismatch
|
||||
|
||||
if (airconTargetTemp != airconTargetTempCfg) {
|
||||
node.log(`Target temperature mismatch: ${airconTargetTemp} vs ${airconTargetTempCfg}`)
|
||||
node.send(sendTemp)
|
||||
counter += 1
|
||||
}
|
||||
|
||||
// Fix fan mode if mismatch
|
||||
|
||||
if (airconFanMode != airconFanModeCfg) {
|
||||
node.log(`Fan mode mismatch: ${airconFanMode} vs ${airconFanModeCfg}`)
|
||||
node.send(sendAcFan)
|
||||
counter += 1
|
||||
}
|
||||
|
||||
// Fix display mode if mismatch
|
||||
|
||||
if (airconDisplay === false && airconDisplayCfg === 'turn_off') {
|
||||
displayMatch = true
|
||||
} else if (airconDisplay === true && airconDisplayCfg === 'turn_on') {
|
||||
displayMatch = true
|
||||
} else {
|
||||
displayMatch = false
|
||||
}
|
||||
|
||||
if (displayMatch === false) {
|
||||
node.log(`Emma Bedroom Aircon Display mode mismatch: ${airconDisplay} vs ${airconDisplayCfg}`)
|
||||
node.send(sendDisplay)
|
||||
counter += 1
|
||||
}
|
||||
|
||||
if (counter > 0) {
|
||||
node.log(`Emma Bedroom Aircon: ${counter} configuration(s) fixed`)
|
||||
node.status({fill:'yellow',shape:'dot',text:`${counter} config(s) fixed`})
|
||||
} else {
|
||||
node.status({fill:'green',shape:'dot',text:`No config changes`})
|
||||
}
|
@ -4,8 +4,11 @@ const ac = global.get('masterBedroom.aircon.installed', "diskCon")
|
||||
const lastMode = flow.get("masterBedroom.lastMode", "diskCon")
|
||||
const bedTemp = states['input_number.master_bedroom_bedtime_temp'].state
|
||||
|
||||
const airconEntity = ["climate.master_bedroom_aircon"]
|
||||
const fanEntity = ["fan.master_bedroom_fan"]
|
||||
|
||||
let setTemp = bedTemp
|
||||
let setEco = 'none'
|
||||
let setEco = 'turn_off'
|
||||
let setHvac = 'cool'
|
||||
let setAcFan = 'High'
|
||||
let setFan = 'turn_off'
|
||||
@ -14,7 +17,7 @@ let sendFan = {
|
||||
"payload": {
|
||||
"action": `fan.${setFan}`,
|
||||
"target": {
|
||||
"entity_id": ["fan.master_bedroom_fan"]
|
||||
"entity_id": fanEntity
|
||||
},
|
||||
"data": {}
|
||||
}
|
||||
@ -24,7 +27,7 @@ let sendHvac = {
|
||||
"payload": {
|
||||
"action": "climate.set_hvac_mode",
|
||||
"target": {
|
||||
"entity_id": ["climate.master_bedroom_aircon"]
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"hvac_mode": setHvac
|
||||
@ -36,7 +39,7 @@ let sendTemp = {
|
||||
"payload": {
|
||||
"action": "climate.set_temperature",
|
||||
"target": {
|
||||
"entity_id": ["climate.master_bedroom_aircon"]
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"temperature": setTemp
|
||||
@ -46,13 +49,11 @@ let sendTemp = {
|
||||
|
||||
let sendEco = {
|
||||
"payload": {
|
||||
"action": "climate.set_preset_mode",
|
||||
"action": `switch.${setEco}`,
|
||||
"target": {
|
||||
"entity_id": ["climate.master_bedroom_aircon"]
|
||||
"entity_id": ["switch.master_bedroom_aircon_eco_mode"]
|
||||
},
|
||||
"data": {
|
||||
"preset_mode": setEco
|
||||
}
|
||||
"data": {}
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,7 +61,7 @@ let sendAcFan = {
|
||||
"payload": {
|
||||
"action": "climate.set_fan_mode",
|
||||
"target": {
|
||||
"entity_id": ["climate.master_bedroom_aircon"]
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"fan_mode": setAcFan
|
||||
@ -76,7 +77,7 @@ if (toggle === 'on') {
|
||||
node.status({fill:"red",shape:"dot",text:"DANGER MODE ACTIVE"})
|
||||
node.send([null,sendFan,null])
|
||||
if (ac === 'on') {
|
||||
node.send([[sendHvac,sendTemp,sendEco,sendTemp],null,null])
|
||||
node.send([[sendHvac,sendTemp,sendAcFan,sendEco],null,null])
|
||||
}
|
||||
} else {
|
||||
node.status({fill:"green",shape:"dot",text:"Danger Mode Off"})
|
||||
|
@ -27,8 +27,8 @@ node.log("Master Bedroom Climate: Constants Set")
|
||||
|
||||
// Define some entity IDs
|
||||
|
||||
const masterBedroomAircon = "climate.master_bedroom_aircon"
|
||||
const masterBedroomFan = "fan.master_bedroom_fan"
|
||||
const airconEntity = ["climate.master_bedroom_aircon"]
|
||||
const fanEntity = ["fan.master_bedroom_fan"]
|
||||
const peopleIDs = ["input_boolean.tony_awake", "input_boolean.tina_awake"]
|
||||
|
||||
// Helper function to convert a string to title case
|
||||
@ -42,14 +42,15 @@ function convertToTitleCase(str) {
|
||||
|
||||
// init variables
|
||||
|
||||
let setTemp = []
|
||||
let setEco = []
|
||||
let setHvac = []
|
||||
let setTemp = dayTemp
|
||||
let setAcFan = 'auto'
|
||||
let setEco = 'auto'
|
||||
let setHvac = 'cool'
|
||||
let setFan = []
|
||||
let setCool = []
|
||||
let setSleep = []
|
||||
let setPeople = []
|
||||
let setDisplay = []
|
||||
let setDisplay = 'turn_on'
|
||||
let time = []
|
||||
let echoDotService = []
|
||||
let setBriefing = []
|
||||
@ -100,15 +101,15 @@ if (time === 'day') {
|
||||
if (ac === 'on') {
|
||||
if (danger === 'Extreme') {
|
||||
setTemp = nightTemp
|
||||
setEco = "eco"
|
||||
setEco = "turn_on"
|
||||
setHvac = "cool"
|
||||
} else if (hotDay === 'on' || heatWarning === 'on') {
|
||||
setTemp = dayTemp
|
||||
setEco = "eco"
|
||||
setEco = "turn_on"
|
||||
setHvac = "cool"
|
||||
} else {
|
||||
setTemp = nightTemp
|
||||
setEco = "eco"
|
||||
setEco = "turn_on"
|
||||
setHvac = "off"
|
||||
}
|
||||
}
|
||||
@ -132,9 +133,9 @@ if (time === 'day') {
|
||||
setHvac = 'off'
|
||||
}
|
||||
if (hotDay === 'on') {
|
||||
setEco = 'none'
|
||||
setEco = 'turn_off'
|
||||
} else {
|
||||
setEco = 'eco'
|
||||
setEco = 'turn_on'
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -154,9 +155,9 @@ if (time === 'day') {
|
||||
}
|
||||
// Decide eco mode
|
||||
if (sleeping === 'on') {
|
||||
setEco = 'none'
|
||||
setEco = 'turn_off'
|
||||
} else {
|
||||
setEco = 'eco'
|
||||
setEco = 'turn_on'
|
||||
}
|
||||
// Decide HVAC mode
|
||||
if (acMode === 'AC') {
|
||||
@ -177,11 +178,13 @@ if (time === 'day') {
|
||||
setPeople = 'turn_off'
|
||||
if (ac === 'on') {
|
||||
setTemp = bedTemp
|
||||
setEco = 'none'
|
||||
setEco = 'turn_off'
|
||||
if (acMode === 'AC') {
|
||||
setHvac = 'cool'
|
||||
setDisplay = 'turn_off'
|
||||
} else if (acMode === 'Fan') {
|
||||
setHvac = "fan_only"
|
||||
setDisplay = 'turn_off'
|
||||
} else {
|
||||
setHvac = "off"
|
||||
}
|
||||
@ -200,7 +203,7 @@ let sendFan = {
|
||||
"payload": {
|
||||
"action": `fan.${setFan}`,
|
||||
"target": {
|
||||
"entity_id": masterBedroomFan
|
||||
"entity_id": fanEntity
|
||||
},
|
||||
"data": {}
|
||||
}
|
||||
@ -264,7 +267,7 @@ let sendHvac = {
|
||||
"payload": {
|
||||
"action": "climate.set_hvac_mode",
|
||||
"target": {
|
||||
"entity_id": masterBedroomAircon
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"hvac_mode": setHvac
|
||||
@ -276,7 +279,7 @@ let sendTemp = {
|
||||
"payload": {
|
||||
"action": "climate.set_temperature",
|
||||
"target": {
|
||||
"entity_id": masterBedroomAircon
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"temperature": setTemp
|
||||
@ -286,13 +289,11 @@ let sendTemp = {
|
||||
|
||||
let sendEco = {
|
||||
"payload": {
|
||||
"action": "climate.set_preset_mode",
|
||||
"action": `switch.${setEco}`,
|
||||
"target": {
|
||||
"entity_id": masterBedroomAircon
|
||||
"entity_id": ["switch.master_bedroom_aircon_eco_mode"]
|
||||
},
|
||||
"data": {
|
||||
"preset_mode": setEco
|
||||
}
|
||||
"data": {}
|
||||
}
|
||||
}
|
||||
|
||||
@ -300,10 +301,10 @@ let sendAcFan = {
|
||||
"payload": {
|
||||
"action": "climate.set_fan_mode",
|
||||
"target": {
|
||||
"entity_id": masterBedroomAircon
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"fan_mode": "auto"
|
||||
"fan_mode": setAcFan
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -324,6 +325,7 @@ node.log("Master Bedroom Climate: Message Payloads Defined")
|
||||
|
||||
node.log("----- Master Bedroom Climate: Set Parameters -----")
|
||||
node.log(`setTemp: ${setTemp}`)
|
||||
node.log(`setAcFan: ${setAcFan}`)
|
||||
node.log(`setEco: ${setEco}`)
|
||||
node.log(`setHvac: ${setHvac}`)
|
||||
node.log(`setFan: ${setFan}`)
|
||||
@ -354,14 +356,14 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
||||
} else {
|
||||
if (topic === 'mrbedroom-cooling' && ac === 'on') {
|
||||
node.status({ fill: "green", shape: "dot", text: "Cooling Schedule" })
|
||||
node.send([[sendHvac, sendTemp, sendEco, sendAcFan], null, null, null])
|
||||
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.status({ fill: "green", shape: "dot", text: "Bedtime" })
|
||||
node.log("Master Bedroom Climate: Auto/Bedtime")
|
||||
if (ac === 'on') {
|
||||
node.send([[sendHvac, sendTemp, sendEco, sendAcFan], null, null, null, null])
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null, null])
|
||||
node.log("Master Bedroom Climate: Auto/Bedtime/AC")
|
||||
}
|
||||
if (fanMode === 'fan') {
|
||||
@ -381,7 +383,7 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
||||
node.send([null, sendFan, null, null, null])
|
||||
node.log("Master Bedroom Climate: Auto/Wakeup/Sleep Off")
|
||||
if (ac === 'on') {
|
||||
node.send([[sendHvac, sendTemp, sendEco, sendAcFan], null, null, null, null])
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null, null])
|
||||
node.log("Master Bedroom Climate: Auto/Wakeup/AC On")
|
||||
}
|
||||
} else if (sleeping === 'on') {
|
||||
@ -399,7 +401,7 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
||||
node.send([null, sendFan, null, null, null])
|
||||
node.log("Master Bedroom Climate: Manual/Night")
|
||||
if (ac === 'on') {
|
||||
node.send([[sendHvac, sendTemp, sendEco, sendAcFan], null, null, null, null])
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null, null])
|
||||
node.log("Master Bedroom Climate: Manual/Night/AC")
|
||||
}
|
||||
} else if (time === 'day') {
|
||||
@ -407,7 +409,7 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
||||
node.send([null, sendFan, null, null, null])
|
||||
node.log("Master Bedroom Climate: Manual/Day")
|
||||
if (ac === 'on') {
|
||||
node.send([[sendHvac, sendTemp, sendEco, sendAcFan], null, null, null, null])
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null, null])
|
||||
node.log("Master Bedroom Climate: Manual/Day/AC")
|
||||
}
|
||||
} else if (time === 'bedtime') {
|
||||
@ -415,7 +417,7 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
||||
node.send([null, sendFan, null, null, null])
|
||||
node.log("Master Bedroom Climate: Manual/Bedtime")
|
||||
if (ac === 'on') {
|
||||
node.send([[sendHvac, sendTemp, sendEco, sendAcFan], null, null, null, null])
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null, null])
|
||||
node.log("Master Bedroom Climate: Manual/Bedtime/AC")
|
||||
}
|
||||
}
|
||||
@ -431,7 +433,7 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
||||
node.send([null, sendFan, [sendEchoDotDND,sendPeople], null, null])
|
||||
node.log("Master Bedroom Climate: Sleep/Bedtime")
|
||||
if (ac === 'on') {
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendEco, sendAcFan], null, null, null, null])
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null, null])
|
||||
node.log("Master Bedroom Climate: Sleep/Bedtime/AC")
|
||||
}
|
||||
} else {
|
||||
@ -439,7 +441,7 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
||||
node.send([null, sendFan, sendEchoDotDND, null, null])
|
||||
node.log("Master Bedroom Climate: Sleep/Day")
|
||||
if (ac === 'on') {
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendEco, sendAcFan], null, null, null, null])
|
||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null, null])
|
||||
node.log(`Master Bedroom Climate: Sleep/${convertToTitleCase(time)}/AC`)
|
||||
}
|
||||
if (time === 'day' && isWakeup === false) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
const states = global.get('homeassistant.homeAssistant.states')
|
||||
const ac = global.get('masterBedroom.aircon.installed', "diskCon")
|
||||
const temp = global.get('outdoorTemptempStr')
|
||||
const temp = global.get('outdoorTemp.tempStr')
|
||||
const threshold = states['input_number.master_bedroom_aircon_run_threshold'].state
|
||||
const dayTemp = states['input_number.master_bedroom_daytime_temp'].state
|
||||
const nightTemp = states['input_number.master_bedroom_night_temp'].state
|
||||
@ -11,31 +11,33 @@ const sleeping = states['input_boolean.master_bedroom_sleeping'].state
|
||||
const hotDay = states['input_boolean.hot_day'].state
|
||||
const topic = msg.topic
|
||||
|
||||
const airconEntity = ["climate.master_bedroom_aircon"]
|
||||
|
||||
let setTemp = {}
|
||||
let ecoMode = {}
|
||||
let setEco = {}
|
||||
let duration = {}
|
||||
let end = {}
|
||||
let hvac = {}
|
||||
let setHvac = {}
|
||||
|
||||
if (topic === 'toggle') {
|
||||
if (hotDay === 'on' || sleeping === 'on') {
|
||||
setTemp = bedTemp
|
||||
ecoMode = 'none'
|
||||
setEco = 'turn_off'
|
||||
} else {
|
||||
setTemp = nightTemp
|
||||
ecoMode = 'eco'
|
||||
setEco = 'turn_on'
|
||||
}
|
||||
} else if (topic === 'timer') {
|
||||
if (currentSetTemp == bedTemp) {
|
||||
setTemp = nightTemp
|
||||
if (hotDay === 'on') {
|
||||
ecoMode = 'none'
|
||||
setEco = 'turn_off'
|
||||
} else {
|
||||
ecoMode = 'eco'
|
||||
setEco = 'turn_on'
|
||||
}
|
||||
} else {
|
||||
setTemp = dayTemp
|
||||
ecoMode = 'eco'
|
||||
setEco = 'turn_on'
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,36 +52,75 @@ if (setTemp == bedTemp) {
|
||||
if (setTemp == dayTemp) {
|
||||
end = true
|
||||
if (hotDay === 'off') {
|
||||
hvac = 'off'
|
||||
setHvac = 'off'
|
||||
} else {
|
||||
hvac = 'cool'
|
||||
setHvac = 'cool'
|
||||
}
|
||||
} else if (setTemp != bedTemp && coolingTime === 'on') {
|
||||
end = true
|
||||
hvac = 'cool'
|
||||
setHvac = 'cool'
|
||||
} else {
|
||||
end = false
|
||||
hvac = 'cool'
|
||||
}
|
||||
|
||||
let setMsg = {
|
||||
"set": setTemp,
|
||||
"eco": ecoMode,
|
||||
"hvac": hvac,
|
||||
"end": end
|
||||
setHvac = 'cool'
|
||||
}
|
||||
|
||||
let timerStart = {
|
||||
"duration": duration
|
||||
}
|
||||
|
||||
let sendHvac = {
|
||||
"payload": {
|
||||
"action": "climate.set_hvac_mode",
|
||||
"target": {
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"hvac_mode": setHvac
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let sendTemp = {
|
||||
"payload": {
|
||||
"action": "climate.set_temperature",
|
||||
"target": {
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"temperature": setTemp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let sendEco = {
|
||||
"payload": {
|
||||
"action": `switch.${setEco}`,
|
||||
"target": {
|
||||
"entity_id": ["switch.master_bedroom_aircon_eco_mode"]
|
||||
},
|
||||
"data": {}
|
||||
}
|
||||
}
|
||||
|
||||
let sendAcFan = {
|
||||
"payload": {
|
||||
"action": "climate.set_fan_mode",
|
||||
"target": {
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"fan_mode": "auto"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ac === 'on' && temp >= threshold) {
|
||||
if (sleeping === 'on' || coolingTime === 'on' || end === true) {
|
||||
node.status({fill:"green",shape:"dot",text:"Finished"})
|
||||
return [setMsg, null]
|
||||
return [[sendHvac, sendTemp, sendAcFan, sendEco], null]
|
||||
} else {
|
||||
node.status({fill:"blue",shape:"dot",text:"Next Cycle"})
|
||||
return [setMsg, timerStart]
|
||||
return [[sendHvac, sendTemp, sendAcFan, sendEco], timerStart]
|
||||
}
|
||||
} else if (ac === 'off') {
|
||||
node.status({fill:"red",shape:"ring",text:"A/C Not Installed"})
|
||||
|
@ -6,17 +6,56 @@ const nightTemp = states['input_number.master_bedroom_night_temp'].state
|
||||
const bedTemp = states['input_number.master_bedroom_bedtime_temp'].state
|
||||
const sleeping = states['input_boolean.master_bedroom_sleeping'].state
|
||||
|
||||
const airconEntity = ["climate.master_bedroom_aircon"]
|
||||
|
||||
let setTemp = []
|
||||
let setHvac = "dry"
|
||||
let setEco = "turn_off"
|
||||
|
||||
if (sleeping === 'on') {
|
||||
setTemp = bedTemp
|
||||
} else {
|
||||
setTemp = nightTemp
|
||||
}
|
||||
|
||||
let sendHvac = {
|
||||
"payload": {
|
||||
"action": "climate.set_hvac_mode",
|
||||
"target": {
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"hvac_mode": setHvac
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let sendTemp = {
|
||||
"payload": {
|
||||
"action": "climate.set_temperature",
|
||||
"target": {
|
||||
"entity_id": airconEntity
|
||||
},
|
||||
"data": {
|
||||
"temperature": setTemp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let sendEco = {
|
||||
"payload": {
|
||||
"action": `switch.${setEco}`,
|
||||
"target": {
|
||||
"entity_id": ["switch.master_bedroom_aircon_eco_mode"]
|
||||
},
|
||||
"data": {}
|
||||
}
|
||||
}
|
||||
|
||||
if (ac === 'on') {
|
||||
if (temp >= threshold) {
|
||||
if (sleeping === 'on') {
|
||||
msg.set = bedTemp
|
||||
node.status({fill:"green",shape:"dot",text:`Shower Mode On: ${bedTemp}`})
|
||||
return msg
|
||||
} else {
|
||||
msg.set = nightTemp
|
||||
node.status({fill:"green",shape:"dot",text:`Shower Mode On: ${nightTemp}`})
|
||||
return msg
|
||||
}
|
||||
node.status({fill:"green",shape:"dot",text:`Shower Mode On: ${setTemp}°F`})
|
||||
node.send([[sendHvac, sendTemp, sendEco]])
|
||||
} else {
|
||||
node.status({fill:"red",shape:"ring",text:"Too Cold"})
|
||||
return null
|
||||
|
@ -3,11 +3,13 @@ const lights = states['light.kallen_bedroom_lights'].state
|
||||
const duration = states['input_number.kallen_bedroom_lights_off_delay'].state
|
||||
const lux = parseInt(states['sensor.kallen_bedroom_illuminance'].state)
|
||||
const threshold = parseInt(states['input_number.kallen_bedroom_lux_threshold'].state)
|
||||
const sleeping = states['input_boolean.kallen_sleeping'].state
|
||||
const kallenBedroomSleep = states['input_boolean.kallen_sleeping'].state
|
||||
const masterBedroomSleep = states['input_boolean.master_bedroom_sleeping'].state
|
||||
const peopleSleeping = (masterBedroomSleep === 'on' || kallenBedroomSleep === 'on')
|
||||
const payload = msg.payload
|
||||
const newDuration = duration * 60
|
||||
|
||||
if (sleeping === 'off') {
|
||||
if (peopleSleeping === false) {
|
||||
if (payload === 'on') {
|
||||
if (lux <= threshold && lights === 'off') {
|
||||
node.status({fill:'green',shape:'dot',text:'Turning lights on'})
|
||||
|
Reference in New Issue
Block a user