84 lines
1.9 KiB
JavaScript
84 lines
1.9 KiB
JavaScript
const states = global.get('homeassistant.homeAssistant.states')
|
|
const toggle = msg.payload
|
|
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
|
|
|
|
let setTemp = bedTemp
|
|
let setEco = 'none'
|
|
let setHvac = 'cool'
|
|
let setAcFan = 'High'
|
|
let setFan = 'turn_off'
|
|
|
|
let sendFan = {
|
|
"payload": {
|
|
"action": `fan.${setFan}`,
|
|
"target": {
|
|
"entity_id": ["fan.master_bedroom_fan"]
|
|
},
|
|
"data": {}
|
|
}
|
|
}
|
|
|
|
let sendHvac = {
|
|
"payload": {
|
|
"action": "climate.set_hvac_mode",
|
|
"target": {
|
|
"entity_id": ["climate.master_bedroom_aircon"]
|
|
},
|
|
"data": {
|
|
"hvac_mode": setHvac
|
|
}
|
|
}
|
|
}
|
|
|
|
let sendTemp = {
|
|
"payload": {
|
|
"action": "climate.set_temperature",
|
|
"target": {
|
|
"entity_id": ["climate.master_bedroom_aircon"]
|
|
},
|
|
"data": {
|
|
"temperature": setTemp
|
|
}
|
|
}
|
|
}
|
|
|
|
let sendEco = {
|
|
"payload": {
|
|
"action": "climate.set_preset_mode",
|
|
"target": {
|
|
"entity_id": ["climate.master_bedroom_aircon"]
|
|
},
|
|
"data": {
|
|
"preset_mode": setEco
|
|
}
|
|
}
|
|
}
|
|
|
|
let sendAcFan = {
|
|
"payload": {
|
|
"action": "climate.set_fan_mode",
|
|
"target": {
|
|
"entity_id": ["climate.master_bedroom_aircon"]
|
|
},
|
|
"data": {
|
|
"fan_mode": setAcFan
|
|
}
|
|
}
|
|
}
|
|
|
|
let reset = {
|
|
"topic": "Reset"
|
|
}
|
|
|
|
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])
|
|
}
|
|
} else {
|
|
node.status({fill:"green",shape:"dot",text:"Danger Mode Off"})
|
|
node.send([null,null,reset])
|
|
} |