Make Emma's climate flow compatible with white noise

This commit is contained in:
2025-03-29 02:05:39 -04:00
parent 8c1d10f3ef
commit 114d5884c8

View File

@ -10,7 +10,7 @@ const vacation = states['input_boolean.vacation_mode'].state
const dayTemp = states['input_number.emma_bedroom_daytime_temp'].state
const nightTemp = states['input_number.emma_bedroom_night_temp'].state
const bedTemp = states['input_number.emma_bedroom_bedtime_temp'].state
const acMode = states['input_select.scheduled_climate_mode_emma_bedroom'].state
const schedMode = states['input_select.scheduled_climate_mode_emma_bedroom'].state
const sleeping = states['input_boolean.emma_sleeping'].state
const hotDay = states['input_boolean.hot_day'].state
const heatWarning = states["binary_sensor.heat_warning"].state
@ -20,9 +20,11 @@ const meltdown = states['input_boolean.meltdown_protocol'].state
const coolingActive = states['input_boolean.emma_bedroom_cooling_on'].state
node.log("Emma Bedroom Climate: Constants Set")
// Define some entity IDs
// Define reusable constants
const emmaBedroomAircon = "climate.emma_bedroom_aircon"
const emmaBedroomWhiteNoise = "input_boolean.white_noise_emma_bedroom"
const validSchedModesAC = ['AC', 'Fan']
// Helper function to convert a string to title case
@ -42,6 +44,7 @@ let setCool = []
let setSleep = []
let setPeople = []
let setDisplay = []
let setWhiteNoise = "turn_off"
let time = []
let type = msg.type
let topic = msg.topic
@ -96,9 +99,9 @@ if (time === 'day') {
} else {
setTemp = nightTemp
}
if (acMode === 'AC') {
if (schedMode === 'AC') {
setHvac = 'cool'
} else if (acMode === 'fan') {
} else if (schedMode === 'fan') {
setHvac = 'fan_only'
} else {
setHvac = 'off'
@ -131,9 +134,9 @@ if (time === 'day') {
setEco = 'eco'
}
// Decide HVAC mode
if (acMode === 'AC') {
if (schedMode === 'AC') {
setHvac = 'cool'
} else if (acMode === 'Fan') {
} else if (schedMode === 'Fan') {
setHvac = 'fan_only'
} else {
setHvac = 'off'
@ -144,10 +147,15 @@ if (time === 'day') {
if (ac === 'on') {
setTemp = bedTemp
setEco = 'none'
if (acMode === 'AC') {
if (schedMode === 'AC') {
setHvac = 'cool'
} else if (acMode === 'Fan') {
} else if (schedMode === 'Fan') {
setHvac = "fan_only"
} else if (schedMode === 'White Noise') {
setWhiteNoise = 'turn_on'
if (ac === 'on') {
setHvac = 'off'
}
} else {
setHvac = "off"
}
@ -197,10 +205,20 @@ let sendDisplay = {
}
}
let sendWhiteNoise = {
"payload": {
"action": `input_boolean.${setWhiteNoise}`,
"target": {
"entity_id": emmaBedroomWhiteNoise
},
"data": {}
}
}
let notify = {
"topic": topic,
"nighttemp": nightTemp,
"acmode": acMode
"schedMode": schedMode
}
let sendHvac = {
@ -289,15 +307,19 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
node.send([null, sendPeople, null])
node.status({ fill: "green", shape: "dot", text: "Bedtime" })
node.log("Emma Bedroom Climate: Auto/Bedtime")
if (ac === 'on') {
if (validSchedModesAC.includes(schedMode) && ac === 'on') {
node.send([[sendHvac, sendTemp, sendEco, sendAcFan], null, null])
node.log("Emma Bedroom Climate: Auto/Bedtime/AC")
} else if (schedMode === 'White Noise') {
node.send([null, sendWhiteNoise, null])
node.log("Emma Bedroom Climate: Auto/Bedtime/White Noise")
}
} else if (topic === 'emmabedroom-wakeup') {
node.status({ fill: "green", shape: "dot", text: "Wakeup Schedule" })
node.log("Emma Bedroom Climate: Auto/Wakeup")
if (sleeping === 'off') {
context.set("isWakeup", false)
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])
@ -322,6 +344,7 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
}
} else if (time === 'day') {
node.status({ fill: "blue", shape: "dot", text: "Manual Day" })
node.send([null, sendWhiteNoise, null])
node.log("Emma Bedroom Climate: Manual/Day")
if (ac === 'on') {
node.send([[sendHvac, sendTemp, sendEco, sendAcFan], null, null])
@ -330,21 +353,24 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
} else if (time === 'bedtime') {
node.status({ fill: "blue", shape: "dot", text: "Manual Bedtime" })
node.log("Emma Bedroom Climate: Manual/Bedtime")
if (ac === 'on') {
if (validSchedModesAC.includes(schedMode) && ac === 'on') {
node.send([[sendHvac, sendTemp, sendEco, sendAcFan], null, null])
node.log("Emma Bedroom Climate: Manual/Bedtime/AC")
} else if (schedMode === 'White Noise') {
node.send([null, sendWhiteNoise, null])
node.log("Emma Bedroom Climate: Manual/Bedtime/White Noise")
}
}
context.set("isWakeup", false)
// Sleep Switch Responses
} else if (type === 'sleep') {
if (payload === 'off') {
node.send([null, sendPeople, null])
node.send([null, [sendPeople, sendWhiteNoise], null])
}
node.log("Emma Bedroom Climate: Sleep")
if (time === 'bedtime') {
node.status({ fill: "blue", shape: "dot", text: "Sleep" })
node.send([null, sendPeople, null])
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])
@ -352,6 +378,7 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
}
} else {
node.status({ fill: "blue", shape: "dot", text: "Wakeup" })
node.send([null, sendWhiteNoise, null])
node.log("Emma Bedroom Climate: Sleep/Day")
if (ac === 'on') {
node.send([[sendDisplay, sendHvac, sendTemp, sendEco, sendAcFan], null, null])