Files
HA-NerdFlows-Functions/climate/master-bedroom/shower-off.js

91 lines
2.4 KiB
JavaScript

const states = global.get('homeassistant.homeAssistant.states')
const ac = global.get('masterBedroom.aircon.installed', "diskCon")
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
const bedTemp = states['input_number.master_bedroom_bedtime_temp'].state
const currentSetTemp = states['climate.master_bedroom_aircon'].attributes.temperature
const coolingTime = states['input_boolean.master_bedroom_cooling_on'].state
const sleeping = states['input_boolean.master_bedroom_sleeping'].state
const hotDay = states['input_boolean.hot_day'].state
const topic = msg.topic
let setTemp = {}
let ecoMode = {}
let duration = {}
let end = {}
let hvac = {}
if (topic === 'toggle') {
if (hotDay === 'on' || sleeping === 'on') {
setTemp = bedTemp
ecoMode = 'none'
} else {
setTemp = nightTemp
ecoMode = 'eco'
}
} else if (topic === 'timer') {
if (currentSetTemp == bedTemp) {
setTemp = nightTemp
if (hotDay === 'on') {
ecoMode = 'none'
} else {
ecoMode = 'eco'
}
} else {
setTemp = dayTemp
ecoMode = 'eco'
}
}
if (setTemp == bedTemp) {
duration = 3600
} else if (setTemp == nightTemp && hotDay === 'off') {
duration = 3600
} else {
duration = 1800
}
if (setTemp == dayTemp) {
end = true
if (hotDay === 'off') {
hvac = 'off'
} else {
hvac = 'cool'
}
} else if (setTemp != bedTemp && coolingTime === 'on') {
end = true
hvac = 'cool'
} else {
end = false
hvac = 'cool'
}
let setMsg = {
"set": setTemp,
"eco": ecoMode,
"hvac": hvac,
"end": end
}
let timerStart = {
"duration": duration
}
if (ac === 'on' && temp >= threshold) {
if (sleeping === 'on' || coolingTime === 'on' || end === true) {
node.status({fill:"green",shape:"dot",text:"Finished"})
return [setMsg, null]
} else {
node.status({fill:"blue",shape:"dot",text:"Next Cycle"})
return [setMsg, timerStart]
}
} else if (ac === 'off') {
node.status({fill:"red",shape:"ring",text:"A/C Not Installed"})
return null
} else {
node.status({fill:"red",shape:"ring",text:"Too Cold"})
return null
}