34 lines
994 B
JavaScript
34 lines
994 B
JavaScript
const states = global.get('homeassistant.homeAssistant.states')
|
|
const allowed = states['input_boolean.basement_studio_heat_allowed'].state
|
|
const outsideTemp = global.get('outdoorTemp.tempInt')
|
|
const todaysHighTemp = states['sensor.todays_high_temp'].state
|
|
const basementTemp = states['sensor.basement_studio_temperature'].state
|
|
|
|
let power = {}
|
|
let reason = {}
|
|
|
|
if (todaysHighTemp < 55) {
|
|
power = 'on'
|
|
reason = 'Todays High Temperature'
|
|
} else if (outsideTemp < 40) {
|
|
power = 'on'
|
|
reason = 'Outside Temperature'
|
|
} else if (basementTemp < 64) {
|
|
power = 'on'
|
|
reason = 'Basement Temperature'
|
|
} else {
|
|
power = 'off'
|
|
}
|
|
|
|
if (allowed === 'on') {
|
|
if (power === 'on') {
|
|
node.status({fill:'green',shape:'dot',text:`Heater Needed: ${reason}`})
|
|
node.send(msg,null)
|
|
} else {
|
|
node.status({fill:'red',shape:'ring',text:'Heater Not Needed'})
|
|
node.send(null,msg)
|
|
}
|
|
} else {
|
|
node.status({fill:'red',shape:'ring',text:'Heat Disabled'})
|
|
}
|