Compare commits

..

3 Commits

8 changed files with 65 additions and 108 deletions

View File

@@ -11,7 +11,7 @@ let fanOnlyMsg = {
"topic": "Emma AC Mode: Fan Only" "topic": "Emma AC Mode: Fan Only"
} }
if (topic === 'emmabedroom-climate') { if (topic === 'emmabedroom-cooling') {
if (acMode === 'AC') { if (acMode === 'AC') {
node.status({fill:"green",shape:"dot",text:"AC Cooling"}) node.status({fill:"green",shape:"dot",text:"AC Cooling"})
return coolMsg return coolMsg

View File

@@ -1,14 +0,0 @@
const outdoor = global.get("outdoorTemp.tempInt")
const thresholdEntity = global.get("homeassistant.homeAssistant.states['input_number.emma_bedroom_aircon_mode_threshold'].state")
const threshold = parseInt(thresholdEntity)
msg.outdoor = outdoor
msg.modeThreshold = threshold
if (outdoor >= threshold) {
node.status({fill:"green",shape:"dot",text:`${outdoor} >= ${threshold}`})
return msg
} else {
node.status({fill:"red",shape:"ring",text:`${outdoor} < ${threshold}`})
return null
}

View File

@@ -322,7 +322,7 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
node.status({ fill: "red", shape: "ring", text: "Blocked (sleep mode)" }) node.status({ fill: "red", shape: "ring", text: "Blocked (sleep mode)" })
node.log("Emma Bedroom Climate: Blocked (sleep mode)") node.log("Emma Bedroom Climate: Blocked (sleep mode)")
} else { } else {
if (topic === 'emmabedroom-climate' && ac === 'on') { if (topic === 'emmabedroom-cooling' && ac === 'on') {
node.status({ fill: "green", shape: "dot", text: "Cooling Schedule" }) node.status({ fill: "green", shape: "dot", text: "Cooling Schedule" })
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null]) node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null])
node.log("Emma Bedroom Climate: Auto/Cooling") node.log("Emma Bedroom Climate: Auto/Cooling")

View File

@@ -0,0 +1,15 @@
const states = global.get('homeassistant.homeAssistant.states')
const earlyNight = states['binary_sensor.early_night_mode'].state
const payload = msg.payload
if (payload === 'off') {
if (earlyNight === 'on') {
msg.mode = 'Night Mode'
} else {
msg.mode = 'Day Mode'
}
} else if (payload === 'on') {
msg.mode = 'Bedtime Mode'
}
return msg

View File

@@ -1,14 +0,0 @@
const outdoor = global.get("outdoorTemp.tempInt")
const thresholdEntity = global.get("homeassistant.homeAssistant.states['input_number.master_bedroom_aircon_mode_threshold'].state")
const threshold = parseInt(thresholdEntity)
msg.outdoor = outdoor
msg.modeThreshold = threshold
if (outdoor >= threshold) {
node.status({fill:"green",shape:"dot",text:`${outdoor} >= ${threshold}`})
return msg
} else {
node.status({fill:"red",shape:"ring",text:`${outdoor} < ${threshold}`})
return null
}

View File

@@ -11,7 +11,6 @@ const dayTemp = states['input_number.master_bedroom_daytime_temp'].state
const nightTemp = states['input_number.master_bedroom_night_temp'].state const nightTemp = states['input_number.master_bedroom_night_temp'].state
const bedTemp = states['input_number.master_bedroom_bedtime_temp'].state const bedTemp = states['input_number.master_bedroom_bedtime_temp'].state
const showerMode = states['input_boolean.shower_mode'].state const showerMode = states['input_boolean.shower_mode'].state
const nightVolume = states['input_number.master_bedroom_echo_dot_night_volume'].state
const fanMode = states['input_select.scheduled_climate_mode_master_bedroom_fan'].state const fanMode = states['input_select.scheduled_climate_mode_master_bedroom_fan'].state
const acMode = states['input_select.scheduled_climate_mode_master_bedroom_aircon'].state const acMode = states['input_select.scheduled_climate_mode_master_bedroom_aircon'].state
const sleeping = states['input_boolean.master_bedroom_sleeping'].state const sleeping = states['input_boolean.master_bedroom_sleeping'].state
@@ -21,8 +20,8 @@ const showerCooldown = states["timer.shower_mode_cooldown"].state
const earlyNight = states["binary_sensor.early_night_mode"].state const earlyNight = states["binary_sensor.early_night_mode"].state
const danger = states['binary_sensor.heat_warning'].attributes.danger const danger = states['binary_sensor.heat_warning'].attributes.danger
const meltdown = states['input_boolean.meltdown_protocol'].state 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 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") node.log("Master Bedroom Climate: Constants Set")
// Define some entity IDs // Define some entity IDs
@@ -47,14 +46,13 @@ let setAcFan = 'auto'
let setEco = 'auto' let setEco = 'auto'
let setHvac = 'cool' let setHvac = 'cool'
let setFan = [] let setFan = []
let setCool = [] let setMode = []
let validNight = ['Night Mode','Bedtime Mode']
let setSleep = [] let setSleep = []
let setPeople = [] let setPeople = []
let setDisplay = 'turn_on' let setDisplay = 'turn_on'
let time = [] let time = []
let echoDotService = [] let echoDotService = []
let setBriefing = []
let setBriefingDelay = []
let type = msg.type let type = msg.type
let topic = msg.topic let topic = msg.topic
let isWakeup = context.get("isWakeup") let isWakeup = context.get("isWakeup")
@@ -65,15 +63,18 @@ if (type === 'sleep' && payload === 'off') {
setDisplay = 'turn_on' setDisplay = 'turn_on'
echoDotService = 'turn_off' echoDotService = 'turn_off'
setPeople = 'turn_on' setPeople = 'turn_on'
if (coolingActive === 'on') { if (validNight.includes(currentMode)) {
time = 'night' time = 'night'
setMode = 'Night Mode'
} else { } else {
time = 'day' time = 'day'
setMode = 'Day Mode'
} }
} else if (type === 'sleep' && payload === 'on') { } else if (type === 'sleep' && payload === 'on') {
setDisplay = 'turn_off' setDisplay = 'turn_off'
echoDotService = 'turn_on' echoDotService = 'turn_on'
time = 'bedtime' time = 'bedtime'
setMode = 'Bedtime Mode'
} else { } else {
time = msg.time time = msg.time
} }
@@ -82,20 +83,9 @@ if (topic === 'mrbedroom-wakeup') {
setSleep = 'turn_off' 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 // Day Time
if (time === 'day') { if (time === 'day') {
if (type === 'auto') { setMode = 'Day Mode'
setCool = 'turn_off'
}
if (earlyNight === 'off') { if (earlyNight === 'off') {
setFan = "turn_off" setFan = "turn_off"
if (ac === 'on') { if (ac === 'on') {
@@ -141,10 +131,7 @@ if (time === 'day') {
} }
// Night Time // Night Time
} else if (time === 'night') { } else if (time === 'night') {
// If this is being run at scheduled time, turn on input_boolean.master_bedroom_cooling_on setMode = 'Night Mode'
if (type === 'auto') {
setCool = 'turn_on'
}
// Decide temperature // Decide temperature
if (type === 'sleep' && payload === 'off') { if (type === 'sleep' && payload === 'off') {
setTemp = dayTemp setTemp = dayTemp
@@ -175,6 +162,7 @@ if (time === 'day') {
} }
// Bed Time // Bed Time
} else if (time === 'bedtime') { } else if (time === 'bedtime') {
setMode = 'Bedtime Mode'
setPeople = 'turn_off' setPeople = 'turn_off'
if (ac === 'on') { if (ac === 'on') {
setTemp = bedTemp setTemp = bedTemp
@@ -209,13 +197,15 @@ let sendFan = {
} }
} }
let sendCool = { let sendMode = {
"payload": { "payload": {
"action": `input_boolean.${setCool}`, "action": "input_select.select_option",
"target": { "target": {
"entity_id": ["input_boolean.master_bedroom_cooling_on"] "entity_id": ["input_select.current_climate_mode_master_bedroom"]
}, },
"data": {} "data": {
"option": setMode
}
} }
} }
@@ -256,13 +246,6 @@ let notify = {
"fanmode": fanMode "fanmode": fanMode
} }
let sendBriefing = {
"payload": {
"action": `script.${setBriefing}`,
},
"delay": setBriefingDelay
}
let sendHvac = { let sendHvac = {
"payload": { "payload": {
"action": "climate.set_hvac_mode", "action": "climate.set_hvac_mode",
@@ -329,12 +312,10 @@ node.log(`setAcFan: ${setAcFan}`)
node.log(`setEco: ${setEco}`) node.log(`setEco: ${setEco}`)
node.log(`setHvac: ${setHvac}`) node.log(`setHvac: ${setHvac}`)
node.log(`setFan: ${setFan}`) node.log(`setFan: ${setFan}`)
node.log(`setCool: ${setCool}`) node.log(`setMode: ${setMode}`)
node.log(`setSleep: ${setSleep}`) node.log(`setSleep: ${setSleep}`)
node.log(`setPeople: ${setPeople}`) node.log(`setPeople: ${setPeople}`)
node.log(`setDisplay: ${setDisplay}`) node.log(`setDisplay: ${setDisplay}`)
node.log(`setBriefing: ${setBriefing}`)
node.log(`setBriefingDelay: ${setBriefingDelay}`)
node.log(`time: ${time}`) node.log(`time: ${time}`)
node.log(`type: ${type}`) node.log(`type: ${type}`)
node.log(`topic: ${topic}`) node.log(`topic: ${topic}`)
@@ -342,13 +323,13 @@ node.log("----- Master Bedroom Climate: End Parameters -----")
// If this was an automated trigger, set the cooling context for the bedroom accordingly. // If this was an automated trigger, set the cooling context for the bedroom accordingly.
if (type === 'auto' && time != 'bedtime') { if (type === 'auto') {
node.send([null, null, sendCool, null, null]) node.send([null, null, sendMode, null])
node.log("Master Bedroom Climate: Cooling Context Set") node.log("Master Bedroom Climate: Cooling Mode Context Set")
} }
// Automated responses // Automated responses
if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'off') { //! allowed === 'off' currently because of upstairs heat issues. Need to figure out a way to still allow wakeup flow to run. if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'off') {
node.log("Master Bedroom Climate: Auto") node.log("Master Bedroom Climate: Auto")
if (sleeping === 'on' && topic != 'mrbedroom-wakeup') { if (sleeping === 'on' && topic != 'mrbedroom-wakeup') {
node.status({ fill: "red", shape: "ring", text: "Blocked (sleep mode)" }) node.status({ fill: "red", shape: "ring", text: "Blocked (sleep mode)" })
@@ -359,36 +340,35 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null]) node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null])
node.log("Master Bedroom Climate: Auto/Cooling") node.log("Master Bedroom Climate: Auto/Cooling")
} else if (topic === 'mrbedroom-bedtime') { } 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.status({ fill: "green", shape: "dot", text: "Bedtime" })
node.log("Master Bedroom Climate: Auto/Bedtime") node.log("Master Bedroom Climate: Auto/Bedtime")
if (ac === 'on') { 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") node.log("Master Bedroom Climate: Auto/Bedtime/AC")
} }
if (fanMode === 'fan') { if (fanMode === 'fan') {
node.send([null, sendFan, null, null, null]) node.send([null, sendFan, null, null])
node.log("Master Bedroom Climate: Auto/Bedtime/Fan") node.log("Master Bedroom Climate: Auto/Bedtime/Fan")
} }
} else if (topic === 'mrbedroom-fan' && fanMode === 'Fan') { } else if (topic === 'mrbedroom-fan' && fanMode === 'Fan') {
node.status({ fill: "green", shape: "dot", text: "Fan Schedule" }) 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") node.log("Master Bedroom Climate: Auto/Fan")
} else if (topic === 'mrbedroom-wakeup') { } else if (topic === 'mrbedroom-wakeup') {
node.send([null, null, null, null, sendBriefing])
node.status({ fill: "green", shape: "dot", text: "Wakeup Schedule" }) node.status({ fill: "green", shape: "dot", text: "Wakeup Schedule" })
node.log("Master Bedroom Climate: Auto/Wakeup") node.log("Master Bedroom Climate: Auto/Wakeup")
if (sleeping === 'off') { if (sleeping === 'off') {
context.set("isWakeup", false) 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") node.log("Master Bedroom Climate: Auto/Wakeup/Sleep Off")
if (ac === 'on') { 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") node.log("Master Bedroom Climate: Auto/Wakeup/AC On")
} }
} else if (sleeping === 'on') { } else if (sleeping === 'on') {
context.set("isWakeup", true) 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") node.log("Master Bedroom Climate: Auto/Wakeup/Sleep On")
} }
} }
@@ -398,26 +378,26 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
node.log("Master Bedroom Climate: Manual") node.log("Master Bedroom Climate: Manual")
if (time === 'night') { if (time === 'night') {
node.status({ fill: "blue", shape: "dot", text: "Manual 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") node.log("Master Bedroom Climate: Manual/Night")
if (ac === 'on') { 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") node.log("Master Bedroom Climate: Manual/Night/AC")
} }
} else if (time === 'day') { } else if (time === 'day') {
node.status({ fill: "blue", shape: "dot", text: "Manual 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") node.log("Master Bedroom Climate: Manual/Day")
if (ac === 'on') { 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") node.log("Master Bedroom Climate: Manual/Day/AC")
} }
} else if (time === 'bedtime') { } else if (time === 'bedtime') {
node.status({ fill: "blue", shape: "dot", text: "Manual 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") node.log("Master Bedroom Climate: Manual/Bedtime")
if (ac === 'on') { 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") node.log("Master Bedroom Climate: Manual/Bedtime/AC")
} }
} }
@@ -425,28 +405,25 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
// Sleep Switch Responses // Sleep Switch Responses
} else if (type === 'sleep') { } else if (type === 'sleep') {
if (payload === 'off') { if (payload === 'off') {
node.send([null, null, sendPeople, null, null]) node.send([null, null, sendPeople, null])
} }
node.log("Master Bedroom Climate: Sleep") node.log("Master Bedroom Climate: Sleep")
if (time === 'bedtime') { if (time === 'bedtime') {
node.status({ fill: "blue", shape: "dot", text: "Sleep" }) 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") node.log("Master Bedroom Climate: Sleep/Bedtime")
if (ac === 'on') { 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") node.log("Master Bedroom Climate: Sleep/Bedtime/AC")
} }
} else { } else {
node.status({ fill: "blue", shape: "dot", text: "Wakeup" }) 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") node.log("Master Bedroom Climate: Sleep/Day")
if (ac === 'on') { 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`) 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) context.set("isWakeup", false)
} else if (meltdown === 'on') { } else if (meltdown === 'on') {

View File

@@ -5,8 +5,7 @@ const lux = parseInt(states['sensor.master_bedroom_illuminance'].state)
const threshold = parseInt(states['input_number.master_bedroom_lux_threshold'].state) const threshold = parseInt(states['input_number.master_bedroom_lux_threshold'].state)
const masterBedroomSleep = states['input_boolean.master_bedroom_sleeping'].state const masterBedroomSleep = states['input_boolean.master_bedroom_sleeping'].state
const kallenBedroomSleep = states['input_boolean.kallen_sleeping'].state const kallenBedroomSleep = states['input_boolean.kallen_sleeping'].state
const emmaBedroomSleep = states['input_boolean.emma_sleeping'].state const peopleSleeping = (masterBedroomSleep === 'on' || kallenBedroomSleep === 'on')
const peopleSleeping = (masterBedroomSleep === 'on' || kallenBedroomSleep === 'on' || emmaBedroomSleep === 'on')
const nightMode = states['input_boolean.night_mode'].state const nightMode = states['input_boolean.night_mode'].state
const payload = msg.payload const payload = msg.payload
const newDuration = duration * 60 const newDuration = duration * 60

View File

@@ -2,17 +2,11 @@ const states = global.get('homeassistant.homeAssistant.states')
const lights = states['light.upstairs_bathroom_lights'].state const lights = states['light.upstairs_bathroom_lights'].state
const duration = states['input_number.upstairs_bathroom_motion_off_delay'].state const duration = states['input_number.upstairs_bathroom_motion_off_delay'].state
const lux = parseInt(states['sensor.upstairs_bathroom_illuminance'].state) const lux = parseInt(states['sensor.upstairs_bathroom_illuminance'].state)
const threshold = parseInt(states['input_number.upstairs_bathroom_lux_threshold'].state)
const showerMode = states['input_boolean.shower_mode'].state const showerMode = states['input_boolean.shower_mode'].state
const emmaBedroomSleep = states['input_boolean.emma_sleeping'].state
const payload = msg.payload const payload = msg.payload
const newDuration = duration * 60 const newDuration = duration * 60
let threshold = parseInt(states['input_number.upstairs_bathroom_lux_threshold'].state)
if (emmaBedroomSleep === 'on') {
threshold = 10
}
let timerCancel = { let timerCancel = {
"payload": "stop" "payload": "stop"
} }
@@ -38,11 +32,11 @@ if (showerMode === 'off') {
} }
node.log("----- Upstairs Bathroom Motion Parameters Start -----") node.log("----- Upstairs Bathroom Motion Parameters Start -----")
node.log(`Upstairs Bathroom payload: ${payload}`) node.log("Upstairs Bathroom payload: " + payload)
node.log(`Upstairs Bathroom lights: ${lights}`) node.log("Upstairs Bathroom lights: " + lights)
node.log(`Upstairs Bathroom duration: ${duration}`) node.log("Upstairs Bathroom duration: " + duration)
node.log(`Upstairs Bathroom newDuration: ${newDuration}`) node.log("Upstairs Bathroom newDuration: " + newDuration)
node.log(`Upstairs Bathroom lux: ${lux}`) node.log("Upstairs Bathroom lux: " + lux)
node.log(`Upstairs Bathroom threshold: ${threshold}`) node.log("Upstairs Bathroom threshold: " + threshold)
node.log(`Upstairs Bathroom showerMode: ${showerMode}`) node.log("Upstairs Bathroom showerMode: " + showerMode)
node.log("----- Upstairs Bathroom Motion Parameters End -----") node.log("----- Upstairs Bathroom Motion Parameters End -----")