Compare commits
7 Commits
master
...
lightingfx
Author | SHA1 | Date | |
---|---|---|---|
3107541623
|
|||
8a002c6599
|
|||
f758c36508
|
|||
591151f606
|
|||
d6a4b107a6
|
|||
58be744880
|
|||
90aef47ef1
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1 @@
|
|||||||
**.vscode
|
/.vscode
|
||||||
testing/
|
|
@ -1,6 +1,6 @@
|
|||||||
const states = global.get('homeassistant.homeAssistant.states')
|
const states = global.get('homeassistant.homeAssistant.states')
|
||||||
const allowed = states['input_boolean.basement_studio_heat_allowed'].state
|
const allowed = states['input_boolean.basement_studio_heat_allowed'].state
|
||||||
const outsideTemp = global.get('outdoorTemp.tempInt')
|
const outsideTemp = states['weather.iron_nerd_weather_station'].attributes.temperature
|
||||||
const nightMode = states['input_boolean.night_mode'].state
|
const nightMode = states['input_boolean.night_mode'].state
|
||||||
|
|
||||||
let power = {}
|
let power = {}
|
||||||
@ -13,14 +13,14 @@ if (outsideTemp > 32) {
|
|||||||
if (nightMode === 'on') {
|
if (nightMode === 'on') {
|
||||||
preset = "frost"
|
preset = "frost"
|
||||||
} else {
|
} else {
|
||||||
preset = "activity"
|
preset = "eco"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allowed === 'on') {
|
if (allowed === 'on') {
|
||||||
if (power === 'on') {
|
if (power === 'on') {
|
||||||
msg.preset = preset
|
msg.preset = preset
|
||||||
node.status({fill:'green',shape:'dot',text:`Preset ${preset}`})
|
node.status({fill:'green',shape:'dot',text:'Preset ' + preset})
|
||||||
node.send(msg,null)
|
node.send(msg,null)
|
||||||
} else {
|
} else {
|
||||||
node.status({fill:'red',shape:'ring',text:'Heater Shutoff'})
|
node.status({fill:'red',shape:'ring',text:'Heater Shutoff'})
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
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'})
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
const states = global.get('homeassistant.homeAssistant.states')
|
|
||||||
const toggle = msg.payload
|
|
||||||
const ac = global.get('emmaBedroom.aircon.installed', "diskCon")
|
|
||||||
const lastMode = flow.get("emmaBedroom.lastMode", "diskCon")
|
|
||||||
const bedTemp = states['input_number.emma_bedroom_bedtime_temp'].state
|
|
||||||
|
|
||||||
const airconEntity = ["climate.emma_bedroom_aircon"]
|
|
||||||
|
|
||||||
let setTemp = bedTemp
|
|
||||||
let setEco = 'turn_off'
|
|
||||||
let setHvac = 'cool'
|
|
||||||
let setAcFan = 'High'
|
|
||||||
|
|
||||||
let sendHvac = {
|
|
||||||
"payload": {
|
|
||||||
"action": "climate.set_hvac_mode",
|
|
||||||
"target": {
|
|
||||||
"entity_id": airconEntity
|
|
||||||
},
|
|
||||||
"data": {
|
|
||||||
"hvac_mode": setHvac
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendTemp = {
|
|
||||||
"payload": {
|
|
||||||
"action": "climate.set_temperature",
|
|
||||||
"target": {
|
|
||||||
"entity_id": airconEntity
|
|
||||||
},
|
|
||||||
"data": {
|
|
||||||
"temperature": setTemp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendEco = {
|
|
||||||
"payload": {
|
|
||||||
"action": `switch.${setEco}`,
|
|
||||||
"target": {
|
|
||||||
"entity_id": ["switch.emma_bedroom_aircon_eco_mode"]
|
|
||||||
},
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendAcFan = {
|
|
||||||
"payload": {
|
|
||||||
"action": "climate.set_fan_mode",
|
|
||||||
"target": {
|
|
||||||
"entity_id": airconEntity
|
|
||||||
},
|
|
||||||
"data": {
|
|
||||||
"fan_mode": setAcFan
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let reset = {
|
|
||||||
"topic": "Reset"
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toggle === 'on') {
|
|
||||||
node.status({fill:"red",shape:"dot",text:"DANGER MODE ACTIVE"})
|
|
||||||
if (ac === 'on') {
|
|
||||||
node.send([[sendHvac,sendTemp,sendAcFan,sendEco],null])
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
node.status({fill:"green",shape:"dot",text:"Danger Mode Off"})
|
|
||||||
node.send([null,reset])
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
const topic = msg.topic
|
|
||||||
const nightTemp = msg.nighttemp
|
|
||||||
const acMode = msg.acmode
|
|
||||||
|
|
||||||
let coolMsg = {
|
|
||||||
"payload": `Emma bedroom AC temp has been set to ${nightTemp} °F as scheduled`,
|
|
||||||
"topic": 'Emma AC Mode: Cooling'
|
|
||||||
}
|
|
||||||
let fanOnlyMsg = {
|
|
||||||
"payload": 'Mildly chilly outside, AC running fan only.',
|
|
||||||
"topic": "Emma AC Mode: Fan Only"
|
|
||||||
}
|
|
||||||
|
|
||||||
if (topic === 'emmabedroom-cooling') {
|
|
||||||
if (acMode === 'AC') {
|
|
||||||
node.status({fill:"green",shape:"dot",text:"AC Cooling"})
|
|
||||||
return coolMsg
|
|
||||||
} else if (acMode === 'Fan') {
|
|
||||||
node.status({fill:"green",shape:"dot",text:"AC Fan Only"})
|
|
||||||
return fanOnlyMsg
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
node.status({fill:"red",shape:"ring",text:"Notification not sent"})
|
|
||||||
return null
|
|
||||||
}
|
|
@ -1,423 +0,0 @@
|
|||||||
node.log("Emma Bedroom Climate: Processing Started");
|
|
||||||
// pull in the necessary information
|
|
||||||
|
|
||||||
const states = global.get('homeassistant.homeAssistant.states')
|
|
||||||
const allowed = states['input_boolean.emma_bedroom_climate_protocol'].state
|
|
||||||
const ac = global.get('emmaBedroom.aircon.installed', "diskCon")
|
|
||||||
const temp = global.get("outdoorTemp.tempStr")
|
|
||||||
const payload = msg.payload
|
|
||||||
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 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
|
|
||||||
const earlyNight = states["binary_sensor.early_night_mode"].state
|
|
||||||
const danger = states['binary_sensor.heat_warning'].attributes.danger
|
|
||||||
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 reusable constants
|
|
||||||
|
|
||||||
const airconEntity = ["climate.emma_bedroom_aircon"]
|
|
||||||
const whiteNoiseEntity = ["input_boolean.white_noise_emma_bedroom"]
|
|
||||||
const validSchedModesAC = ['AC', 'Fan']
|
|
||||||
const peopleIDs = ["input_boolean.emma_awake"]
|
|
||||||
|
|
||||||
// Helper function to convert a string to title case
|
|
||||||
|
|
||||||
function convertToTitleCase(str) {
|
|
||||||
if (!str) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return str.toLowerCase().replace(/\b\w/g, (s) => s.toUpperCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
// init variables
|
|
||||||
|
|
||||||
let setTemp = dayTemp
|
|
||||||
let setAcFan = 'auto'
|
|
||||||
let setEco = 'turn_on'
|
|
||||||
let setHvac = 'cool'
|
|
||||||
let setCool = []
|
|
||||||
let setSleep = []
|
|
||||||
let setPeople = []
|
|
||||||
let setDisplay = 'turn_on'
|
|
||||||
let setWhiteNoise = "turn_off"
|
|
||||||
let time = []
|
|
||||||
let type = msg.type
|
|
||||||
let topic = msg.topic
|
|
||||||
let isWakeup = context.get("isWakeup")
|
|
||||||
node.log("Emma Bedroom Climate: Variables Defined")
|
|
||||||
|
|
||||||
// Sleep Switch Handling
|
|
||||||
if (type === 'sleep' && payload === 'off') {
|
|
||||||
setDisplay = 'turn_on'
|
|
||||||
setPeople = 'turn_on'
|
|
||||||
if (coolingActive === 'on') {
|
|
||||||
time = 'night'
|
|
||||||
} else {
|
|
||||||
time = 'day'
|
|
||||||
}
|
|
||||||
} else if (type === 'sleep' && payload === 'on') {
|
|
||||||
setDisplay = 'turn_off'
|
|
||||||
time = 'bedtime'
|
|
||||||
} else {
|
|
||||||
time = msg.time
|
|
||||||
}
|
|
||||||
|
|
||||||
if (topic === 'emmabedroom-wakeup') {
|
|
||||||
setSleep = 'turn_off'
|
|
||||||
}
|
|
||||||
|
|
||||||
// Day Time
|
|
||||||
if (time === 'day') {
|
|
||||||
if (type === 'auto') {
|
|
||||||
setCool = 'turn_off'
|
|
||||||
}
|
|
||||||
if (earlyNight === 'off') {
|
|
||||||
if (ac === 'on') {
|
|
||||||
if (danger === 'Extreme') {
|
|
||||||
setTemp = nightTemp
|
|
||||||
setEco = "turn_on"
|
|
||||||
setHvac = "cool"
|
|
||||||
} else if (hotDay === 'on' || heatWarning === 'on') {
|
|
||||||
setTemp = dayTemp
|
|
||||||
setEco = "turn_on"
|
|
||||||
setHvac = "cool"
|
|
||||||
} else {
|
|
||||||
setTemp = nightTemp
|
|
||||||
setEco = "turn_on"
|
|
||||||
setHvac = "off"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (earlyNight === 'on') {
|
|
||||||
if (ac === 'on') {
|
|
||||||
if (danger === 'Extreme') {
|
|
||||||
setTemp === bedTemp
|
|
||||||
} else {
|
|
||||||
setTemp = nightTemp
|
|
||||||
}
|
|
||||||
if (schedMode === 'AC') {
|
|
||||||
setHvac = 'cool'
|
|
||||||
} else if (schedMode === 'fan') {
|
|
||||||
setHvac = 'fan_only'
|
|
||||||
} else {
|
|
||||||
setHvac = 'off'
|
|
||||||
}
|
|
||||||
if (hotDay === 'on') {
|
|
||||||
setEco = 'turn_off'
|
|
||||||
} else {
|
|
||||||
setEco = 'turn_on'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Night Time
|
|
||||||
} else if (time === 'night') {
|
|
||||||
// If this is being run at scheduled time, turn on input_boolean.emma_bedroom_cooling_on
|
|
||||||
if (type === 'auto') {
|
|
||||||
setCool = 'turn_on'
|
|
||||||
}
|
|
||||||
// Decide temperature
|
|
||||||
if (type === 'sleep' && payload === 'off') {
|
|
||||||
setTemp = dayTemp
|
|
||||||
} else if (danger === 'Extreme') {
|
|
||||||
setTemp = bedTemp
|
|
||||||
} else {
|
|
||||||
setTemp = nightTemp
|
|
||||||
}
|
|
||||||
// Decide eco mode
|
|
||||||
if (sleeping === 'on') {
|
|
||||||
setEco = 'turn_off'
|
|
||||||
} else {
|
|
||||||
setEco = 'turn_on'
|
|
||||||
}
|
|
||||||
// Decide HVAC mode
|
|
||||||
if (schedMode === 'AC') {
|
|
||||||
setHvac = 'cool'
|
|
||||||
} else if (schedMode === 'Fan') {
|
|
||||||
setHvac = 'fan_only'
|
|
||||||
} else {
|
|
||||||
setHvac = 'off'
|
|
||||||
}
|
|
||||||
// Bed Time
|
|
||||||
} else if (time === 'bedtime') {
|
|
||||||
setPeople = 'turn_off'
|
|
||||||
if (ac === 'on') {
|
|
||||||
setTemp = bedTemp
|
|
||||||
setEco = 'turn_off'
|
|
||||||
if (schedMode === 'AC') {
|
|
||||||
setHvac = 'cool'
|
|
||||||
setDisplay = 'turn_off'
|
|
||||||
} else if (schedMode === 'Fan') {
|
|
||||||
setHvac = "fan_only"
|
|
||||||
setDisplay = 'turn_off'
|
|
||||||
} else if (schedMode === 'White Noise') {
|
|
||||||
setWhiteNoise = 'turn_on'
|
|
||||||
if (ac === 'on') {
|
|
||||||
setHvac = 'off'
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setHvac = "off"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
node.log("Emma Bedroom Climate: Decision Logic Complete")
|
|
||||||
|
|
||||||
// Define message payloads
|
|
||||||
|
|
||||||
let sendCool = {
|
|
||||||
"payload": {
|
|
||||||
"action": `input_boolean.${setCool}`,
|
|
||||||
"target": {
|
|
||||||
"entity_id": ["input_boolean.emma_bedroom_cooling_on"]
|
|
||||||
},
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendSleep = {
|
|
||||||
"payload": {
|
|
||||||
"action": `input_boolean.${setSleep}`,
|
|
||||||
"target": {
|
|
||||||
"entity_id": ["input_boolean.emma_sleeping"]
|
|
||||||
},
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendPeople = {
|
|
||||||
"payload": {
|
|
||||||
"action": `input_boolean.${setPeople}`,
|
|
||||||
"target": {
|
|
||||||
"entity_id": peopleIDs
|
|
||||||
},
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendDisplay = {
|
|
||||||
"payload": {
|
|
||||||
"action": `switch.${setDisplay}`,
|
|
||||||
"target": {
|
|
||||||
"entity_id": ["switch.emma_bedroom_aircon_display"]
|
|
||||||
},
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendWhiteNoise = {
|
|
||||||
"payload": {
|
|
||||||
"action": `input_boolean.${setWhiteNoise}`,
|
|
||||||
"target": {
|
|
||||||
"entity_id": whiteNoiseEntity
|
|
||||||
},
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let notify = {
|
|
||||||
"topic": topic,
|
|
||||||
"nighttemp": nightTemp,
|
|
||||||
"schedMode": schedMode
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendHvac = {
|
|
||||||
"payload": {
|
|
||||||
"action": "climate.set_hvac_mode",
|
|
||||||
"target": {
|
|
||||||
"entity_id": airconEntity
|
|
||||||
},
|
|
||||||
"data": {
|
|
||||||
"hvac_mode": setHvac
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendTemp = {
|
|
||||||
"payload": {
|
|
||||||
"action": "climate.set_temperature",
|
|
||||||
"target": {
|
|
||||||
"entity_id": airconEntity
|
|
||||||
},
|
|
||||||
"data": {
|
|
||||||
"temperature": setTemp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendEco = {
|
|
||||||
"payload": {
|
|
||||||
"action": `switch.${setEco}`,
|
|
||||||
"target": {
|
|
||||||
"entity_id": ["switch.emma_bedroom_aircon_eco_mode"]
|
|
||||||
},
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendAcFan = {
|
|
||||||
"payload": {
|
|
||||||
"action": "climate.set_fan_mode",
|
|
||||||
"target": {
|
|
||||||
"entity_id": airconEntity
|
|
||||||
},
|
|
||||||
"data": {
|
|
||||||
"fan_mode": setAcFan
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
node.log("Emma Bedroom Climate: Message Payloads Defined")
|
|
||||||
|
|
||||||
// Send some parameters to flow context for use in other nodes
|
|
||||||
|
|
||||||
if (setHvac.length > 0) {
|
|
||||||
flow.set('emmaBedroom.airconHvacMode',setHvac,'diskCon')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setEco.length > 0) {
|
|
||||||
flow.set('emmaBedroom.airconEco',setEco,'diskCon')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setTemp.length > 0) {
|
|
||||||
flow.set('emmaBedroom.airconTargetTemp',setTemp,'diskCon')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setDisplay.length > 0) {
|
|
||||||
flow.set('emmaBedroom.airconDisplay',setDisplay,'diskCon')
|
|
||||||
}
|
|
||||||
|
|
||||||
flow.set('emmaBedroom.airconFanMode',setAcFan,'diskCon')
|
|
||||||
|
|
||||||
// Log the parameters that were chosen, for debugging purposes
|
|
||||||
|
|
||||||
node.log("----- Emma Bedroom Climate: Set Parameters -----")
|
|
||||||
node.log(`setTemp: ${setTemp}`)
|
|
||||||
node.log(`setAcFan: ${setAcFan}`)
|
|
||||||
node.log(`setEco: ${setEco}`)
|
|
||||||
node.log(`setHvac: ${setHvac}`)
|
|
||||||
node.log(`setCool: ${setCool}`)
|
|
||||||
node.log(`setSleep: ${setSleep}`)
|
|
||||||
node.log(`setPeople: ${setPeople}`)
|
|
||||||
node.log(`setDisplay: ${setDisplay}`)
|
|
||||||
node.log(`time: ${time}`)
|
|
||||||
node.log(`type: ${type}`)
|
|
||||||
node.log(`topic: ${topic}`)
|
|
||||||
node.log("----- Emma Bedroom Climate: End Parameters -----")
|
|
||||||
|
|
||||||
// If this was an automated trigger, set the cooling context for the bedroom accordingly.
|
|
||||||
|
|
||||||
if (type === 'auto' && time != 'bedtime') {
|
|
||||||
node.send([null, sendCool, null])
|
|
||||||
node.log("Emma Bedroom Climate: Cooling Context Set")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'off') {
|
|
||||||
node.log("Emma Bedroom Climate: Auto")
|
|
||||||
if (sleeping === 'on' && topic != 'emmabedroom-wakeup') {
|
|
||||||
node.status({ fill: "red", shape: "ring", text: "Blocked (sleep mode)" })
|
|
||||||
node.log("Emma Bedroom Climate: Blocked (sleep mode)")
|
|
||||||
} else {
|
|
||||||
if (topic === 'emmabedroom-cooling' && ac === 'on') {
|
|
||||||
node.status({ fill: "green", shape: "dot", text: "Cooling Schedule" })
|
|
||||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null])
|
|
||||||
node.log("Emma Bedroom Climate: Auto/Cooling")
|
|
||||||
} else if (topic === 'emmabedroom-bedtime') {
|
|
||||||
node.send([null, sendPeople, null])
|
|
||||||
node.status({ fill: "green", shape: "dot", text: "Bedtime" })
|
|
||||||
node.log("Emma Bedroom Climate: Auto/Bedtime")
|
|
||||||
if (validSchedModesAC.includes(schedMode) && ac === 'on') {
|
|
||||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], 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([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null])
|
|
||||||
node.log("Emma Bedroom Climate: Auto/Wakeup/AC On")
|
|
||||||
}
|
|
||||||
} else if (sleeping === 'on') {
|
|
||||||
context.set("isWakeup", true)
|
|
||||||
node.send([null, sendSleep, null])
|
|
||||||
node.log("Emma Bedroom Climate: Auto/Wakeup/Sleep On")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Manual Responses
|
|
||||||
} else if (type === 'manual') {
|
|
||||||
node.log("Emma Bedroom Climate: Manual")
|
|
||||||
if (time === 'night') {
|
|
||||||
node.status({ fill: "blue", shape: "dot", text: "Manual Night" })
|
|
||||||
node.log("Emma Bedroom Climate: Manual/Night")
|
|
||||||
if (ac === 'on') {
|
|
||||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null])
|
|
||||||
node.log("Emma Bedroom Climate: Manual/Night/AC")
|
|
||||||
}
|
|
||||||
} 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([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null])
|
|
||||||
node.log("Emma Bedroom Climate: Manual/Day/AC")
|
|
||||||
}
|
|
||||||
} else if (time === 'bedtime') {
|
|
||||||
node.status({ fill: "blue", shape: "dot", text: "Manual Bedtime" })
|
|
||||||
node.log("Emma Bedroom Climate: Manual/Bedtime")
|
|
||||||
if (validSchedModesAC.includes(schedMode) && ac === 'on') {
|
|
||||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], 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, sendWhiteNoise], null])
|
|
||||||
}
|
|
||||||
node.log("Emma Bedroom Climate: Sleep")
|
|
||||||
if (time === 'bedtime') {
|
|
||||||
node.status({ fill: "blue", shape: "dot", text: "Sleep" })
|
|
||||||
node.send([null, [sendPeople, sendWhiteNoise], null])
|
|
||||||
node.log("Emma Bedroom Climate: Sleep/Bedtime")
|
|
||||||
if (ac === 'on') {
|
|
||||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null])
|
|
||||||
node.log("Emma Bedroom Climate: Sleep/Bedtime/AC")
|
|
||||||
}
|
|
||||||
} 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, sendAcFan, sendEco], null, null])
|
|
||||||
node.log(`Emma Bedroom Climate: Sleep/${convertToTitleCase(time)}/AC`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
context.set("isWakeup", false)
|
|
||||||
} else if (meltdown === 'on') {
|
|
||||||
node.status({ fill: "red", shape: "ring", text: "Blocked (Meltdown Protocol)" })
|
|
||||||
node.log("Emma Bedroom Climate: Blocked (Meltdown Protocol)")
|
|
||||||
} else if (vacation === 'on') {
|
|
||||||
node.status({ fill: "red", shape: "ring", text: "Blocked (Vacation Mode)" })
|
|
||||||
node.log("Emma Bedroom Climate: Blocked (Vacation Mode)")
|
|
||||||
} else {
|
|
||||||
node.status({ fill: "red", shape: "ring", text: "Blocked (Automation Disabled)" })
|
|
||||||
node.log("Emma Bedroom Climate: Blocked (Automation Disabled)")
|
|
||||||
}
|
|
||||||
|
|
||||||
node.log("Emma Bedroom Climate: Processing Complete")
|
|
@ -1,30 +0,0 @@
|
|||||||
const lastMode = flow.get("emmaBedroom.lastMode", "diskCon")
|
|
||||||
const linkSource = msg._linkSource
|
|
||||||
|
|
||||||
let setTime = []
|
|
||||||
let setType = []
|
|
||||||
let setTopic = []
|
|
||||||
|
|
||||||
if (lastMode === 'day') {
|
|
||||||
setTime = 'day'
|
|
||||||
setType = 'manual'
|
|
||||||
setTopic = 'manual-day'
|
|
||||||
} else if (lastMode === 'night') {
|
|
||||||
setTime = 'night'
|
|
||||||
setType = 'manual'
|
|
||||||
setTopic = 'manual-night'
|
|
||||||
} else if (lastMode === 'bedtime') {
|
|
||||||
setTime = 'bedtime'
|
|
||||||
setType = 'manual'
|
|
||||||
setTopic = 'manual-bedtime'
|
|
||||||
}
|
|
||||||
|
|
||||||
let reset = {
|
|
||||||
"type": setType,
|
|
||||||
"time": setTime,
|
|
||||||
"topic": setTopic,
|
|
||||||
"_linkSource": linkSource
|
|
||||||
}
|
|
||||||
|
|
||||||
node.send(reset)
|
|
||||||
node.status({ fill: "green", shape: "dot", text: `Mode reset to ${setTopic}`})
|
|
@ -1,20 +0,0 @@
|
|||||||
const states = global.get("homeassistant.homeAssistant.states")
|
|
||||||
const sleeping = states["input_boolean.emma_sleeping"].state
|
|
||||||
const earlyNight = states["binary_sensor.early_night_mode"].state
|
|
||||||
const giveMeDarkness = states["input_boolean.give_me_darkness"].state
|
|
||||||
const nightMode = states["input_boolean.night_mode"].state
|
|
||||||
const goodnight = states["input_boolean.goodnight"].state
|
|
||||||
const coolingActive = states['input_boolean.emma_bedroom_cooling_on'].state
|
|
||||||
|
|
||||||
let lastMode = []
|
|
||||||
|
|
||||||
if (sleeping === 'on' || nightMode === 'on' || goodnight === 'on') {
|
|
||||||
lastMode = 'bedtime'
|
|
||||||
} else if (earlyNight === 'on' || giveMeDarkness === 'on' || coolingActive === 'on') {
|
|
||||||
lastMode = 'night'
|
|
||||||
} else {
|
|
||||||
lastMode = 'day'
|
|
||||||
}
|
|
||||||
|
|
||||||
flow.set("emmaBedroom.lastMode", lastMode, "diskCon")
|
|
||||||
node.status({ fill: "green", shape: "dot", text: `Last Mode Set: ${lastMode}`})
|
|
@ -1,21 +0,0 @@
|
|||||||
const topic = msg.topic
|
|
||||||
const payload = msg.payload
|
|
||||||
const lastMode = flow.get('emmaBedroom.lastMode', 'diskCon')
|
|
||||||
|
|
||||||
if (topic === 'daytemp') {
|
|
||||||
flow.set('emmaBedroom.dayTemp', payload, 'diskCon')
|
|
||||||
} else if (topic === 'nighttemp') {
|
|
||||||
flow.set("emmaBedroom.nightTemp", payload, "diskCon")
|
|
||||||
} else if (topic === 'bedtemp') {
|
|
||||||
flow.set("emmaBedroom.bedTemp", payload, "diskCon")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastMode === 'day') {
|
|
||||||
flow.set('emmaBedroom.airconTargetTemp', flow.get('emmaBedroom.dayTemp', 'diskCon'), 'diskCon')
|
|
||||||
} else if (lastMode === 'night') {
|
|
||||||
flow.set('emmaBedroom.airconTargetTemp', flow.get('emmaBedroom.nightTemp', 'diskCon'), 'diskCon')
|
|
||||||
} else if (lastMode === 'bedtime') {
|
|
||||||
flow.set('emmaBedroom.airconTargetTemp', flow.get('emmaBedroom.bedTemp', 'diskCon'), 'diskCon')
|
|
||||||
}
|
|
||||||
|
|
||||||
node.status({fill:'green',shape:'dot',text:`Set ${topic} to ${payload}`})
|
|
@ -1,151 +0,0 @@
|
|||||||
const states = global.get('homeassistant.homeAssistant.states')
|
|
||||||
const sleeping = states['input_boolean.emma_sleeping'].state
|
|
||||||
|
|
||||||
if (sleeping !== 'on') {
|
|
||||||
node.status({fill:'red',shape:'ring',text:'Emma not sleeping, watchdog disabled'})
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const airconEntity = ['climate.emma_bedroom_aircon']
|
|
||||||
|
|
||||||
// Gather relevant attributes from the aircon entity
|
|
||||||
|
|
||||||
const airconState = msg.payload.state
|
|
||||||
const airconAttributes = msg.payload.attributes
|
|
||||||
const airconEco = airconAttributes['eco_mode']
|
|
||||||
const airconTargetTemp = airconAttributes['temperature']
|
|
||||||
const airconFanMode = airconAttributes['fan_mode']
|
|
||||||
const airconDisplay = airconAttributes['screen_display']
|
|
||||||
|
|
||||||
// Gather the last explicitly sent configuration from the context
|
|
||||||
|
|
||||||
const airconHvacCfg = flow.get('emmaBedroom.airconHvacMode', 'diskCon')
|
|
||||||
const airconEcoCfg = flow.get('emmaBedroom.airconEco', 'diskCon')
|
|
||||||
const airconTargetTempCfg = parseFloat(flow.get('emmaBedroom.airconTargetTemp', 'diskCon'))
|
|
||||||
const airconFanModeCfg = flow.get('emmaBedroom.airconFanMode', 'diskCon')
|
|
||||||
const airconDisplayCfg = flow.get('emmaBedroom.airconDisplay', 'diskCon')
|
|
||||||
|
|
||||||
// Compare the current state with the last sent configuration
|
|
||||||
|
|
||||||
let ecoMatch = {}
|
|
||||||
let displayMatch = {}
|
|
||||||
let counter = 0
|
|
||||||
|
|
||||||
let sendDisplay = {
|
|
||||||
"payload": {
|
|
||||||
"action": `switch.${airconDisplayCfg}`,
|
|
||||||
"target": {
|
|
||||||
"entity_id": ["switch.emma_bedroom_aircon_display"]
|
|
||||||
},
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendHvac = {
|
|
||||||
"payload": {
|
|
||||||
"action": "climate.set_hvac_mode",
|
|
||||||
"target": {
|
|
||||||
"entity_id": airconEntity
|
|
||||||
},
|
|
||||||
"data": {
|
|
||||||
"hvac_mode": airconHvacCfg
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendTemp = {
|
|
||||||
"payload": {
|
|
||||||
"action": "climate.set_temperature",
|
|
||||||
"target": {
|
|
||||||
"entity_id": airconEntity
|
|
||||||
},
|
|
||||||
"data": {
|
|
||||||
"temperature": airconTargetTempCfg
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendEco = {
|
|
||||||
"payload": {
|
|
||||||
"action": `switch.${airconEcoCfg}`,
|
|
||||||
"target": {
|
|
||||||
"entity_id": ["switch.emma_bedroom_aircon_eco_mode"]
|
|
||||||
},
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendAcFan = {
|
|
||||||
"payload": {
|
|
||||||
"action": "climate.set_fan_mode",
|
|
||||||
"target": {
|
|
||||||
"entity_id": airconEntity
|
|
||||||
},
|
|
||||||
"data": {
|
|
||||||
"fan_mode": airconFanModeCfg
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fix hvac mode if mismatch
|
|
||||||
|
|
||||||
if (airconState != airconHvacCfg) {
|
|
||||||
node.log(`Emma Bedroom Aircon HVAC mode mismatch: ${airconState} vs ${airconHvacCfg}`)
|
|
||||||
node.send(sendHvac)
|
|
||||||
counter += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fix eco mode if mismatch
|
|
||||||
|
|
||||||
if (airconEco === false && airconEcoCfg === 'turn_off') {
|
|
||||||
ecoMatch = true
|
|
||||||
} else if (airconEco === true && airconEcoCfg === 'turn_on') {
|
|
||||||
ecoMatch = true
|
|
||||||
} else {
|
|
||||||
ecoMatch = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ecoMatch === false) {
|
|
||||||
node.log(`Emma Bedroom Aircon Eco mode mismatch: ${airconEco} vs ${airconEcoCfg}`)
|
|
||||||
node.send(sendEco)
|
|
||||||
counter += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fix target temperature if mismatch
|
|
||||||
|
|
||||||
if (airconTargetTemp != airconTargetTempCfg) {
|
|
||||||
node.log(`Target temperature mismatch: ${airconTargetTemp} vs ${airconTargetTempCfg}`)
|
|
||||||
node.send(sendTemp)
|
|
||||||
counter += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fix fan mode if mismatch
|
|
||||||
|
|
||||||
if (airconFanMode != airconFanModeCfg) {
|
|
||||||
node.log(`Fan mode mismatch: ${airconFanMode} vs ${airconFanModeCfg}`)
|
|
||||||
node.send(sendAcFan)
|
|
||||||
counter += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fix display mode if mismatch
|
|
||||||
|
|
||||||
if (airconDisplay === false && airconDisplayCfg === 'turn_off') {
|
|
||||||
displayMatch = true
|
|
||||||
} else if (airconDisplay === true && airconDisplayCfg === 'turn_on') {
|
|
||||||
displayMatch = true
|
|
||||||
} else {
|
|
||||||
displayMatch = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (displayMatch === false) {
|
|
||||||
node.log(`Emma Bedroom Aircon Display mode mismatch: ${airconDisplay} vs ${airconDisplayCfg}`)
|
|
||||||
node.send(sendDisplay)
|
|
||||||
counter += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if (counter > 0) {
|
|
||||||
node.log(`Emma Bedroom Aircon: ${counter} configuration(s) fixed`)
|
|
||||||
node.status({fill:'yellow',shape:'dot',text:`${counter} config(s) fixed`})
|
|
||||||
} else {
|
|
||||||
node.status({fill:'green',shape:'dot',text:`No config changes`})
|
|
||||||
}
|
|
@ -8,15 +8,10 @@ const brightness = states['switch.adaptive_lighting_kallen_bedroom'].attributes.
|
|||||||
const fadeNight = states['input_number.wakeup_lights_fade_night'].state
|
const fadeNight = states['input_number.wakeup_lights_fade_night'].state
|
||||||
const hotDay = states['input_boolean.hot_day'].state
|
const hotDay = states['input_boolean.hot_day'].state
|
||||||
const heatWarning = states['binary_sensor.heat_warning'].state
|
const heatWarning = states['binary_sensor.heat_warning'].state
|
||||||
const fanState = states['fan.kallen_bedroom_fan'].state
|
|
||||||
const fanAvailable = fanState !== 'unavailable'
|
|
||||||
const fanSeparate = states['binary_sensor.kallen_fan_separate_schedule'].state
|
const fanSeparate = states['binary_sensor.kallen_fan_separate_schedule'].state
|
||||||
const schedMode = states['input_select.scheduled_climate_mode_kallen_bedroom'].state
|
const schedMode = states['input_select.scheduled_climate_mode_kallen_bedroom'].state
|
||||||
const topic = msg.topic
|
const topic = msg.topic
|
||||||
const toggle = msg.toggle || ''
|
const toggle = msg.toggle
|
||||||
|
|
||||||
const roomName = 'Kallen Bedroom'
|
|
||||||
|
|
||||||
node.log("Kallen Bedroom: Constants Set")
|
node.log("Kallen Bedroom: Constants Set")
|
||||||
|
|
||||||
let setFan = []
|
let setFan = []
|
||||||
@ -24,40 +19,27 @@ let setWhiteNoise = []
|
|||||||
let setVolume = []
|
let setVolume = []
|
||||||
let setLights = []
|
let setLights = []
|
||||||
let setWake = []
|
let setWake = []
|
||||||
node.log(`${roomName}: Variables Defined`)
|
node.log("Kallen Bedroom: Variables Defined")
|
||||||
|
|
||||||
if (schedMode === 'White Noise') {
|
if (toggle === 'off' && (hotDay === 'on' || heatWarning === 'on')) {
|
||||||
setFan = 'turn_off'
|
setFan = 'turn_on'
|
||||||
|
} else if ((toggle === 'on' || topic === 'kallen-fan') && schedMode === 'Fan') {
|
||||||
|
setFan = 'turn_on'
|
||||||
} else {
|
} else {
|
||||||
if (fanAvailable) {
|
setFan = 'turn_off'
|
||||||
if (toggle === 'off' && (hotDay === 'on' || heatWarning === 'on')) {
|
|
||||||
setFan = 'turn_on'
|
|
||||||
} else if ((toggle === 'on' || topic === 'kallen-fan') && schedMode === 'Fan') {
|
|
||||||
setFan = 'turn_on'
|
|
||||||
} else {
|
|
||||||
setFan = 'turn_off'
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (schedMode === 'Fan') {
|
|
||||||
node.log(`${roomName}: Fan is unavailable, forcing White Noise mode`)
|
|
||||||
}
|
|
||||||
setFan = 'turn_off'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((schedMode === 'White Noise' && toggle === 'on') || (schedMode === 'Fan' && !fanAvailable)) {
|
if (schedMode === 'White Noise' && toggle === 'on') {
|
||||||
setWhiteNoise = 'turn_on'
|
|
||||||
} else if (topic === 'kallen-fan' && !fanAvailable && schedMode !== 'N/A') {
|
|
||||||
setWhiteNoise = 'turn_on'
|
setWhiteNoise = 'turn_on'
|
||||||
} else {
|
} else {
|
||||||
setWhiteNoise = 'turn_off'
|
setWhiteNoise = 'turn_off'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (topic === 'boolean' && toggle === 'on') {
|
if (toggle === 'on') {
|
||||||
setVolume = parseFloat(nightVolume)
|
setVolume = parseFloat(nightVolume)
|
||||||
setLights = 'turn_on'
|
setLights = 'turn_on'
|
||||||
setWake = 'turn_off'
|
setWake = 'turn_off'
|
||||||
} else if (topic === 'boolean' && toggle === 'off') {
|
} else {
|
||||||
setVolume = parseFloat(dayVolume)
|
setVolume = parseFloat(dayVolume)
|
||||||
setWake = 'turn_on'
|
setWake = 'turn_on'
|
||||||
}
|
}
|
||||||
@ -67,11 +49,12 @@ let fadeFinal = Math.round(fadeMult)
|
|||||||
|
|
||||||
let brtFinal = Math.round(brightness)
|
let brtFinal = Math.round(brightness)
|
||||||
|
|
||||||
node.log(`${roomName}: Decision Logic Complete`)
|
node.log("Kallen Bedroom: Decision Logic Complete")
|
||||||
|
|
||||||
let sendFan = {
|
let sendFan = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": `fan.${setFan}`,
|
"domain": "fan",
|
||||||
|
"service": setFan,
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": ["fan.kallen_bedroom_fan"]
|
"entity_id": ["fan.kallen_bedroom_fan"]
|
||||||
},
|
},
|
||||||
@ -81,7 +64,8 @@ let sendFan = {
|
|||||||
|
|
||||||
let sendWhiteNoise = {
|
let sendWhiteNoise = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": `input_boolean.${setWhiteNoise}`,
|
"domain": "input_boolean",
|
||||||
|
"service": setWhiteNoise,
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": ["input_boolean.white_noise_kallen_bedroom"]
|
"entity_id": ["input_boolean.white_noise_kallen_bedroom"]
|
||||||
},
|
},
|
||||||
@ -91,7 +75,8 @@ let sendWhiteNoise = {
|
|||||||
|
|
||||||
let sendVolume = {
|
let sendVolume = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "media_player.volume_set",
|
"domain": "media_player",
|
||||||
|
"service": "volume_set",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": ["media_player.kallen_bedroom_google_speaker"]
|
"entity_id": ["media_player.kallen_bedroom_google_speaker"]
|
||||||
},
|
},
|
||||||
@ -103,7 +88,8 @@ let sendVolume = {
|
|||||||
|
|
||||||
let sendLights = {
|
let sendLights = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": `light.${setLights}`,
|
"domain": "light",
|
||||||
|
"service": setLights,
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": ["light.kallen_bedroom_lights"]
|
"entity_id": ["light.kallen_bedroom_lights"]
|
||||||
},
|
},
|
||||||
@ -113,7 +99,8 @@ let sendLights = {
|
|||||||
|
|
||||||
let sendWake = {
|
let sendWake = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": `input_boolean.${setWake}`,
|
"domain": "input_boolean",
|
||||||
|
"service": setWake,
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": ["input_boolean.kallen_awake"]
|
"entity_id": ["input_boolean.kallen_awake"]
|
||||||
},
|
},
|
||||||
@ -130,34 +117,33 @@ let sleepMsg = {
|
|||||||
"payload": "sleep"
|
"payload": "sleep"
|
||||||
}
|
}
|
||||||
|
|
||||||
node.log(`${roomName}: Message Payloads Defined`)
|
node.log("Kallen Bedroom: Message Payloads Defined")
|
||||||
|
|
||||||
node.log(`----- ${roomName}: Set Parameters -----`)
|
node.log("----- Kallen Bedroom: Set Parameters -----")
|
||||||
node.log(`${roomName}: fanAvailable: ${fanAvailable}`)
|
node.log("setFan: " + setFan)
|
||||||
node.log(`${roomName}: setFan: ${setFan}`)
|
node.log("setWhiteNoise: " + setWhiteNoise)
|
||||||
node.log(`${roomName}: setWhiteNoise: ${setWhiteNoise}`)
|
node.log("setVolume: " + setVolume)
|
||||||
node.log(`${roomName}: setVolume: ${setVolume}`)
|
node.log("setLights: " + setLights)
|
||||||
node.log(`${roomName}: setLights: ${setLights}`)
|
node.log("setWake: " + setWake)
|
||||||
node.log(`${roomName}: setWake: ${setWake}`)
|
node.log("----- Kallen Bedroom: End Parameters -----")
|
||||||
node.log(`----- ${roomName}: End Parameters -----`)
|
|
||||||
|
|
||||||
if (vacationMode === 'off' && overnight === 'off' && kallenLoc === 'home') {
|
if (vacationMode === 'off' && overnight === 'off' && kallenLoc === 'home') {
|
||||||
if (topic === 'kallen-fan' && fanSeparate === 'on') {
|
if (topic === 'kallen-fan' && fanSeparate === 'on') {
|
||||||
node.status({fill:"green",shape:"dot",text:"Fan"})
|
node.status({fill:"green",shape:"dot",text:"Fan"})
|
||||||
node.log(`${roomName}: Early Fan`)
|
node.log("Kallen Bedroom: Early Fan")
|
||||||
node.send([null,[sendFan,sendWhiteNoise],null])
|
node.send([null,[sendFan,sendWhiteNoise],null])
|
||||||
} else if (topic === 'boolean' && toggle === 'off') {
|
} else if (toggle === 'off') {
|
||||||
node.status({fill:"green",shape:"dot",text:"Wakeup"})
|
node.status({fill:"green",shape:"dot",text:"Wakeup"})
|
||||||
node.log(`${roomName}: Wake`)
|
node.log("Kallen Bedroom: Wake")
|
||||||
node.send([wakeMsg,[sendFan,sendWhiteNoise,sendVolume,sendWake],null])
|
node.send([wakeMsg,[sendFan,sendWhiteNoise,sendVolume,sendWake],null])
|
||||||
} else if (topic === 'boolean' && toggle === 'on') {
|
} else if (toggle === 'on') {
|
||||||
node.status({fill:"green",shape:"dot",text:"Sleep"})
|
node.status({fill:"green",shape:"dot",text:"Sleep"})
|
||||||
node.log(`${roomName}: Sleep`)
|
node.log("Kallen Bedroom: Sleep")
|
||||||
node.send([null,[sendFan,sendWhiteNoise,sendVolume,sendLights,sendWake],sleepMsg])
|
node.send([null,[sendFan,sendWhiteNoise,sendVolume,sendLights,sendWake],sleepMsg])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
node.status({fill:"red",shape:"ring",text:"Blocked"})
|
node.status({fill:"red",shape:"ring",text:"Blocked"})
|
||||||
node.log(`${roomName}: Flow Blocked`)
|
node.log("Kallen Bedroom: Flow Blocked")
|
||||||
}
|
}
|
||||||
|
|
||||||
node.log(`${roomName}: Processing Complete`)
|
node.log("Kallen Bedroom: Processing Complete")
|
@ -1,23 +1,21 @@
|
|||||||
const states = global.get('homeassistant.homeAssistant.states')
|
const states = global.get('homeassistant.homeAssistant.states')
|
||||||
const toggle = msg.payload
|
const toggle = msg.payload
|
||||||
const ac = global.get('masterBedroom.aircon.installed', "diskCon")
|
const ac = global.get('mb_aircon_installed', "diskCon")
|
||||||
const lastMode = flow.get("masterBedroom.lastMode", "diskCon")
|
const lastMode = flow.get("lastMode", "diskCon")
|
||||||
const bedTemp = states['input_number.master_bedroom_bedtime_temp'].state
|
const bedTemp = states['input_number.master_bedroom_bedtime_temp'].state
|
||||||
|
|
||||||
const airconEntity = ["climate.master_bedroom_aircon"]
|
|
||||||
const fanEntity = ["fan.master_bedroom_fan"]
|
|
||||||
|
|
||||||
let setTemp = bedTemp
|
let setTemp = bedTemp
|
||||||
let setEco = 'turn_off'
|
let setEco = 'none'
|
||||||
let setHvac = 'cool'
|
let setHvac = 'cool'
|
||||||
let setAcFan = 'High'
|
let setAcFan = 'High'
|
||||||
let setFan = 'turn_off'
|
let setFan = 'turn_off'
|
||||||
|
|
||||||
let sendFan = {
|
let sendFan = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": `fan.${setFan}`,
|
"domain": "fan",
|
||||||
|
"service": setFan,
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": fanEntity
|
"entity_id": ["fan.master_bedroom_fan"]
|
||||||
},
|
},
|
||||||
"data": {}
|
"data": {}
|
||||||
}
|
}
|
||||||
@ -25,9 +23,10 @@ let sendFan = {
|
|||||||
|
|
||||||
let sendHvac = {
|
let sendHvac = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "climate.set_hvac_mode",
|
"domain": "climate",
|
||||||
|
"service": "set_hvac_mode",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": airconEntity
|
"entity_id": ["climate.master_bedroom_aircon"]
|
||||||
},
|
},
|
||||||
"data": {
|
"data": {
|
||||||
"hvac_mode": setHvac
|
"hvac_mode": setHvac
|
||||||
@ -37,9 +36,10 @@ let sendHvac = {
|
|||||||
|
|
||||||
let sendTemp = {
|
let sendTemp = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "climate.set_temperature",
|
"domain": "climate",
|
||||||
|
"service": "set_temperature",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": airconEntity
|
"entity_id": ["climate.master_bedroom_aircon"]
|
||||||
},
|
},
|
||||||
"data": {
|
"data": {
|
||||||
"temperature": setTemp
|
"temperature": setTemp
|
||||||
@ -49,19 +49,23 @@ let sendTemp = {
|
|||||||
|
|
||||||
let sendEco = {
|
let sendEco = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": `switch.${setEco}`,
|
"domain": "climate",
|
||||||
|
"service": "set_preset_mode",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": ["switch.master_bedroom_aircon_eco_mode"]
|
"entity_id": ["climate.master_bedroom_aircon"]
|
||||||
},
|
},
|
||||||
"data": {}
|
"data": {
|
||||||
|
"preset_mode": setEco
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let sendAcFan = {
|
let sendAcFan = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "climate.set_fan_mode",
|
"domain": "climate",
|
||||||
|
"service": "set_fan_mode",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": airconEntity
|
"entity_id": ["climate.master_bedroom_aircon"]
|
||||||
},
|
},
|
||||||
"data": {
|
"data": {
|
||||||
"fan_mode": setAcFan
|
"fan_mode": setAcFan
|
||||||
@ -77,7 +81,7 @@ if (toggle === 'on') {
|
|||||||
node.status({fill:"red",shape:"dot",text:"DANGER MODE ACTIVE"})
|
node.status({fill:"red",shape:"dot",text:"DANGER MODE ACTIVE"})
|
||||||
node.send([null,sendFan,null])
|
node.send([null,sendFan,null])
|
||||||
if (ac === 'on') {
|
if (ac === 'on') {
|
||||||
node.send([[sendHvac,sendTemp,sendAcFan,sendEco],null,null])
|
node.send([[sendHvac,sendTemp,sendEco,sendTemp],null,null])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
node.status({fill:"green",shape:"dot",text:"Danger Mode Off"})
|
node.status({fill:"green",shape:"dot",text:"Danger Mode Off"})
|
||||||
|
@ -4,7 +4,7 @@ const acMode = msg.acmode
|
|||||||
const fanMode = msg.fanmode
|
const fanMode = msg.fanmode
|
||||||
|
|
||||||
let coolMsg = {
|
let coolMsg = {
|
||||||
"payload": `Master bedroom AC temp has been set to ${nightTemp} °F as scheduled`,
|
"payload": 'Master bedroom AC temp has been set to ' + nightTemp + '°F as scheduled',
|
||||||
"topic": 'AC Mode: Cooling'
|
"topic": 'AC Mode: Cooling'
|
||||||
}
|
}
|
||||||
let fanOnlyMsg = {
|
let fanOnlyMsg = {
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
context.set("isWakeup", false)
|
|
||||||
|
|
||||||
const states = global.get('homeassistant.homeAssistant.states')
|
|
||||||
const dayTemp = parseInt(states['input_number.master_bedroom_daytime_temp'].state)
|
|
||||||
const nightTemp = parseInt(states['input_number.master_bedroom_night_temp'].state)
|
|
||||||
const bedTemp = parseInt(states['input_number.master_bedroom_bedtime_temp'].state)
|
|
||||||
|
|
||||||
let dayMode = {
|
|
||||||
"power": "turn_on",
|
|
||||||
"temp": dayTemp,
|
|
||||||
"hvac": "cool",
|
|
||||||
"fan": "auto",
|
|
||||||
"eco": "turn_on"
|
|
||||||
}
|
|
||||||
|
|
||||||
let nightMode = {
|
|
||||||
"power": "turn_on",
|
|
||||||
"temp": nightTemp,
|
|
||||||
"hvac": "cool",
|
|
||||||
"fan": "auto",
|
|
||||||
"eco": "turn_on"
|
|
||||||
}
|
|
||||||
|
|
||||||
let bedMode = {
|
|
||||||
"power": "turn_on",
|
|
||||||
"temp": bedTemp,
|
|
||||||
"hvac": "cool",
|
|
||||||
"fan": "auto",
|
|
||||||
"eco": "turn_off"
|
|
||||||
}
|
|
||||||
|
|
||||||
let showerMode = {
|
|
||||||
"power": "turn_on",
|
|
||||||
"temp": 70,
|
|
||||||
"hvac": "dry",
|
|
||||||
"fan": "auto",
|
|
||||||
"eco": "turn_off"
|
|
||||||
}
|
|
||||||
|
|
||||||
flow.set('masterBedroom.modes.daymode', dayMode, 'diskCon')
|
|
||||||
flow.set('masterBedroom.modes.nightmode', nightMode, 'diskCon')
|
|
||||||
flow.set('masterBedroom.modes.bedmode', bedMode, 'diskCon')
|
|
||||||
flow.set('masterBedroom.modes.showermode', showerMode, 'diskCon')
|
|
@ -3,8 +3,8 @@ node.log("Master Bedroom Climate: Processing Started")
|
|||||||
|
|
||||||
const states = global.get('homeassistant.homeAssistant.states')
|
const states = global.get('homeassistant.homeAssistant.states')
|
||||||
const allowed = states['input_boolean.master_bedroom_climate_protocol'].state
|
const allowed = states['input_boolean.master_bedroom_climate_protocol'].state
|
||||||
const ac = global.get('masterBedroom.aircon.installed', "diskCon")
|
const ac = global.get('mb_aircon_installed', "diskCon")
|
||||||
const temp = global.get("outdoorTemp.tempStr")
|
const temp = global.get("tempStr")
|
||||||
const payload = msg.payload
|
const payload = msg.payload
|
||||||
const vacation = states['input_boolean.vacation_mode'].state
|
const vacation = states['input_boolean.vacation_mode'].state
|
||||||
const dayTemp = states['input_number.master_bedroom_daytime_temp'].state
|
const dayTemp = states['input_number.master_bedroom_daytime_temp'].state
|
||||||
@ -25,32 +25,16 @@ 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'
|
||||||
node.log("Master Bedroom Climate: Constants Set")
|
node.log("Master Bedroom Climate: Constants Set")
|
||||||
|
|
||||||
// Define some entity IDs
|
|
||||||
|
|
||||||
const airconEntity = ["climate.master_bedroom_aircon"]
|
|
||||||
const fanEntity = ["fan.master_bedroom_fan"]
|
|
||||||
const peopleIDs = ["input_boolean.tony_awake", "input_boolean.tina_awake"]
|
|
||||||
|
|
||||||
// Helper function to convert a string to title case
|
|
||||||
|
|
||||||
function convertToTitleCase(str) {
|
|
||||||
if (!str) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return str.toLowerCase().replace(/\b\w/g, (s) => s.toUpperCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
// init variables
|
// init variables
|
||||||
|
|
||||||
let setTemp = dayTemp
|
let setTemp = []
|
||||||
let setAcFan = 'auto'
|
let setEco = []
|
||||||
let setEco = 'auto'
|
let setHvac = []
|
||||||
let setHvac = 'cool'
|
|
||||||
let setFan = []
|
let setFan = []
|
||||||
let setCool = []
|
let setCool = []
|
||||||
let setSleep = []
|
let setSleep = []
|
||||||
let setPeople = []
|
let setPeople = []
|
||||||
let setDisplay = 'turn_on'
|
let setDisplay = []
|
||||||
let time = []
|
let time = []
|
||||||
let echoDotService = []
|
let echoDotService = []
|
||||||
let setBriefing = []
|
let setBriefing = []
|
||||||
@ -101,15 +85,15 @@ if (time === 'day') {
|
|||||||
if (ac === 'on') {
|
if (ac === 'on') {
|
||||||
if (danger === 'Extreme') {
|
if (danger === 'Extreme') {
|
||||||
setTemp = nightTemp
|
setTemp = nightTemp
|
||||||
setEco = "turn_on"
|
setEco = "eco"
|
||||||
setHvac = "cool"
|
setHvac = "cool"
|
||||||
} else if (hotDay === 'on' || heatWarning === 'on') {
|
} else if (hotDay === 'on' || heatWarning === 'on') {
|
||||||
setTemp = dayTemp
|
setTemp = dayTemp
|
||||||
setEco = "turn_on"
|
setEco = "eco"
|
||||||
setHvac = "cool"
|
setHvac = "cool"
|
||||||
} else {
|
} else {
|
||||||
setTemp = nightTemp
|
setTemp = nightTemp
|
||||||
setEco = "turn_on"
|
setEco = "eco"
|
||||||
setHvac = "off"
|
setHvac = "off"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,9 +117,9 @@ if (time === 'day') {
|
|||||||
setHvac = 'off'
|
setHvac = 'off'
|
||||||
}
|
}
|
||||||
if (hotDay === 'on') {
|
if (hotDay === 'on') {
|
||||||
setEco = 'turn_off'
|
setEco = 'none'
|
||||||
} else {
|
} else {
|
||||||
setEco = 'turn_on'
|
setEco = 'eco'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,9 +139,9 @@ if (time === 'day') {
|
|||||||
}
|
}
|
||||||
// Decide eco mode
|
// Decide eco mode
|
||||||
if (sleeping === 'on') {
|
if (sleeping === 'on') {
|
||||||
setEco = 'turn_off'
|
setEco = 'none'
|
||||||
} else {
|
} else {
|
||||||
setEco = 'turn_on'
|
setEco = 'eco'
|
||||||
}
|
}
|
||||||
// Decide HVAC mode
|
// Decide HVAC mode
|
||||||
if (acMode === 'AC') {
|
if (acMode === 'AC') {
|
||||||
@ -178,13 +162,11 @@ if (time === 'day') {
|
|||||||
setPeople = 'turn_off'
|
setPeople = 'turn_off'
|
||||||
if (ac === 'on') {
|
if (ac === 'on') {
|
||||||
setTemp = bedTemp
|
setTemp = bedTemp
|
||||||
setEco = 'turn_off'
|
setEco = 'none'
|
||||||
if (acMode === 'AC') {
|
if (acMode === 'AC') {
|
||||||
setHvac = 'cool'
|
setHvac = 'cool'
|
||||||
setDisplay = 'turn_off'
|
|
||||||
} else if (acMode === 'Fan') {
|
} else if (acMode === 'Fan') {
|
||||||
setHvac = "fan_only"
|
setHvac = "fan_only"
|
||||||
setDisplay = 'turn_off'
|
|
||||||
} else {
|
} else {
|
||||||
setHvac = "off"
|
setHvac = "off"
|
||||||
}
|
}
|
||||||
@ -201,9 +183,10 @@ node.log("Master Bedroom Climate: Decision Logic Complete")
|
|||||||
|
|
||||||
let sendFan = {
|
let sendFan = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": `fan.${setFan}`,
|
"domain": "fan",
|
||||||
|
"service": setFan,
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": fanEntity
|
"entity_id": ["fan.master_bedroom_fan"]
|
||||||
},
|
},
|
||||||
"data": {}
|
"data": {}
|
||||||
}
|
}
|
||||||
@ -211,7 +194,8 @@ let sendFan = {
|
|||||||
|
|
||||||
let sendCool = {
|
let sendCool = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": `input_boolean.${setCool}`,
|
"domain": "input_boolean",
|
||||||
|
"service": setCool,
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": ["input_boolean.master_bedroom_cooling_on"]
|
"entity_id": ["input_boolean.master_bedroom_cooling_on"]
|
||||||
},
|
},
|
||||||
@ -221,7 +205,8 @@ let sendCool = {
|
|||||||
|
|
||||||
let sendSleep = {
|
let sendSleep = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": `input_boolean.${setSleep}`,
|
"domain": "input_boolean",
|
||||||
|
"service": setSleep,
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": ["input_boolean.master_bedroom_sleeping"]
|
"entity_id": ["input_boolean.master_bedroom_sleeping"]
|
||||||
},
|
},
|
||||||
@ -231,9 +216,10 @@ let sendSleep = {
|
|||||||
|
|
||||||
let sendPeople = {
|
let sendPeople = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": `input_boolean.${setPeople}`,
|
"domain": "input_boolean",
|
||||||
|
"service": setPeople,
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": peopleIDs
|
"entity_id": ["input_boolean.tony_awake","input_boolean.tina_awake"]
|
||||||
},
|
},
|
||||||
"data": {}
|
"data": {}
|
||||||
}
|
}
|
||||||
@ -241,7 +227,8 @@ let sendPeople = {
|
|||||||
|
|
||||||
let sendDisplay = {
|
let sendDisplay = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": `switch.${setDisplay}`,
|
"domain": "switch",
|
||||||
|
"service": setDisplay,
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": ["switch.master_bedroom_aircon_display"]
|
"entity_id": ["switch.master_bedroom_aircon_display"]
|
||||||
},
|
},
|
||||||
@ -258,16 +245,18 @@ let notify = {
|
|||||||
|
|
||||||
let sendBriefing = {
|
let sendBriefing = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": `script.${setBriefing}`,
|
"domain": "script",
|
||||||
|
"service": setBriefing
|
||||||
},
|
},
|
||||||
"delay": setBriefingDelay
|
"delay": setBriefingDelay
|
||||||
}
|
}
|
||||||
|
|
||||||
let sendHvac = {
|
let sendHvac = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "climate.set_hvac_mode",
|
"domain": "climate",
|
||||||
|
"service": "set_hvac_mode",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": airconEntity
|
"entity_id": ["climate.master_bedroom_aircon"]
|
||||||
},
|
},
|
||||||
"data": {
|
"data": {
|
||||||
"hvac_mode": setHvac
|
"hvac_mode": setHvac
|
||||||
@ -277,9 +266,10 @@ let sendHvac = {
|
|||||||
|
|
||||||
let sendTemp = {
|
let sendTemp = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "climate.set_temperature",
|
"domain": "climate",
|
||||||
|
"service": "set_temperature",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": airconEntity
|
"entity_id": ["climate.master_bedroom_aircon"]
|
||||||
},
|
},
|
||||||
"data": {
|
"data": {
|
||||||
"temperature": setTemp
|
"temperature": setTemp
|
||||||
@ -289,29 +279,34 @@ let sendTemp = {
|
|||||||
|
|
||||||
let sendEco = {
|
let sendEco = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": `switch.${setEco}`,
|
"domain": "climate",
|
||||||
|
"service": "set_preset_mode",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": ["switch.master_bedroom_aircon_eco_mode"]
|
"entity_id": ["climate.master_bedroom_aircon"]
|
||||||
},
|
},
|
||||||
"data": {}
|
"data": {
|
||||||
|
"preset_mode": setEco
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let sendAcFan = {
|
let sendAcFan = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "climate.set_fan_mode",
|
"domain": "climate",
|
||||||
|
"service": "set_fan_mode",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": airconEntity
|
"entity_id": ["climate.master_bedroom_aircon"]
|
||||||
},
|
},
|
||||||
"data": {
|
"data": {
|
||||||
"fan_mode": setAcFan
|
"fan_mode": "auto"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let sendEchoDotDND = {
|
let sendEchoDotDND = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": `switch.${echoDotService}`,
|
"domain": "switch",
|
||||||
|
"service": echoDotService,
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": ["switch.basement_echo_dot_do_not_disturb_switch"]
|
"entity_id": ["switch.basement_echo_dot_do_not_disturb_switch"]
|
||||||
},
|
},
|
||||||
@ -324,20 +319,19 @@ node.log("Master Bedroom Climate: Message Payloads Defined")
|
|||||||
// Log the parameters that were chosen, for debugging purposes
|
// Log the parameters that were chosen, for debugging purposes
|
||||||
|
|
||||||
node.log("----- Master Bedroom Climate: Set Parameters -----")
|
node.log("----- Master Bedroom Climate: Set Parameters -----")
|
||||||
node.log(`setTemp: ${setTemp}`)
|
node.log("setTemp: " + setTemp)
|
||||||
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(`setCool: ${setCool}`)
|
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(`setBriefing: ${setBriefing}`)
|
node.log("setBriefingDelay: " + setBriefingDelay)
|
||||||
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}`)
|
|
||||||
node.log("----- Master Bedroom Climate: End Parameters -----")
|
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.
|
||||||
@ -356,14 +350,14 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
|||||||
} else {
|
} else {
|
||||||
if (topic === 'mrbedroom-cooling' && ac === 'on') {
|
if (topic === 'mrbedroom-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, null])
|
node.send([[sendHvac, sendTemp, sendEco, sendAcFan], 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, 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([[sendHvac, sendTemp, sendEco, sendAcFan], null, 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') {
|
||||||
@ -383,7 +377,7 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
|||||||
node.send([null, sendFan, null, null, null])
|
node.send([null, sendFan, null, 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([[sendHvac, sendTemp, sendEco, sendAcFan], null, 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') {
|
||||||
@ -401,7 +395,7 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
|||||||
node.send([null, sendFan, null, null, null])
|
node.send([null, sendFan, null, 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([[sendHvac, sendTemp, sendEco, sendAcFan], null, 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') {
|
||||||
@ -409,7 +403,7 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
|||||||
node.send([null, sendFan, null, null, null])
|
node.send([null, sendFan, null, 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([[sendHvac, sendTemp, sendEco, sendAcFan], null, 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') {
|
||||||
@ -417,7 +411,7 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
|||||||
node.send([null, sendFan, null, null, null])
|
node.send([null, sendFan, null, 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([[sendHvac, sendTemp, sendEco, sendAcFan], null, null, null, null])
|
||||||
node.log("Master Bedroom Climate: Manual/Bedtime/AC")
|
node.log("Master Bedroom Climate: Manual/Bedtime/AC")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -428,25 +422,33 @@ if (type === 'auto' && allowed === 'on' && meltdown === 'off' && vacation === 'o
|
|||||||
node.send([null, null, sendPeople, null, null])
|
node.send([null, null, sendPeople, null, null])
|
||||||
}
|
}
|
||||||
node.log("Master Bedroom Climate: Sleep")
|
node.log("Master Bedroom Climate: Sleep")
|
||||||
if (time === 'bedtime') {
|
if (time === 'night') {
|
||||||
node.status({ fill: "blue", shape: "dot", text: "Sleep" })
|
node.status({ fill: "blue", shape: "dot", text: "Wakeup (Hot Day)" })
|
||||||
node.send([null, sendFan, [sendEchoDotDND,sendPeople], null, null])
|
node.send([null, sendFan, sendEchoDotDND, null, null])
|
||||||
node.log("Master Bedroom Climate: Sleep/Bedtime")
|
node.log("Master Bedroom Climate: Sleep/Night")
|
||||||
if (ac === 'on') {
|
if (ac === 'on') {
|
||||||
node.send([[sendDisplay, sendHvac, sendTemp, sendAcFan, sendEco], null, null, null, null])
|
node.send([[sendDisplay, sendHvac, sendTemp, sendEco, sendAcFan], null, null, null])
|
||||||
node.log("Master Bedroom Climate: Sleep/Bedtime/AC")
|
node.log("Master Bedroom Climate: Sleep/Night/AC")
|
||||||
}
|
}
|
||||||
} else {
|
} else if (time === 'day') {
|
||||||
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, 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, sendEco, sendAcFan], null, null, null, null])
|
||||||
node.log(`Master Bedroom Climate: Sleep/${convertToTitleCase(time)}/AC`)
|
node.log("Master Bedroom Climate: Sleep/Day/AC")
|
||||||
}
|
}
|
||||||
if (time === 'day' && isWakeup === false) {
|
if (isWakeup === false) {
|
||||||
node.send([null, null, null, null, sendBriefing])
|
node.send([null, null, null, null, sendBriefing])
|
||||||
}
|
}
|
||||||
|
} else if (time === 'bedtime') {
|
||||||
|
node.status({ fill: "blue", shape: "dot", text: "Sleep" })
|
||||||
|
node.send([null, sendFan, [sendEchoDotDND,sendPeople], null, null])
|
||||||
|
node.log("Master Bedroom Climate: Sleep/Bedtime")
|
||||||
|
if (ac === 'on') {
|
||||||
|
node.send([[sendDisplay, sendHvac, sendTemp, sendEco, sendAcFan], null, null, null, null])
|
||||||
|
node.log("Master Bedroom Climate: Sleep/Bedtime/AC")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
context.set("isWakeup", false)
|
context.set("isWakeup", false)
|
||||||
} else if (meltdown === 'on') {
|
} else if (meltdown === 'on') {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const lastMode = flow.get('masterBedroom.lastMode', "diskCon")
|
const lastMode = flow.get('lastMode', "diskCon")
|
||||||
const linkSource = msg._linkSource
|
const linkSource = msg._linkSource
|
||||||
|
|
||||||
let setTime = []
|
let setTime = []
|
||||||
@ -27,4 +27,4 @@ let reset = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
node.send(reset)
|
node.send(reset)
|
||||||
node.status({ fill: "green", shape: "dot", text: `Mode reset to ${setTopic}`})
|
node.status({ fill: "green", shape: "dot", text: "Mode reset to " + setTopic})
|
@ -16,5 +16,5 @@ if (sleeping === 'on' || nightMode === 'on' || goodnight === 'on') {
|
|||||||
lastMode = 'day'
|
lastMode = 'day'
|
||||||
}
|
}
|
||||||
|
|
||||||
flow.set("masterBedroom.lastMode", lastMode, "diskCon")
|
flow.set("lastMode", lastMode, "diskCon")
|
||||||
node.status({ fill: "green", shape: "dot", text: `Last Mode Set: ${lastMode}`})
|
node.status({ fill: "green", shape: "dot", text: "Last Mode Set: " + lastMode})
|
@ -1,6 +1,6 @@
|
|||||||
const states = global.get('homeassistant.homeAssistant.states')
|
const states = global.get('homeassistant.homeAssistant.states')
|
||||||
const ac = global.get('masterBedroom.aircon.installed', "diskCon")
|
const ac = states['input_boolean.master_bedroom_aircon_installed'].state
|
||||||
const temp = global.get('outdoorTemp.tempStr')
|
const temp = global.get('tempStr')
|
||||||
const threshold = states['input_number.master_bedroom_aircon_run_threshold'].state
|
const threshold = states['input_number.master_bedroom_aircon_run_threshold'].state
|
||||||
const dayTemp = states['input_number.master_bedroom_daytime_temp'].state
|
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
|
||||||
@ -11,33 +11,31 @@ const sleeping = states['input_boolean.master_bedroom_sleeping'].state
|
|||||||
const hotDay = states['input_boolean.hot_day'].state
|
const hotDay = states['input_boolean.hot_day'].state
|
||||||
const topic = msg.topic
|
const topic = msg.topic
|
||||||
|
|
||||||
const airconEntity = ["climate.master_bedroom_aircon"]
|
|
||||||
|
|
||||||
let setTemp = {}
|
let setTemp = {}
|
||||||
let setEco = {}
|
let ecoMode = {}
|
||||||
let duration = {}
|
let duration = {}
|
||||||
let end = {}
|
let end = {}
|
||||||
let setHvac = {}
|
let hvac = {}
|
||||||
|
|
||||||
if (topic === 'toggle') {
|
if (topic === 'toggle') {
|
||||||
if (hotDay === 'on' || sleeping === 'on') {
|
if (hotDay === 'on' || sleeping === 'on') {
|
||||||
setTemp = bedTemp
|
setTemp = bedTemp
|
||||||
setEco = 'turn_off'
|
ecoMode = 'none'
|
||||||
} else {
|
} else {
|
||||||
setTemp = nightTemp
|
setTemp = nightTemp
|
||||||
setEco = 'turn_on'
|
ecoMode = 'eco'
|
||||||
}
|
}
|
||||||
} else if (topic === 'timer') {
|
} else if (topic === 'timer') {
|
||||||
if (currentSetTemp == bedTemp) {
|
if (currentSetTemp == bedTemp) {
|
||||||
setTemp = nightTemp
|
setTemp = nightTemp
|
||||||
if (hotDay === 'on') {
|
if (hotDay === 'on') {
|
||||||
setEco = 'turn_off'
|
ecoMode = 'none'
|
||||||
} else {
|
} else {
|
||||||
setEco = 'turn_on'
|
ecoMode = 'eco'
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setTemp = dayTemp
|
setTemp = dayTemp
|
||||||
setEco = 'turn_on'
|
ecoMode = 'eco'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,75 +50,36 @@ if (setTemp == bedTemp) {
|
|||||||
if (setTemp == dayTemp) {
|
if (setTemp == dayTemp) {
|
||||||
end = true
|
end = true
|
||||||
if (hotDay === 'off') {
|
if (hotDay === 'off') {
|
||||||
setHvac = 'off'
|
hvac = 'off'
|
||||||
} else {
|
} else {
|
||||||
setHvac = 'cool'
|
hvac = 'cool'
|
||||||
}
|
}
|
||||||
} else if (setTemp != bedTemp && coolingTime === 'on') {
|
} else if (setTemp != bedTemp && coolingTime === 'on') {
|
||||||
end = true
|
end = true
|
||||||
setHvac = 'cool'
|
hvac = 'cool'
|
||||||
} else {
|
} else {
|
||||||
end = false
|
end = false
|
||||||
setHvac = 'cool'
|
hvac = 'cool'
|
||||||
|
}
|
||||||
|
|
||||||
|
let setMsg = {
|
||||||
|
"set": setTemp,
|
||||||
|
"eco": ecoMode,
|
||||||
|
"hvac": hvac,
|
||||||
|
"end": end
|
||||||
}
|
}
|
||||||
|
|
||||||
let timerStart = {
|
let timerStart = {
|
||||||
"duration": duration
|
"duration": duration
|
||||||
}
|
}
|
||||||
|
|
||||||
let sendHvac = {
|
|
||||||
"payload": {
|
|
||||||
"action": "climate.set_hvac_mode",
|
|
||||||
"target": {
|
|
||||||
"entity_id": airconEntity
|
|
||||||
},
|
|
||||||
"data": {
|
|
||||||
"hvac_mode": setHvac
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendTemp = {
|
|
||||||
"payload": {
|
|
||||||
"action": "climate.set_temperature",
|
|
||||||
"target": {
|
|
||||||
"entity_id": airconEntity
|
|
||||||
},
|
|
||||||
"data": {
|
|
||||||
"temperature": setTemp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendEco = {
|
|
||||||
"payload": {
|
|
||||||
"action": `switch.${setEco}`,
|
|
||||||
"target": {
|
|
||||||
"entity_id": ["switch.master_bedroom_aircon_eco_mode"]
|
|
||||||
},
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendAcFan = {
|
|
||||||
"payload": {
|
|
||||||
"action": "climate.set_fan_mode",
|
|
||||||
"target": {
|
|
||||||
"entity_id": airconEntity
|
|
||||||
},
|
|
||||||
"data": {
|
|
||||||
"fan_mode": "auto"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ac === 'on' && temp >= threshold) {
|
if (ac === 'on' && temp >= threshold) {
|
||||||
if (sleeping === 'on' || coolingTime === 'on' || end === true) {
|
if (sleeping === 'on' || coolingTime === 'on' || end === true) {
|
||||||
node.status({fill:"green",shape:"dot",text:"Finished"})
|
node.status({fill:"green",shape:"dot",text:"Finished"})
|
||||||
return [[sendHvac, sendTemp, sendAcFan, sendEco], null]
|
return [setMsg, null]
|
||||||
} else {
|
} else {
|
||||||
node.status({fill:"blue",shape:"dot",text:"Next Cycle"})
|
node.status({fill:"blue",shape:"dot",text:"Next Cycle"})
|
||||||
return [[sendHvac, sendTemp, sendAcFan, sendEco], timerStart]
|
return [setMsg, timerStart]
|
||||||
}
|
}
|
||||||
} else if (ac === 'off') {
|
} else if (ac === 'off') {
|
||||||
node.status({fill:"red",shape:"ring",text:"A/C Not Installed"})
|
node.status({fill:"red",shape:"ring",text:"A/C Not Installed"})
|
||||||
|
@ -1,61 +1,22 @@
|
|||||||
const states = global.get('homeassistant.homeAssistant.states')
|
const states = global.get('homeassistant.homeAssistant.states')
|
||||||
const ac = global.get('masterBedroom.aircon.installed', "diskCon")
|
const ac = states['input_boolean.master_bedroom_aircon_installed'].state
|
||||||
const temp = global.get('outdoorTemp.tempStr')
|
const temp = global.get('tempStr')
|
||||||
const threshold = states['input_number.master_bedroom_aircon_run_threshold'].state
|
const threshold = states['input_number.master_bedroom_aircon_run_threshold'].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 sleeping = states['input_boolean.master_bedroom_sleeping'].state
|
const sleeping = states['input_boolean.master_bedroom_sleeping'].state
|
||||||
|
|
||||||
const airconEntity = ["climate.master_bedroom_aircon"]
|
|
||||||
|
|
||||||
let setTemp = []
|
|
||||||
let setHvac = "dry"
|
|
||||||
let setEco = "turn_off"
|
|
||||||
|
|
||||||
if (sleeping === 'on') {
|
|
||||||
setTemp = bedTemp
|
|
||||||
} else {
|
|
||||||
setTemp = nightTemp
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendHvac = {
|
|
||||||
"payload": {
|
|
||||||
"action": "climate.set_hvac_mode",
|
|
||||||
"target": {
|
|
||||||
"entity_id": airconEntity
|
|
||||||
},
|
|
||||||
"data": {
|
|
||||||
"hvac_mode": setHvac
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendTemp = {
|
|
||||||
"payload": {
|
|
||||||
"action": "climate.set_temperature",
|
|
||||||
"target": {
|
|
||||||
"entity_id": airconEntity
|
|
||||||
},
|
|
||||||
"data": {
|
|
||||||
"temperature": setTemp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendEco = {
|
|
||||||
"payload": {
|
|
||||||
"action": `switch.${setEco}`,
|
|
||||||
"target": {
|
|
||||||
"entity_id": ["switch.master_bedroom_aircon_eco_mode"]
|
|
||||||
},
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ac === 'on') {
|
if (ac === 'on') {
|
||||||
if (temp >= threshold) {
|
if (temp >= threshold) {
|
||||||
node.status({fill:"green",shape:"dot",text:`Shower Mode On: ${setTemp}°F`})
|
if (sleeping === 'on') {
|
||||||
node.send([[sendHvac, sendTemp, sendEco]])
|
msg.set = bedTemp
|
||||||
|
node.status({fill:"green",shape:"dot",text:"Shower Mode On: " + bedTemp})
|
||||||
|
return msg
|
||||||
|
} else {
|
||||||
|
msg.set = nightTemp
|
||||||
|
node.status({fill:"green",shape:"dot",text:"Shower Mode On: " + nightTemp})
|
||||||
|
return msg
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
node.status({fill:"red",shape:"ring",text:"Too Cold"})
|
node.status({fill:"red",shape:"ring",text:"Too Cold"})
|
||||||
return null
|
return null
|
||||||
|
@ -7,22 +7,17 @@ const payload = msg.payload
|
|||||||
const newDuration = duration * 60
|
const newDuration = duration * 60
|
||||||
|
|
||||||
if (payload === 'on') {
|
if (payload === 'on') {
|
||||||
if (lux <= threshold && lights === 'off') {
|
if (lux <= threshold || lights === 'on') {
|
||||||
node.status({fill:'green',shape:'dot',text:'Turning lights on'})
|
node.status({fill:'green',shape:'dot',text:'Lights On'})
|
||||||
node.send([msg,msg,null])
|
node.send([msg,null])
|
||||||
} else {
|
} else {
|
||||||
if (lights === 'on') {
|
node.status({fill:'red',shape:'ring',text:'Too bright'})
|
||||||
node.status({fill:'red',shape:'ring',text:'Lights already on'})
|
|
||||||
node.send([null,msg,null])
|
|
||||||
} else {
|
|
||||||
node.status({fill:'red',shape:'ring',text:'Too bright'})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (payload === 'off') {
|
} else if (payload === 'off') {
|
||||||
if (lights === 'on') {
|
if (lights === 'on') {
|
||||||
msg.duration = newDuration
|
msg.duration = newDuration
|
||||||
node.status({fill:"green",shape:"dot",text:parseInt(duration) + ' minutes'})
|
node.status({fill:"green",shape:"dot",text:parseInt(duration) + ' minutes'})
|
||||||
node.send([null,null,msg])
|
node.send([null,msg])
|
||||||
} else {
|
} else {
|
||||||
node.status({fill:"red",shape:"ring",text:"Lights already off"})
|
node.status({fill:"red",shape:"ring",text:"Lights already off"})
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
const states = global.get('homeassistant.homeAssistant.states')
|
const states = global.get('homeassistant.homeAssistant.states')
|
||||||
const lights = states['light.mud_room_overhead'].state
|
const lights = states['light.mud_room_overhead'].state
|
||||||
const selScene = states['input_text.mud_room_selected_scene'].state
|
|
||||||
const duration = states['input_number.mud_room_lights_off_delay'].state
|
const duration = states['input_number.mud_room_lights_off_delay'].state
|
||||||
const lux = parseInt(states['sensor.mud_room_illuminance'].state)
|
const lux = parseInt(states['sensor.mud_room_illuminance'].state)
|
||||||
const threshold = parseInt(states['input_number.mud_room_lux_threshold'].state)
|
const threshold = parseInt(states['input_number.mud_room_lux_threshold'].state)
|
||||||
@ -8,22 +7,17 @@ const payload = msg.payload
|
|||||||
const newDuration = duration * 60
|
const newDuration = duration * 60
|
||||||
|
|
||||||
if (payload === 'on') {
|
if (payload === 'on') {
|
||||||
if (lux <= threshold && (lights === 'off' || selScene === 'Nightlight')) {
|
if (lux <= threshold || lights === 'on') {
|
||||||
node.status({fill:'green',shape:'dot',text:'Turning lights on'})
|
node.status({fill:'green',shape:'dot',text:'Lights On'})
|
||||||
node.send([msg,msg,null])
|
node.send([msg,null])
|
||||||
} else {
|
} else {
|
||||||
if (lights === 'on') {
|
node.status({fill:'red',shape:'ring',text:'Too bright'})
|
||||||
node.status({fill:'red',shape:'ring',text:'Lights already on'})
|
|
||||||
node.send([null,msg,null])
|
|
||||||
} else {
|
|
||||||
node.status({fill:'red',shape:'ring',text:'Too bright'})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (payload === 'off') {
|
} else if (payload === 'off') {
|
||||||
if (lights === 'on') {
|
if (lights === 'on') {
|
||||||
msg.duration = newDuration
|
msg.duration = newDuration
|
||||||
node.status({fill:"green",shape:"dot",text:parseInt(duration) + ' minutes'})
|
node.status({fill:"green",shape:"dot",text:parseInt(duration) + ' minutes'})
|
||||||
node.send([null,null,msg])
|
node.send([null,msg])
|
||||||
} else {
|
} else {
|
||||||
node.status({fill:"red",shape:"ring",text:"Lights already off"})
|
node.status({fill:"red",shape:"ring",text:"Lights already off"})
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
const states = global.get('homeassistant.homeAssistant.states')
|
const states = global.get('homeassistant.homeAssistant.states')
|
||||||
const outdoorLux = parseInt(states['sensor.home_tempest_illuminance'].state)
|
const earlyNightMode = states['binary_sensor.early_night_mode'].state
|
||||||
const threshold = parseInt(states['input_number.front_porch_lux_threshold'].state)
|
|
||||||
const frontPorchToggle = states['input_boolean.front_porch_light_on'].state
|
const frontPorchToggle = states['input_boolean.front_porch_light_on'].state
|
||||||
const holidaymode = states['input_boolean.holiday_mode'].state
|
const holidaymode = states['input_boolean.holiday_mode'].state
|
||||||
const currentholiday = states['input_select.holiday_animation'].state
|
const currentholiday = states['input_select.holiday_animation'].state
|
||||||
@ -10,7 +9,7 @@ let holidayMsg = {
|
|||||||
"holiday": holiday
|
"holiday": holiday
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((outdoorLux <= threshold) && frontPorchToggle === 'on') {
|
if (earlyNightMode === 'on' && frontPorchToggle === 'on') {
|
||||||
if (holidaymode === 'on') {
|
if (holidaymode === 'on') {
|
||||||
node.status({fill:"blue",shape:"dot",text:"Holiday On"})
|
node.status({fill:"blue",shape:"dot",text:"Holiday On"})
|
||||||
node.send([holidayMsg,msg])
|
node.send([holidayMsg,msg])
|
||||||
@ -21,7 +20,7 @@ if ((outdoorLux <= threshold) && frontPorchToggle === 'on') {
|
|||||||
} else {
|
} else {
|
||||||
if (frontPorchToggle === 'off') {
|
if (frontPorchToggle === 'off') {
|
||||||
node.status({ fill: "red", shape: "ring", text: "Disabled" })
|
node.status({ fill: "red", shape: "ring", text: "Disabled" })
|
||||||
} else if (outdoorLux > threshold) {
|
} else if (earlyNightMode === 'off') {
|
||||||
node.status({ fill: "red", shape: "ring", text: "Daytime" })
|
node.status({ fill: "red", shape: "ring", text: "Daytime" })
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,30 +0,0 @@
|
|||||||
const states = global.get('homeassistant.homeAssistant.states')
|
|
||||||
const schoolToday = states['input_boolean.kallen_school_today'].state
|
|
||||||
const kallen = states['person.kallen_stork'].state
|
|
||||||
const morning = states['binary_sensor.morning'].state
|
|
||||||
|
|
||||||
let basement = {
|
|
||||||
"payload": {
|
|
||||||
"action": "script.goodnight_in_basement"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let firstFloor = {
|
|
||||||
"payload": {
|
|
||||||
"action": "script.goodnight_on_first_floor"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let secondFloor = {
|
|
||||||
"payload": {
|
|
||||||
"action": "script.goodnight_on_second_floor"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (schoolToday === 'on' && kallen === 'home' && morning === 'on') {
|
|
||||||
node.send([[basement,secondFloor]])
|
|
||||||
node.status({fill:'yellow',shape:'dot',text:'Kallen waiting for school bus'})
|
|
||||||
} else {
|
|
||||||
node.send([[basement,firstFloor,secondFloor]])
|
|
||||||
node.status({fill:'green',shape:'dot',text:'All scripts sent'})
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
const states = global.get('homeassistant.homeAssistant.states')
|
|
||||||
const schoolToday = states['input_boolean.kallen_school_today'].state
|
|
||||||
const kallen = states['person.kallen_stork'].state
|
|
||||||
const morning = states['binary_sensor.morning'].state
|
|
||||||
const masterBedroomSleeping = states['input_boolean.master_bedroom_sleeping'].state
|
|
||||||
const payload = msg.payload
|
|
||||||
|
|
||||||
let presence = {}
|
|
||||||
|
|
||||||
if (payload === 'home') {
|
|
||||||
presence = 'on'
|
|
||||||
} else if (payload != 'unavailable' && payload != 'unknown') {
|
|
||||||
presence = 'off'
|
|
||||||
}
|
|
||||||
|
|
||||||
if (schoolToday === 'on' && kallen != 'home' && morning === 'on') {
|
|
||||||
if (presence === 'off' && masterBedroomSleeping === 'on') {
|
|
||||||
node.send(msg)
|
|
||||||
node.status({fill:'green',shape:'dot',text:'Kallen left, first floor lights off'})
|
|
||||||
} else {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return null
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
const statusCode = msg.statusCode
|
|
||||||
const issueNumber = msg.payload.number
|
|
||||||
const issueTitle = msg.payload.title
|
|
||||||
const url = msg.payload.html_url
|
|
||||||
const user = msg.user
|
|
||||||
|
|
||||||
let notification = {
|
|
||||||
"title": "Issue Submitted",
|
|
||||||
"message": `${user.firstName} ${user.lastName} submitted a new issue: #${issueNumber} - ${issueTitle}`,
|
|
||||||
"actions": [
|
|
||||||
{
|
|
||||||
"action": "URI",
|
|
||||||
"uri": url,
|
|
||||||
"title": "View Issue"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
node.send(notification)
|
|
||||||
node.status({fill:'green',shape:'dot',text:`Issue #${issueNumber} notification sent`})
|
|
@ -1,33 +0,0 @@
|
|||||||
const needsReponseLabel = flow.get("needsReponseLabel", "diskCon")
|
|
||||||
const typeBugLabel = flow.get("typeBugLabel", "diskCon")
|
|
||||||
const typeEnhancementLabel = flow.get("typeEnhancementLabel", "diskCon")
|
|
||||||
const typeAdjustmentLabel = flow.get("typeAdjustmentLabel", "diskCon")
|
|
||||||
const title = msg.text
|
|
||||||
const type = msg.type
|
|
||||||
const user = msg.user
|
|
||||||
|
|
||||||
let labels = [needsReponseLabel]
|
|
||||||
let formatType = {}
|
|
||||||
|
|
||||||
if (type === 'Bug Report') {
|
|
||||||
labels.push(typeBugLabel)
|
|
||||||
formatType = "[Bug]"
|
|
||||||
} else if (type === 'New Idea') {
|
|
||||||
labels.push(typeEnhancementLabel)
|
|
||||||
formatType = "[Feature Request]"
|
|
||||||
} else if (type === 'Adjustment') {
|
|
||||||
labels.push(typeAdjustmentLabel)
|
|
||||||
formatType = "[Adjustment Request]"
|
|
||||||
}
|
|
||||||
|
|
||||||
let newTitle = `${formatType}: ${title}`
|
|
||||||
|
|
||||||
msg.payload = {
|
|
||||||
"title": newTitle,
|
|
||||||
"body": `This issue was submitted by ${user.firstName} ${user.lastName}, using the automated form on the main Home Assistant dashboard`,
|
|
||||||
"assignees":["tm24fan8"],
|
|
||||||
"labels": labels
|
|
||||||
}
|
|
||||||
|
|
||||||
node.status({fill:'green',shape:'dot',text:'API data prepped'})
|
|
||||||
return msg
|
|
@ -1,21 +0,0 @@
|
|||||||
const states = global.get('homeassistant.homeAssistant.states')
|
|
||||||
const text = states['input_text.report_system'].state
|
|
||||||
const type = states['input_select.report_type'].state
|
|
||||||
const resetText = 'Type your report here'
|
|
||||||
const resetType = 'Bug Report'
|
|
||||||
|
|
||||||
msg.text = text
|
|
||||||
msg.type = type
|
|
||||||
|
|
||||||
msg.reset_text = resetText
|
|
||||||
msg.reset_type = resetType
|
|
||||||
|
|
||||||
if (type === "New Idea") {
|
|
||||||
node.status({fill:"green",shape:"dot",text:"New Idea"})
|
|
||||||
} else if (type === "Bug Report") {
|
|
||||||
node.status({fill:"green",shape:"dot",text:"Bug Report"})
|
|
||||||
} else if (type === "Adjustment") {
|
|
||||||
node.status({fill:"green",shape:"dot",text:"Adjustment"})
|
|
||||||
}
|
|
||||||
|
|
||||||
return msg
|
|
@ -1,9 +0,0 @@
|
|||||||
const needsReponseLabel = 213
|
|
||||||
const typeBugLabel = 196
|
|
||||||
const typeEnhancementLabel = 198
|
|
||||||
const typeAdjustmentLabel = 208
|
|
||||||
|
|
||||||
flow.set("needsReponseLabel", needsReponseLabel, "diskCon")
|
|
||||||
flow.set("typeBugLabel", typeBugLabel, "diskCon")
|
|
||||||
flow.set("typeEnhancementLabel", typeEnhancementLabel, "diskCon")
|
|
||||||
flow.set("typeAdjustmentLabel", typeAdjustmentLabel, "diskCon")
|
|
@ -6,7 +6,7 @@ if (msg.lights === 'on') {
|
|||||||
node.status({fill:"green",shape:"dot",text:"Lights Controlled"})
|
node.status({fill:"green",shape:"dot",text:"Lights Controlled"})
|
||||||
return[null,msg]
|
return[null,msg]
|
||||||
} else {
|
} else {
|
||||||
node.status({fill:"red",shape:"ring",text:`N/A in ${msg.room}`})
|
node.status({fill:"red",shape:"ring",text:"N/A in " + msg.room})
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -68,7 +68,8 @@ if (payload === 'start') {
|
|||||||
// Prepare message payloads
|
// Prepare message payloads
|
||||||
let sendTimerStart = {
|
let sendTimerStart = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "timer.start",
|
"domain": "timer",
|
||||||
|
"service": "start",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": timerEntity
|
"entity_id": timerEntity
|
||||||
},
|
},
|
||||||
@ -80,7 +81,8 @@ let sendTimerStart = {
|
|||||||
|
|
||||||
let sendTimerCancel = {
|
let sendTimerCancel = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "timer.cancel",
|
"domain": "timer",
|
||||||
|
"service": "cancel",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": timerEntity
|
"entity_id": timerEntity
|
||||||
},
|
},
|
||||||
@ -90,7 +92,8 @@ let sendTimerCancel = {
|
|||||||
|
|
||||||
let sendBoolFinished = {
|
let sendBoolFinished = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "input_boolean." + servFinished,
|
"domain": "input_boolean",
|
||||||
|
"service": servFinished,
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": boolFinished
|
"entity_id": boolFinished
|
||||||
},
|
},
|
||||||
@ -100,7 +103,8 @@ let sendBoolFinished = {
|
|||||||
|
|
||||||
let sendDateTimeFinished = {
|
let sendDateTimeFinished = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "input_datetime.set_datetime",
|
"domain": "input_datetime",
|
||||||
|
"service": "set_datetime",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": dateTimeEntity
|
"entity_id": dateTimeEntity
|
||||||
},
|
},
|
||||||
|
@ -10,6 +10,13 @@ const segLivingRoom2 = [10,11,12,13,14,15,16,17,18,19]
|
|||||||
const segLivingRoom3 = [20,21,22,23,24,25,26,27,28,29]
|
const segLivingRoom3 = [20,21,22,23,24,25,26,27,28,29]
|
||||||
const segLivingRoom4 = [30,31,32,33,34,35,36,37,38,39]
|
const segLivingRoom4 = [30,31,32,33,34,35,36,37,38,39]
|
||||||
|
|
||||||
|
// Preset effect segments for living room LED strip
|
||||||
|
const effectSegLivingRoom1 = [].concat(segLivingRoom1, segLivingRoom3)
|
||||||
|
const effectSegLivingRoom2 = [].concat(segLivingRoom2, segLivingRoom4)
|
||||||
|
|
||||||
|
// Full strip for living room LED strip
|
||||||
|
const livingRoomFull = [].concat(halfLivingRoom1, halfLivingRoom2)
|
||||||
|
|
||||||
// Half and half for basement LED strip
|
// Half and half for basement LED strip
|
||||||
const halfBasement1 = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
|
const halfBasement1 = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
|
||||||
const halfBasement2 = [16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]
|
const halfBasement2 = [16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]
|
||||||
@ -20,18 +27,65 @@ const segBasement2 = [8,9,10,11,12,13,14,15]
|
|||||||
const segBasement3 = [16,17,18,19,20,21,22,23]
|
const segBasement3 = [16,17,18,19,20,21,22,23]
|
||||||
const segBasement4 = [24,25,26,27,28,29,30,31]
|
const segBasement4 = [24,25,26,27,28,29,30,31]
|
||||||
|
|
||||||
|
// Preset effect segments for basement LED strip
|
||||||
|
const effectSegBasement1 = [].concat(segBasement1, segBasement3)
|
||||||
|
const effectSegBasement2 = [].concat(segBasement2, segBasement4)
|
||||||
|
|
||||||
|
// Full strip for basement LED strip
|
||||||
|
const basementFull = [].concat(halfBasement1, halfBasement2)
|
||||||
|
|
||||||
|
// Adaptive Lighting switches
|
||||||
|
const adaptiveFirstFloor = [
|
||||||
|
"switch.adaptive_lighting_living_room",
|
||||||
|
"switch.adaptive_lighting_dining_room_lamp",
|
||||||
|
"switch.adaptive_lighting_tina_lamp"]
|
||||||
|
|
||||||
|
const adaptiveBasement = [
|
||||||
|
"switch.adaptive_lighting_basement_studio"
|
||||||
|
]
|
||||||
|
|
||||||
|
// Define light arrays for backup scenes
|
||||||
|
const lightsTinaDesk = ['light.tina_desk_strip','light.tina_lamp_top','light.tina_lamp_side']
|
||||||
|
const lightsBasement = ['light.basement_tall_lamp','light.basement_short_lamp','light.basement_stairwell','light.basement_led_strip_1']
|
||||||
|
const lightsLivingRoom = ['light.living_room_color_1','light.living_room_color_2','light.living_room_color_3','light.living_room_led_strip']
|
||||||
|
const lightsDiningRoom = ['light.dining_room_lamp']
|
||||||
|
const lightsStairwell = ['light.stairwell_led_strip']
|
||||||
|
|
||||||
|
// Write flow variables
|
||||||
flow.set("halfLivingRoom1", halfLivingRoom1, "diskCon")
|
flow.set("halfLivingRoom1", halfLivingRoom1, "diskCon")
|
||||||
flow.set("halfLivingRoom2", halfLivingRoom1, "diskCon")
|
flow.set("halfLivingRoom2", halfLivingRoom2, "diskCon")
|
||||||
|
|
||||||
flow.set("segLivingRoom1", segLivingRoom1, "diskCon")
|
flow.set("segLivingRoom1", segLivingRoom1, "diskCon")
|
||||||
flow.set("segLivingRoom2", segLivingRoom2, "diskCon")
|
flow.set("segLivingRoom2", segLivingRoom2, "diskCon")
|
||||||
flow.set("segLivingRoom3", segLivingRoom3, "diskCon")
|
flow.set("segLivingRoom3", segLivingRoom3, "diskCon")
|
||||||
flow.set("segLivingRoom4", segLivingRoom4, "diskCon")
|
flow.set("segLivingRoom4", segLivingRoom4, "diskCon")
|
||||||
|
|
||||||
|
flow.set("effectSegLivingRoom1", effectSegLivingRoom1, "diskCon")
|
||||||
|
flow.set("effectSegLivingRoom2", effectSegLivingRoom2, "diskCon")
|
||||||
|
|
||||||
|
flow.set("livingRoomFull", livingRoomFull, "diskCon")
|
||||||
|
|
||||||
flow.set("halfBasement1", halfBasement1, "diskCon")
|
flow.set("halfBasement1", halfBasement1, "diskCon")
|
||||||
flow.set("halfBasement2", halfBasement1, "diskCon")
|
flow.set("halfBasement2", halfBasement2, "diskCon")
|
||||||
|
|
||||||
flow.set("segBasement1", segBasement1, "diskCon")
|
flow.set("segBasement1", segBasement1, "diskCon")
|
||||||
flow.set("segBasement2", segBasement2, "diskCon")
|
flow.set("segBasement2", segBasement2, "diskCon")
|
||||||
flow.set("segBasement3", segBasement3, "diskCon")
|
flow.set("segBasement3", segBasement3, "diskCon")
|
||||||
flow.set("segBasement4", segBasement4, "diskCon")
|
flow.set("segBasement4", segBasement4, "diskCon")
|
||||||
|
|
||||||
|
flow.set("effectSegBasement1", effectSegBasement1, "diskCon")
|
||||||
|
flow.set("effectSegBasement2", effectSegBasement2, "diskCon")
|
||||||
|
|
||||||
|
flow.set("basementFull", basementFull, "diskCon")
|
||||||
|
|
||||||
|
flow.set("adaptiveFirstFloor", adaptiveFirstFloor, "diskCon")
|
||||||
|
flow.set("adaptiveBasement", adaptiveBasement, "diskCon")
|
||||||
|
|
||||||
|
flow.set('lightsTinaDesk', lightsTinaDesk, 'diskCon')
|
||||||
|
flow.set('lightsBasement', lightsBasement, 'diskCon')
|
||||||
|
flow.set('lightsLivingRoom', lightsLivingRoom, 'diskCon')
|
||||||
|
flow.set('lightsDiningRoom', lightsDiningRoom, 'diskCon')
|
||||||
|
flow.set('lightsStairwell', lightsStairwell, 'diskCon')
|
||||||
|
|
||||||
|
flow.set('alertFirstFloor', false)
|
||||||
|
flow.set('alertBasement', false)
|
@ -1,36 +1,368 @@
|
|||||||
|
// Set constants
|
||||||
const states = global.get('homeassistant.homeAssistant.states')
|
const states = global.get('homeassistant.homeAssistant.states')
|
||||||
const occupied = states["binary_sensor.basement_occupied"].state
|
const occupied = states["binary_sensor.basement_occupied"].state
|
||||||
const quiet = states["input_boolean.studio_quiet"].state
|
const quiet = states["input_boolean.studio_quiet"].state
|
||||||
const deskState = states["light.tina_desk_lights"].state
|
const stateTinaDesk = states["light.tina_desk_lights"].state
|
||||||
const livingRoomState = states["light.living_room_lights"].state
|
const stateLivingRoom = states["light.living_room_lights"].state
|
||||||
const diningRoomState = states["light.dining_room_lamp"].state
|
const stateDiningRoom = states["light.dining_room_lamp"].state
|
||||||
const basementState = states["light.basement_studio_lights"].state
|
const stateStairwell = states["light.stairwell_led_strip"].state
|
||||||
const where = msg.payload.event.where
|
const stateBasement = states["light.basement_studio_lights"].state
|
||||||
const type = msg.payload.event.type
|
const adaptLivingRoom = states["switch.adaptive_lighting_living_room"].state
|
||||||
|
const adaptDiningRoom = states["switch.adaptive_lighting_dining_room_lamp"].state
|
||||||
|
const adaptBasement = states["switch.adaptive_lighting_basement_studio"].state
|
||||||
|
const nightLivingRoom = states["switch.adaptive_lighting_sleep_mode_living_room"].state
|
||||||
|
const nightDiningRoom = states["switch.adaptive_lighting_sleep_mode_dining_room_lamp"].state
|
||||||
|
const nightBasement = states["switch.adaptive_lighting_sleep_mode_basement_studio"].state
|
||||||
|
const currentSceneBasement = states["input_text.basement_studio_selected_scene"].state
|
||||||
|
const currentSceneLivingRoom = states["input_text.living_room_selected_scene"].state
|
||||||
|
const currentSceneTinaDesk = states["input_text.tina_desk_selected_scene"].state
|
||||||
|
const currentSceneDiningRoom = states["input_text.dining_room_lamp_selected_scene"].state
|
||||||
|
const effectBasement = msg.payload.event.basement
|
||||||
|
const effectFirstFloor = msg.payload.event.first_floor
|
||||||
|
const effectColor = msg.payload.event.color
|
||||||
|
const effectDivide = msg.payload.event.divide
|
||||||
const duration = msg.payload.event.duration
|
const duration = msg.payload.event.duration
|
||||||
|
const delay = duration * 1000
|
||||||
|
const adaptiveSwitchFirstFloor = flow.get("adaptiveFirstFloor", "diskCon")
|
||||||
|
const adaptiveSwitchBasement = flow.get("adaptiveBasement", "diskCon")
|
||||||
|
const lightsTinaDesk = flow.get('lightsTinaDesk', 'diskCon')
|
||||||
|
const lightsBasement = flow.get('lightsBasement', 'diskCon')
|
||||||
|
const lightsLivingRoom = flow.get('lightsLivingRoom', 'diskCon')
|
||||||
|
const lightsDiningRoom = flow.get('lightsDiningRoom', 'diskCon')
|
||||||
|
const alertFirstFloor = flow.get('alertFirstFloor')
|
||||||
|
const alertBasement = flow.get('alertBasement')
|
||||||
|
|
||||||
let firstFloorLights = []
|
// Set flow contexts to be used later in the reset node
|
||||||
let basementLights = []
|
flow.set("currentSceneBasement", currentSceneBasement)
|
||||||
|
flow.set("currentSceneLivingRoom", currentSceneLivingRoom)
|
||||||
|
flow.set("currentSceneTinaDesk", currentSceneTinaDesk)
|
||||||
|
flow.set('currentSceneDiningRoom', currentSceneDiningRoom)
|
||||||
|
flow.set("adaptLivingRoom", adaptLivingRoom)
|
||||||
|
flow.set("adaptBasement", adaptBasement)
|
||||||
|
flow.set("nightLivingRoom", nightLivingRoom)
|
||||||
|
flow.set("nightBasement", nightBasement)
|
||||||
|
flow.set('nightDiningRoom', nightDiningRoom)
|
||||||
|
flow.set("stateTinaDesk", stateTinaDesk)
|
||||||
|
flow.set("stateLivingRoom", stateLivingRoom)
|
||||||
|
flow.set("stateDiningRoom", stateDiningRoom)
|
||||||
|
flow.set("stateStairwell", stateStairwell)
|
||||||
|
flow.set("stateBasement", stateBasement)
|
||||||
|
|
||||||
if (deskState === 'on') {
|
// Define empty arrays for basement LED strip zones
|
||||||
firstFloorLights.push('light.tina_desk_strip','light.tina_lamp_top','light.tina_lamp_side')
|
let basement1 = []
|
||||||
|
let basement2 = []
|
||||||
|
let basementFull = []
|
||||||
|
// Define empty arrays for living room LED strip zones
|
||||||
|
let livingRoom1 = []
|
||||||
|
let livingRoom2 = []
|
||||||
|
let livingRoomFull = []
|
||||||
|
// Color names are set by default, however certain effects can override them below
|
||||||
|
let colorName1 = effectColor
|
||||||
|
let colorName2 = "white"
|
||||||
|
// Define empty object for LIFX effect settings
|
||||||
|
let lifxData = {}
|
||||||
|
let effectLifx = msg.payload.event.lifx
|
||||||
|
|
||||||
|
// Setup the proper zones to use for the effect
|
||||||
|
if (effectDivide === 'half') {
|
||||||
|
basement1 = flow.get("halfBasement1", "diskCon")
|
||||||
|
basement2 = flow.get("halfBasement2", "diskCon")
|
||||||
|
livingRoom1 = flow.get("halfLivingRoom1", "diskCon")
|
||||||
|
livingRoom2 = flow.get("halfLivingRoom2", "diskCon")
|
||||||
|
} else if (effectDivide === 'quarter') {
|
||||||
|
basement1 = flow.get("effectSegBasement1", "diskCon")
|
||||||
|
basement2 = flow.get("effectSegBasement2", "diskCon")
|
||||||
|
livingRoom1 = flow.get("effectSegLivingRoom1", "diskCon")
|
||||||
|
livingRoom2 = flow.get("effectSegLivingRoom2", "diskCon")
|
||||||
|
} else if (effectDivide === 'full') {
|
||||||
|
basementFull = flow.get("basementFull", "diskCon")
|
||||||
|
livingRoomFull = flow.get("livingRoomFull", "diskCon")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (livingRoomState === 'on') {
|
if (effectFirstFloor === true) {
|
||||||
firstFloorLights.push('light.living_room_color_1','light.living_room_color_2','light.living_room_color_3','light.living_room_led_strip')
|
flow.set('alertFirstFloor', true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (diningRoomState === 'on') {
|
if (effectBasement === true) {
|
||||||
firstFloorLights.push('light.dining_room_lamp')
|
flow.set('alertBasement', true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (basementState === 'on') {
|
// Set/change colors if necessary
|
||||||
basementLights.push('light.basement_tall_lamp','light.basement_short_lamp','light.basement_stairwell','light.basement_led_strip_1')
|
if (effectColor === 'police') {
|
||||||
|
colorName1 = 'red'
|
||||||
|
colorName2 = 'blue'
|
||||||
}
|
}
|
||||||
|
|
||||||
flow.set("deskState", deskState)
|
// Define parameters for different LIFX effects
|
||||||
flow.set("livingRoomState", livingRoomState)
|
if (effectLifx === 'move') {
|
||||||
flow.set("diningRoomState", diningRoomState)
|
lifxData = {
|
||||||
flow.set("basementState", basementState)
|
"speed": 0.5,
|
||||||
|
"direction": "right",
|
||||||
|
"power_on": false
|
||||||
|
}
|
||||||
|
} else if (effectLifx === 'ping') {
|
||||||
|
effectLifx = 'pulse'
|
||||||
|
colorName2 = colorName1
|
||||||
|
lifxData = {
|
||||||
|
"power_on": false,
|
||||||
|
"mode": "ping",
|
||||||
|
"period": 1,
|
||||||
|
"cycles": duration,
|
||||||
|
"color_name": "white",
|
||||||
|
"brightness": 255
|
||||||
|
}
|
||||||
|
} else if (effectLifx === 'blink') {
|
||||||
|
effectLifx = 'pulse'
|
||||||
|
colorName2 = colorName1
|
||||||
|
lifxData = {
|
||||||
|
"power_on": false,
|
||||||
|
"mode": "blink",
|
||||||
|
"period": 0.5,
|
||||||
|
"cycles": duration * 2,
|
||||||
|
"color_name": "white",
|
||||||
|
"brightness": 255
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// let segLivingRoom = [].concat(segLivingRoom1, segLivingRoom2)
|
// Define messages
|
||||||
|
let sendBasementStripFX = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "lifx",
|
||||||
|
"service": "effect_" + effectLifx,
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["light.basement_led_strip_1"]
|
||||||
|
},
|
||||||
|
"data": lifxData
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendBasementStrip1 = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "lifx",
|
||||||
|
"service": "set_state",
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["light.basement_led_strip_1"]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"zones": basement1,
|
||||||
|
"color_name": colorName1,
|
||||||
|
"brightness": 255
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendBasementStrip2 = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "lifx",
|
||||||
|
"service": "set_state",
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["light.basement_led_strip_1"]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"zones": basement2,
|
||||||
|
"color_name": colorName2,
|
||||||
|
"brightness": 255,
|
||||||
|
"power": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendBasementLights = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "light",
|
||||||
|
"service": "turn_on",
|
||||||
|
"target": {
|
||||||
|
"entity_id": [
|
||||||
|
"light.basement_tall_lamp",
|
||||||
|
"light.basement_short_lamp",
|
||||||
|
"light.basement_stairwell"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"color_name": colorName1,
|
||||||
|
"brightness": 255
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendLivingRoomStripFX = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "lifx",
|
||||||
|
"service": "effect_" + effectLifx,
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["light.living_room_led_strip"]
|
||||||
|
},
|
||||||
|
"data": lifxData
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendLivingRoomStrip1 = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "lifx",
|
||||||
|
"service": "set_state",
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["light.living_room_led_strip"]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"zones": livingRoom1,
|
||||||
|
"color_name": colorName1,
|
||||||
|
"brightness": 255
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendLivingRoomStrip2 = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "lifx",
|
||||||
|
"service": "set_state",
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["light.living_room_led_strip"]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"zones": livingRoom2,
|
||||||
|
"color_name": colorName2,
|
||||||
|
"brightness": 255,
|
||||||
|
"power": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendLivingRoomLights = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "light",
|
||||||
|
"service": "turn_on",
|
||||||
|
"target": {
|
||||||
|
"entity_id": [
|
||||||
|
"light.living_room_color_1",
|
||||||
|
"light.living_room_color_2",
|
||||||
|
"light.living_room_color_3",
|
||||||
|
"light.stairwell_led_strip"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"color_name": colorName1,
|
||||||
|
"brightness": 255
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendTinaDeskLights = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "light",
|
||||||
|
"service": "turn_on",
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["light.tina_desk_lights"]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"color_name": colorName1,
|
||||||
|
"brightness": 255
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendDiningRoomLamp = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "light",
|
||||||
|
"service": "turn_off",
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["light.dining_room_lamp"]
|
||||||
|
},
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendAdaptiveFirstFloor = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "switch",
|
||||||
|
"service": "turn_off",
|
||||||
|
"target": {
|
||||||
|
"entity_id": adaptiveSwitchFirstFloor
|
||||||
|
},
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendAdaptiveBasement = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "switch",
|
||||||
|
"service": "turn_off",
|
||||||
|
"target": {
|
||||||
|
"entity_id": adaptiveSwitchBasement
|
||||||
|
},
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let backupLivingRoom = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "scene",
|
||||||
|
"service": "create",
|
||||||
|
"data": {
|
||||||
|
"scene_id": "living_room_alert_restore",
|
||||||
|
"snapshot_entities": lightsLivingRoom
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let backupTinaDesk = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "scene",
|
||||||
|
"service": "create",
|
||||||
|
"data": {
|
||||||
|
"scene_id": "tina_desk_alert_restore",
|
||||||
|
"snapshot_entities": lightsTinaDesk
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let backupBasement = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "scene",
|
||||||
|
"service": "create",
|
||||||
|
"data": {
|
||||||
|
"scene_id": "basement_alert_restore",
|
||||||
|
"snapshot_entities": lightsBasement
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendReset = {
|
||||||
|
"delay": delay
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendDebug = {
|
||||||
|
"topic": "debug",
|
||||||
|
"colorName1": colorName1,
|
||||||
|
"colorName2": colorName2,
|
||||||
|
"lifxData": lifxData,
|
||||||
|
"effectLifx": effectLifx,
|
||||||
|
"basement1": basement1,
|
||||||
|
"basement2": basement2
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send backup messages
|
||||||
|
if (stateLivingRoom === 'on' && alertFirstFloor === false) {
|
||||||
|
node.send([backupLivingRoom,null,null,null,null,null])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stateTinaDesk === 'on' && alertFirstFloor === false) {
|
||||||
|
node.send([backupTinaDesk,null,null,null,null,null])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stateBasement === 'on' && alertBasement === false) {
|
||||||
|
node.send([backupBasement,null,null,null,null,null])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send effect messages
|
||||||
|
if (effectBasement === true) {
|
||||||
|
node.send([null,null,null,null,[sendAdaptiveBasement,sendBasementLights,sendBasementStripFX,sendBasementStrip1,sendBasementStrip2,sendDebug],null])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (effectFirstFloor === true) {
|
||||||
|
node.send([null,[sendAdaptiveFirstFloor,sendLivingRoomLights,sendLivingRoomStripFX,sendLivingRoomStrip1,sendLivingRoomStrip2],sendTinaDeskLights,sendDiningRoomLamp,null,null])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send the reset message to start the timer
|
||||||
|
node.send([null,null,null,null,null,sendReset])
|
||||||
|
|
||||||
|
node.status({fill:'green',shape:'dot',text:'Alert Sent'})
|
326
lightfx/reset.js
Normal file
326
lightfx/reset.js
Normal file
@ -0,0 +1,326 @@
|
|||||||
|
// Set constants
|
||||||
|
const states = global.get('homeassistant.homeAssistant.states')
|
||||||
|
const currentSceneBasement = flow.get('currentSceneBasement')
|
||||||
|
const currentSceneLivingRoom = flow.get('currentSceneLivingRoom')
|
||||||
|
const currentSceneTinaDesk = flow.get('currentSceneTinaDesk')
|
||||||
|
const currentSceneDiningRoom = flow.get('currentSceneDiningRoom')
|
||||||
|
const adaptLivingRoom = flow.get('adaptLivingRoom')
|
||||||
|
const adaptBasement = flow.get('adaptBasement')
|
||||||
|
const nightLivingRoom = flow.get('nightLivingRoom')
|
||||||
|
const nightBasement = flow.get('nightBasement')
|
||||||
|
const nightDiningRoom = flow.get('nightDiningRoom')
|
||||||
|
const stateTinaDesk = flow.get('stateTinaDesk')
|
||||||
|
const stateLivingRoom = flow.get('stateLivingRoom')
|
||||||
|
const stateDiningRoom = flow.get('stateDiningRoom')
|
||||||
|
const stateBasement = flow.get('stateBasement')
|
||||||
|
const stateStairwell = flow.get('stateStairwell')
|
||||||
|
const scenesLivingRoom = states["input_select.living_room_scenes"].attributes.options
|
||||||
|
const scenesBasement = states["input_select.basement_studio_scenes"].attributes.options
|
||||||
|
const scenesTinaDesk = states["input_select.tina_desk_scenes"].attributes.options
|
||||||
|
const scenesDiningRoom = states["input_select.dining_room_lamp_scenes"].attributes.options
|
||||||
|
const definedLivingRoom = scenesLivingRoom.includes(currentSceneLivingRoom)
|
||||||
|
const definedBasement = scenesBasement.includes(currentSceneBasement)
|
||||||
|
const definedTinaDesk = scenesTinaDesk.includes(currentSceneTinaDesk)
|
||||||
|
const definedDiningRoom = scenesDiningRoom.includes(currentSceneDiningRoom)
|
||||||
|
|
||||||
|
// Define variables
|
||||||
|
let setSceneLivingRoom = []
|
||||||
|
let setSceneTinaDesk = []
|
||||||
|
let setSceneBasement = []
|
||||||
|
let setSceneDiningRoom = []
|
||||||
|
let setServiceLivingRoom = []
|
||||||
|
let setServiceTinaDesk = []
|
||||||
|
let setServiceDiningRoom = []
|
||||||
|
let setServiceBasement = []
|
||||||
|
let restoreLivingRoom = {}
|
||||||
|
let restoreTinaDesk = {}
|
||||||
|
let restoreBasement = {}
|
||||||
|
|
||||||
|
// Decide what to restore for each room
|
||||||
|
if (stateLivingRoom === 'on') {
|
||||||
|
setServiceLivingRoom = 'turn_on'
|
||||||
|
if (definedLivingRoom === true) {
|
||||||
|
restoreLivingRoom = 'defined'
|
||||||
|
setSceneLivingRoom = currentSceneLivingRoom
|
||||||
|
} else if (nightLivingRoom === 'on') {
|
||||||
|
restoreLivingRoom = 'night'
|
||||||
|
setSceneLivingRoom = 'Adaptive'
|
||||||
|
} else if (adaptLivingRoom === 'on') {
|
||||||
|
restoreLivingRoom = 'adaptive'
|
||||||
|
setSceneLivingRoom = 'Adaptive'
|
||||||
|
} else {
|
||||||
|
restoreLivingRoom = 'backup'
|
||||||
|
setSceneLivingRoom = 'living_room_alert_restore'
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
restoreLivingRoom = 'off'
|
||||||
|
setServiceLivingRoom = 'turn_off'
|
||||||
|
setSceneLivingRoom = 'Adaptive'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stateTinaDesk === 'on') {
|
||||||
|
setServiceTinaDesk = 'turn_on'
|
||||||
|
if (definedTinaDesk === true) {
|
||||||
|
restoreTinaDesk = 'defined'
|
||||||
|
setSceneTinaDesk = currentSceneTinaDesk
|
||||||
|
} else {
|
||||||
|
restoreTinaDesk = 'adaptive'
|
||||||
|
setSceneTinaDesk = 'Reset'
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
restoreTinaDesk = 'off'
|
||||||
|
setServiceTinaDesk = 'turn_off'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stateDiningRoom === 'on') {
|
||||||
|
setServiceDiningRoom = 'turn_on'
|
||||||
|
if (nightDiningRoom === 'on') {
|
||||||
|
setSceneDiningRoom = 'Nightlight'
|
||||||
|
} else {
|
||||||
|
setSceneDiningRoom = 'Adaptive'
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setServiceDiningRoom = 'turn_off'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stateBasement === 'on') {
|
||||||
|
setServiceBasement = 'turn_on'
|
||||||
|
if (definedBasement === true) {
|
||||||
|
restoreBasement = 'defined'
|
||||||
|
setSceneBasement = currentSceneBasement
|
||||||
|
} else if (nightBasement === 'on') {
|
||||||
|
restoreBasement = 'night'
|
||||||
|
setSceneBasement = 'Adaptive'
|
||||||
|
} else if (adaptBasement === 'on') {
|
||||||
|
restoreBasement = 'adaptive'
|
||||||
|
setSceneBasement = 'Adaptive'
|
||||||
|
} else {
|
||||||
|
restoreBasement = 'backup'
|
||||||
|
setSceneBasement = 'basement_alert_restore'
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
restoreBasement = 'off'
|
||||||
|
setServiceBasement = 'turn_off'
|
||||||
|
setSceneBasement = 'Adaptive'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define messages
|
||||||
|
let sendSceneLivingRoom = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "input_select",
|
||||||
|
"service": "select_option",
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["input_select.living_room_scenes"]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"option": setSceneLivingRoom
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendSceneTinaDesk = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "input_select",
|
||||||
|
"service": "select_option",
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["input_select.tina_desk_scenes"]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"option": setSceneTinaDesk
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendSceneBasement = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "input_select",
|
||||||
|
"service": "select_option",
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["input_select.basement_studio_scenes"]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"option": setSceneBasement
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendSceneDiningRoomLamp = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "input_select",
|
||||||
|
"service": "select_option",
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["input_select.dining_room_lamp_scenes"]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"option": setSceneDiningRoom
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let sendNightLivingRoom = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "switch",
|
||||||
|
"service": "turn_on",
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["switch.adaptive_lighting_sleep_mode_living_room"]
|
||||||
|
},
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendNightTinaDesk = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "switch",
|
||||||
|
"service": "turn_on",
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["switch.adaptive_lighting_sleep_mode_tina_desk"]
|
||||||
|
},
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendNightBasement = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "switch",
|
||||||
|
"service": "turn_on",
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["switch.adaptive_lighting_sleep_mode_basement_studio"]
|
||||||
|
},
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendStateLivingRoom = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "light",
|
||||||
|
"service": setServiceLivingRoom,
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["light.living_room_lights"]
|
||||||
|
},
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendStateTinaDesk = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "light",
|
||||||
|
"service": setServiceTinaDesk,
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["light.tina_desk_lights"]
|
||||||
|
},
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendStateDiningRoom = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "light",
|
||||||
|
"service": setServiceDiningRoom,
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["light.dining_room_lamp"]
|
||||||
|
},
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendStateBasement = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "light",
|
||||||
|
"service": setServiceBasement,
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["light.basement_studio_lights"]
|
||||||
|
},
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendRestoreLivingRoom = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "scene",
|
||||||
|
"service": "turn_on",
|
||||||
|
"target": {
|
||||||
|
"entity_id": setSceneLivingRoom
|
||||||
|
},
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendRestoreTinaDesk = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "scene",
|
||||||
|
"service": "turn_on",
|
||||||
|
"target": {
|
||||||
|
"entity_id": setSceneTinaDesk
|
||||||
|
},
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendRestoreBasement = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "scene",
|
||||||
|
"service": "turn_on",
|
||||||
|
"target": {
|
||||||
|
"entity_id": setSceneBasement
|
||||||
|
},
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendStairwellScript = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "script",
|
||||||
|
"service": "stairwell_led_strip",
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendStairwellOff = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "light",
|
||||||
|
"service": "turn_off",
|
||||||
|
"target": {
|
||||||
|
"entity_id": ["light.stairwell_led_strip"]
|
||||||
|
},
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send messages
|
||||||
|
if (restoreLivingRoom === 'backup') {
|
||||||
|
node.send([sendRestoreLivingRoom,null,null,null])
|
||||||
|
} else if (restoreLivingRoom === 'off') {
|
||||||
|
node.send([sendStateLivingRoom,null,null,null])
|
||||||
|
} else {
|
||||||
|
node.send([sendSceneLivingRoom,null,null,null])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (restoreTinaDesk === 'backup') {
|
||||||
|
node.send([null,sendRestoreTinaDesk,null,null])
|
||||||
|
} else if (restoreTinaDesk === 'off') {
|
||||||
|
node.send([null,sendStateTinaDesk,null,null])
|
||||||
|
} else {
|
||||||
|
node.send([null,sendSceneTinaDesk,null,null])
|
||||||
|
}
|
||||||
|
|
||||||
|
node.send([null,null,[sendStateDiningRoom,sendSceneDiningRoomLamp],null])
|
||||||
|
|
||||||
|
if (restoreBasement === 'backup') {
|
||||||
|
node.send([null,null,null,sendRestoreBasement])
|
||||||
|
} else if (restoreBasement === 'off') {
|
||||||
|
node.send([null,null,null,sendStateBasement])
|
||||||
|
} else {
|
||||||
|
node.send([null,null,null,sendSceneBasement])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stateStairwell === 'on') {
|
||||||
|
node.send([sendStairwellScript,null,null,null])
|
||||||
|
} else {
|
||||||
|
node.send([sendStairwellOff,null,null,null])
|
||||||
|
}
|
||||||
|
|
||||||
|
flow.set('alertFirstFloor', false)
|
||||||
|
flow.set('alertBasement', false)
|
||||||
|
|
||||||
|
node.status({fill:'green',shape:'dot',text:'Scenes Reset'})
|
@ -5,9 +5,6 @@ const tinawork = msg.tinawork
|
|||||||
if (tinawork === 'on' && workEndZone === 'on') {
|
if (tinawork === 'on' && workEndZone === 'on') {
|
||||||
node.status({fill:"green",shape:"dot",text:"Activated"})
|
node.status({fill:"green",shape:"dot",text:"Activated"})
|
||||||
return[msg,null]
|
return[msg,null]
|
||||||
} else if (tinawork === 'on' && workEndZone === 'off') {
|
|
||||||
node.status({fill:"yellow",shape:"dot",text:"Not time to leave yet"})
|
|
||||||
return null
|
|
||||||
} else if (tinawork === 'off') {
|
} else if (tinawork === 'off') {
|
||||||
node.status({fill:"yellow",shape:"dot",text:"No Work Today"})
|
node.status({fill:"yellow",shape:"dot",text:"No Work Today"})
|
||||||
return null
|
return null
|
||||||
|
@ -9,22 +9,17 @@ const newDuration = duration * 60
|
|||||||
|
|
||||||
if (sleeping === 'off') {
|
if (sleeping === 'off') {
|
||||||
if (payload === 'on') {
|
if (payload === 'on') {
|
||||||
if (lux <= threshold && lights === 'off') {
|
if (lux <= threshold || lights === 'on') {
|
||||||
node.status({fill:'green',shape:'dot',text:'Turning lights on'})
|
node.status({fill:'green',shape:'dot',text:'Lights On'})
|
||||||
node.send([msg,msg,null])
|
node.send([msg,null])
|
||||||
} else {
|
} else {
|
||||||
if (lights === 'on') {
|
node.status({fill:'red',shape:'ring',text:'Too bright'})
|
||||||
node.status({fill:'red',shape:'ring',text:'Lights already on'})
|
|
||||||
node.send([null,msg,null])
|
|
||||||
} else {
|
|
||||||
node.status({fill:'red',shape:'ring',text:'Too bright'})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (payload === 'off') {
|
} else if (payload === 'off') {
|
||||||
if (lights === 'on') {
|
if (lights === 'on') {
|
||||||
msg.duration = newDuration
|
msg.duration = newDuration
|
||||||
node.status({fill:"green",shape:"dot",text:parseInt(duration) + ' minutes'})
|
node.status({fill:"green",shape:"dot",text:parseInt(duration) + ' minutes'})
|
||||||
node.send([null,null,msg])
|
node.send([null,msg])
|
||||||
} else {
|
} else {
|
||||||
node.status({fill:"red",shape:"ring",text:"Lights already off"})
|
node.status({fill:"red",shape:"ring",text:"Lights already off"})
|
||||||
}
|
}
|
@ -3,30 +3,23 @@ const lights = states['light.kallen_bedroom_lights'].state
|
|||||||
const duration = states['input_number.kallen_bedroom_lights_off_delay'].state
|
const duration = states['input_number.kallen_bedroom_lights_off_delay'].state
|
||||||
const lux = parseInt(states['sensor.kallen_bedroom_illuminance'].state)
|
const lux = parseInt(states['sensor.kallen_bedroom_illuminance'].state)
|
||||||
const threshold = parseInt(states['input_number.kallen_bedroom_lux_threshold'].state)
|
const threshold = parseInt(states['input_number.kallen_bedroom_lux_threshold'].state)
|
||||||
const kallenBedroomSleep = states['input_boolean.kallen_sleeping'].state
|
const sleeping = states['input_boolean.kallen_sleeping'].state
|
||||||
const masterBedroomSleep = states['input_boolean.master_bedroom_sleeping'].state
|
|
||||||
const peopleSleeping = (masterBedroomSleep === 'on' || kallenBedroomSleep === 'on')
|
|
||||||
const payload = msg.payload
|
const payload = msg.payload
|
||||||
const newDuration = duration * 60
|
const newDuration = duration * 60
|
||||||
|
|
||||||
if (peopleSleeping === false) {
|
if (sleeping === 'off') {
|
||||||
if (payload === 'on') {
|
if (payload === 'on') {
|
||||||
if (lux <= threshold && lights === 'off') {
|
if (lux <= threshold || lights === 'on') {
|
||||||
node.status({fill:'green',shape:'dot',text:'Turning lights on'})
|
node.status({fill:'green',shape:'dot',text:'Lights On'})
|
||||||
node.send([msg,msg,null])
|
node.send([msg,null])
|
||||||
} else {
|
} else {
|
||||||
if (lights === 'on') {
|
node.status({fill:'red',shape:'ring',text:'Too bright'})
|
||||||
node.status({fill:'red',shape:'ring',text:'Lights already on'})
|
|
||||||
node.send([null,msg,null])
|
|
||||||
} else {
|
|
||||||
node.status({fill:'red',shape:'ring',text:'Too bright'})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (payload === 'off') {
|
} else if (payload === 'off') {
|
||||||
if (lights === 'on') {
|
if (lights === 'on') {
|
||||||
msg.duration = newDuration
|
msg.duration = newDuration
|
||||||
node.status({fill:"green",shape:"dot",text:parseInt(duration) + ' minutes'})
|
node.status({fill:"green",shape:"dot",text:parseInt(duration) + ' minutes'})
|
||||||
node.send([null,null,msg])
|
node.send([null,msg])
|
||||||
} else {
|
} else {
|
||||||
node.status({fill:"red",shape:"ring",text:"Lights already off"})
|
node.status({fill:"red",shape:"ring",text:"Lights already off"})
|
||||||
}
|
}
|
@ -12,22 +12,17 @@ const newDuration = duration * 60
|
|||||||
|
|
||||||
if (peopleSleeping === false && nightMode === 'off') {
|
if (peopleSleeping === false && nightMode === 'off') {
|
||||||
if (payload === 'on') {
|
if (payload === 'on') {
|
||||||
if (lux <= threshold && lights === 'off') {
|
if (lux <= threshold || lights === 'on') {
|
||||||
node.status({fill:'green',shape:'dot',text:'Turning lights on'})
|
node.status({fill:'green',shape:'dot',text:'Lights On'})
|
||||||
node.send([msg,msg,null])
|
node.send([msg,null])
|
||||||
} else {
|
} else {
|
||||||
if (lights === 'on') {
|
node.status({fill:'red',shape:'ring',text:'Too bright'})
|
||||||
node.status({fill:'red',shape:'ring',text:'Lights already on'})
|
|
||||||
node.send([null,msg,null])
|
|
||||||
} else {
|
|
||||||
node.status({fill:'red',shape:'ring',text:'Too bright'})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (payload === 'off') {
|
} else if (payload === 'off') {
|
||||||
if (lights === 'on') {
|
if (lights === 'on') {
|
||||||
msg.duration = newDuration
|
msg.duration = newDuration
|
||||||
node.status({fill:"green",shape:"dot",text:parseInt(duration) + ' minutes'})
|
node.status({fill:"green",shape:"dot",text:parseInt(duration) + ' minutes'})
|
||||||
node.send([null,null,msg])
|
node.send([null,msg])
|
||||||
} else {
|
} else {
|
||||||
node.status({fill:"red",shape:"ring",text:"Lights already off"})
|
node.status({fill:"red",shape:"ring",text:"Lights already off"})
|
||||||
}
|
}
|
@ -1,94 +0,0 @@
|
|||||||
const states = global.get('homeassistant.homeAssistant.states')
|
|
||||||
const masterBedroomSleeping = states['input_boolean.master_bedroom_sleeping'].state
|
|
||||||
const emmaSleep = states['input_boolean.emma_sleeping'].state
|
|
||||||
const tonyAwake = states['input_boolean.tony_awake'].state
|
|
||||||
const xiaDesktopUser = states['sensor.xia_desktop_current_username'].state
|
|
||||||
const xiaDesktopIdle = states['binary_sensor.tina_desktop_idle'].state
|
|
||||||
const tonyLocation = states['person.tony_stork'].state
|
|
||||||
const tinaLocation = states['person.christina_stork'].state
|
|
||||||
const overnight = states['binary_sensor.overnight'].state
|
|
||||||
const payload = msg.payload
|
|
||||||
const topic = msg.topic
|
|
||||||
|
|
||||||
// Set some default values
|
|
||||||
|
|
||||||
let who = 'Alexa Everywhere' // Default to playing on all Echo Dots unless told otherwise
|
|
||||||
let tinaAvailable = false
|
|
||||||
let tonyAvailable = false
|
|
||||||
let enable = false
|
|
||||||
let reason = {}
|
|
||||||
|
|
||||||
// Determine who is available to respond
|
|
||||||
|
|
||||||
if (tonyAwake === 'on' && tonyLocation === 'home') {
|
|
||||||
tonyAvailable = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xiaDesktopUser === 'irish' && xiaDesktopIdle === 'off' && tinaLocation === 'home') {
|
|
||||||
tinaAvailable = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// If both of us are still asleep, or I am asleep and she is at work, play the alert only in the master bedroom
|
|
||||||
|
|
||||||
if (tinaAvailable === false && tonyAvailable === false) {
|
|
||||||
who = 'Master Bedroom'
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine if the alert should be sent
|
|
||||||
|
|
||||||
if (emmaSleep === 'on') {
|
|
||||||
if (overnight === 'on' && masterBedroomSleeping === 'on') {
|
|
||||||
enable = true
|
|
||||||
reason = 'Overnight is on, and master bedroom is sleeping'
|
|
||||||
} else if (overnight === 'off') {
|
|
||||||
enable = true
|
|
||||||
reason = 'Overnight is off'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define the alert message
|
|
||||||
|
|
||||||
let alertTTS = {
|
|
||||||
"topic": who,
|
|
||||||
"payload": "Emma has opened her door, please check on her. I repeat, Emma has opened her door, please check on her. This is urgent, Emma is awake. PDS toddler warning, a large and extremely dangerous toddler is on the ground in your area.",
|
|
||||||
"type": "critical"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add some logs for debugging
|
|
||||||
|
|
||||||
node.log(`--------------- Emma Door Alert --------------`)
|
|
||||||
node.log(`Emma Door Alert - topic: ${topic}`)
|
|
||||||
node.log(`Emma Door Alert - payload: ${payload}`)
|
|
||||||
node.log(`Emma Door Alert - masterBedroomSleeping: ${masterBedroomSleeping}`)
|
|
||||||
node.log(`Emma Door Alert - emmaSleep: ${emmaSleep}`)
|
|
||||||
node.log(`Emma Door Alert - tonyAwake: ${tonyAwake}`)
|
|
||||||
node.log(`Emma Door Alert - xiaDesktopUser: ${xiaDesktopUser}`)
|
|
||||||
node.log(`Emma Door Alert - xiaDesktopIdle: ${xiaDesktopIdle}`)
|
|
||||||
node.log(`Emma Door Alert - tonyLocation: ${tonyLocation}`)
|
|
||||||
node.log(`Emma Door Alert - tinaLocation: ${tinaLocation}`)
|
|
||||||
node.log(`Emma Door Alert - overnight: ${overnight}`)
|
|
||||||
node.log(`Emma Door Alert - tonyAvailable: ${tonyAvailable}`)
|
|
||||||
node.log(`Emma Door Alert - tinaAvailable: ${tinaAvailable}`)
|
|
||||||
node.log(`Emma Door Alert - who: ${who}`)
|
|
||||||
node.log(`Emma Door Alert - enable: ${enable}`)
|
|
||||||
node.log(`Emma Door Alert - reason: ${reason}`)
|
|
||||||
node.log(`----------------------------------------------`)
|
|
||||||
|
|
||||||
// Send the alert if conditions are met
|
|
||||||
|
|
||||||
if (topic === 'door' && payload === 'on') {
|
|
||||||
if (enable === true) {
|
|
||||||
node.status({fill:'green',shape:'dot',text:`Sending alert to ${who}`})
|
|
||||||
node.send([alertTTS,msg,null])
|
|
||||||
} else {
|
|
||||||
node.status({fill:'red',shape:'ring',text:'Door Opened, but no alert sent'})
|
|
||||||
}
|
|
||||||
} else if (topic === 'timer') {
|
|
||||||
node.status({fill:'green',shape:'dot',text:'Timer Finished'})
|
|
||||||
node.send([alertTTS,msg,null])
|
|
||||||
} else if (topic === 'cancel') {
|
|
||||||
node.status({fill:'green',shape:'dot',text:'Cancel Button Pressed'})
|
|
||||||
node.send([null,null,msg])
|
|
||||||
} else if (topic === 'door' && payload === 'off') {
|
|
||||||
node.status({fill:'green',shape:'dot',text:'Door Closed'})
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
const livingRoom = ["Living Room", "Living Room Echo Dot"]
|
|
||||||
const basementAlexa = ["Basement", "Basement Echo Dot"]
|
|
||||||
const basementGoogle = ["Basement Google", "basement_google"]
|
|
||||||
const kallenBedroom = ["Kallen Bedroom", "Kallen Bedroom Speaker"]
|
|
||||||
const emmaBedroom = ["Emma Bedroom", "Emma Bedroom Speaker"]
|
|
||||||
const kidsBedrooms = ["Kids Bedrooms"]
|
|
||||||
const allBedrooms = ["All Bedrooms"]
|
|
||||||
const masterBedroom = ["Master Bedroom", "Master Bedroom Echo Dot"]
|
|
||||||
const commonAreas = ["Common Areas"]
|
|
||||||
const alexaEverywhere = ["alexa_everywhere", "Alexa Everywhere"]
|
|
||||||
const room = msg.topic
|
|
||||||
const voice = msg.voice || global.get("jarvis_voice", "diskCon")
|
|
||||||
const type = msg.type || "normal"
|
|
||||||
|
|
||||||
if (livingRoom.includes(room)) {
|
|
||||||
msg.topic = "living_room"
|
|
||||||
} else if (basementAlexa.includes(room)) {
|
|
||||||
msg.topic = "basement"
|
|
||||||
} else if (basementGoogle.includes(room)) {
|
|
||||||
msg.topic = "basement_google"
|
|
||||||
} else if (kallenBedroom.includes(room)) {
|
|
||||||
msg.topic = "kallen_bedroom"
|
|
||||||
} else if (emmaBedroom.includes(room)) {
|
|
||||||
msg.topic = "emma_bedroom"
|
|
||||||
} else if (kidsBedrooms.includes(room)) {
|
|
||||||
msg.topic = "kids_bedrooms"
|
|
||||||
} else if (allBedrooms.includes(room)) {
|
|
||||||
msg.topic = "all_bedrooms"
|
|
||||||
} else if (masterBedroom.includes(room)) {
|
|
||||||
msg.topic = "master_bedroom"
|
|
||||||
} else if (commonAreas.includes(room)) {
|
|
||||||
msg.topic = "common"
|
|
||||||
} else if (alexaEverywhere.includes(room)) {
|
|
||||||
msg.topic = "alexa_everywhere"
|
|
||||||
} else if (room === "Everywhere") {
|
|
||||||
msg.topic = "everywhere"
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.voice = voice
|
|
||||||
msg.type = type
|
|
||||||
|
|
||||||
let statusMsg = {
|
|
||||||
"status": {
|
|
||||||
"fill": "green",
|
|
||||||
"shape": "dot",
|
|
||||||
"text": `${msg.voice} speaking in ${room}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
node.send([msg,statusMsg])
|
|
@ -1,36 +0,0 @@
|
|||||||
// Get the user ID list from global context
|
|
||||||
const users = global.get("userIDList", "diskCon") || {}
|
|
||||||
|
|
||||||
// Initialize variables
|
|
||||||
let userTrigger = "none"
|
|
||||||
let statusTxt = ""
|
|
||||||
|
|
||||||
// Extract user ID from the message
|
|
||||||
if (msg.payload?.context?.user_id) {
|
|
||||||
userTrigger = msg.payload.context.user_id
|
|
||||||
} else if (msg.data?.context?.user_id) {
|
|
||||||
userTrigger = msg.data.context.user_id
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate userTrigger and set status message
|
|
||||||
if (userTrigger === "none" || !users[userTrigger]) {
|
|
||||||
statusTxt = "User not found"
|
|
||||||
node.error(`User ID '${userTrigger}' not found in user list.`)
|
|
||||||
return null // Stop execution if user is not found
|
|
||||||
} else {
|
|
||||||
const user = users[userTrigger]
|
|
||||||
statusTxt = `User: ${user.firstName}`
|
|
||||||
msg.user = { ...user } // Avoid mutating the original msg
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the status message
|
|
||||||
const statusMsg = {
|
|
||||||
status: {
|
|
||||||
fill: "green",
|
|
||||||
shape: "dot",
|
|
||||||
text: `${statusTxt} at ${new Date().toLocaleString()}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the message and status message to the output nodes
|
|
||||||
node.send([msg, statusMsg])
|
|
@ -1,22 +0,0 @@
|
|||||||
let userIDList = {
|
|
||||||
"c3909d27048140729f002aaef0391775": {
|
|
||||||
"shortName": "tony",
|
|
||||||
"firstName": "Tony",
|
|
||||||
"lastName": "Stork",
|
|
||||||
"hassUser": "tonystork"
|
|
||||||
},
|
|
||||||
"f387a983651a4321a7411ff8cf36f949": {
|
|
||||||
"shortName": "tina",
|
|
||||||
"firstName": "Christina",
|
|
||||||
"lastName": "Stork",
|
|
||||||
"hassUser": "christinastork"
|
|
||||||
},
|
|
||||||
"879b4c04e32841b3ad1d2763a11b4e70": {
|
|
||||||
"shortName": "kallen",
|
|
||||||
"firstName": "Kallen",
|
|
||||||
"lastName": "Stork",
|
|
||||||
"hassUser": "kallenstork"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
global.set("userIDList",userIDList,"diskCon")
|
|
@ -1,27 +1,18 @@
|
|||||||
const states = global.get('homeassistant.homeAssistant.states')
|
const states = global.get('homeassistant.homeAssistant.states')
|
||||||
const luxThresholdLivingRoom = states['input_number.living_room_lux_threshold'].state
|
const luxThresholdLivingRoom = states['input_number.living_room_lux_threshold'].state
|
||||||
const luxThresholdStairwell = states['input_number.stairwell_lux_threshold'].state
|
const luxThresholdStairwell = states['input_number.stairwell_lux_threshold'].state
|
||||||
const luxThresholdOutdoor = states['input_number.sunset_lights_outdoor_lux_threshold'].state
|
const timer = states['timer.sunset_lighting_timer'].state
|
||||||
const earlyNight = states['binary_sensor.early_night_mode'].state
|
|
||||||
const triggered = states['input_boolean.sunset_lights_triggered'].state
|
|
||||||
const level = msg.level
|
const level = msg.level
|
||||||
const room = msg.room
|
const room = msg.room
|
||||||
|
|
||||||
if (earlyNight === 'on' && triggered === 'off') {
|
if (timer === 'active') {
|
||||||
if (room === 'living-room' && level <= luxThresholdLivingRoom) {
|
if (room === 'living-room' && level <= luxThresholdLivingRoom) {
|
||||||
node.status({fill:'green',shape:'dot',text:'Sent (Living Room)'})
|
node.status({fill:'green',shape:'dot',text:'Sent (Living Room)'})
|
||||||
node.send([msg,msg])
|
node.send(msg)
|
||||||
} else if (room === 'stairwell-bottom' && level <= luxThresholdStairwell) {
|
} else if (room === 'stairwell-bottom' && level <= luxThresholdStairwell) {
|
||||||
node.status({fill:'green',shape:'dot',text:'Sent (Stairwell Bottom)'})
|
node.status({fill:'green',shape:'dot',text:'Sent (Stairwell Bottom)'})
|
||||||
node.send([msg,msg])
|
node.send(msg)
|
||||||
} else if (room === 'outdoor' && level <= luxThresholdOutdoor) {
|
|
||||||
node.status({fill:'green',shape:'dot',text:'Sent (Outdoor)'})
|
|
||||||
node.send([msg,msg])
|
|
||||||
}
|
}
|
||||||
} else if (earlyNight === 'off') {
|
|
||||||
node.status({fill:'red',shape:'ring',text:'Not Evening'})
|
|
||||||
} else if (triggered === 'on') {
|
|
||||||
node.status({fill:'red',shape:'ring',text:'Already Triggered'})
|
|
||||||
} else {
|
} else {
|
||||||
node.status({fill:'red',shape:'ring',text:'No Action'})
|
node.status({fill:'red',shape:'ring',text:'Blocked'})
|
||||||
}
|
}
|
@ -64,8 +64,7 @@ const booleanOff = [
|
|||||||
"input_boolean.give_me_darkness",
|
"input_boolean.give_me_darkness",
|
||||||
"input_boolean.goodnight",
|
"input_boolean.goodnight",
|
||||||
"input_boolean.kallen_computer_updates",
|
"input_boolean.kallen_computer_updates",
|
||||||
"input_boolean.night_mode",
|
"input_boolean.night_mode"
|
||||||
"input_boolean.sunset_lights_triggered"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
//! ---------- NIGHT MODE ----------
|
//! ---------- NIGHT MODE ----------
|
||||||
|
@ -11,18 +11,22 @@ const sunsetLights = states['input_boolean.sunset_lights_on'].state
|
|||||||
const vacation = states['input_boolean.vacation_mode'].state
|
const vacation = states['input_boolean.vacation_mode'].state
|
||||||
const upBathOcc = states['binary_sensor.upstairs_bathroom_occupied'].state
|
const upBathOcc = states['binary_sensor.upstairs_bathroom_occupied'].state
|
||||||
const deskLights = states['light.tina_desk_lights'].state
|
const deskLights = states['light.tina_desk_lights'].state
|
||||||
|
const luxLivingRoom = states['sensor.living_room_front_illuminance'].state
|
||||||
|
const luxThresholdLivingRoom = states['input_number.living_room_lux_threshold'].state
|
||||||
|
const luxStairwell = states['sensor.stairwell_bottom_illuminance'].state
|
||||||
|
const luxThresholdStairwell = states['input_number.stairwell_lux_threshold'].state
|
||||||
const adaptiveSleep = flow.get("adaptiveSleep", "diskCon")
|
const adaptiveSleep = flow.get("adaptiveSleep", "diskCon")
|
||||||
const selScenesMain = flow.get("selScenesMain", "diskCon")
|
const selScenesMain = flow.get("selScenesMain", "diskCon")
|
||||||
const selScenesTinaDesk = flow.get("selScenesTinaDesk", "diskCon")
|
const selScenesTinaDesk = flow.get("selScenesTinaDesk", "diskCon")
|
||||||
const booleanOff = flow.get("booleanOff", "diskCon")
|
const booleanOff = flow.get("booleanOff", "diskCon")
|
||||||
const triggered = states['input_boolean.sunset_lights_triggered'].state
|
|
||||||
const payload = msg.payload
|
const payload = msg.payload
|
||||||
const topic = msg.topic
|
|
||||||
node.log("Time-based Automations: Constants Set")
|
node.log("Time-based Automations: Constants Set")
|
||||||
|
|
||||||
// Set a few important variables
|
// Set a few important variables
|
||||||
|
|
||||||
let time = {}
|
let time = {}
|
||||||
|
let topic = {}
|
||||||
|
let delay = {}
|
||||||
let eventCall = {}
|
let eventCall = {}
|
||||||
|
|
||||||
if (payload == 0) {
|
if (payload == 0) {
|
||||||
@ -33,6 +37,17 @@ if (payload == 0) {
|
|||||||
eventCall = "off"
|
eventCall = "off"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (msg.topic === 'timer-finished' || msg.topic === 'manual-trigger' || msg.topic === 'lux') {
|
||||||
|
topic = msg.topic
|
||||||
|
}
|
||||||
|
|
||||||
|
if (topic === 'timer-finished' || topic === 'manual-trigger' || topic === 'lux') {
|
||||||
|
delay = 'off'
|
||||||
|
} else if (luxLivingRoom > luxThresholdLivingRoom && luxStairwell > luxThresholdStairwell) {
|
||||||
|
delay = 'on'
|
||||||
|
} else {
|
||||||
|
delay = 'off'
|
||||||
|
}
|
||||||
node.log("Time-based Automations: Main variables defined")
|
node.log("Time-based Automations: Main variables defined")
|
||||||
|
|
||||||
// ---------- Configuration ----------
|
// ---------- Configuration ----------
|
||||||
@ -81,8 +96,19 @@ if (sunsetLights === 'off') {
|
|||||||
sunsetStatus = "Skipped"
|
sunsetStatus = "Skipped"
|
||||||
} else {
|
} else {
|
||||||
notifyTitle = "Sunset Lights On"
|
notifyTitle = "Sunset Lights On"
|
||||||
notifyMsg = "It's getting dark, evening lighting is now active"
|
if (topic === 'timer-finished') {
|
||||||
sunsetStatus = "Light Level Trigger"
|
notifyMsg = "Lights on because timer was finished manually"
|
||||||
|
sunsetStatus = "Manual Trigger"
|
||||||
|
} else if (topic === 'lux') {
|
||||||
|
notifyMsg = "Lights on because light level dropped below threshold"
|
||||||
|
sunsetStatus = "Light Level Trigger"
|
||||||
|
} else if (delay === 'on') {
|
||||||
|
notifyMsg = "Lights on after delay due to sufficient light"
|
||||||
|
sunsetStatus = "Delayed"
|
||||||
|
} else if (delay === 'off') {
|
||||||
|
notifyMsg = "Lights on early due to low light"
|
||||||
|
sunsetStatus = "Early"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Holiday Settings
|
// Holiday Settings
|
||||||
@ -99,20 +125,10 @@ if (holidayMode === 'on') {
|
|||||||
node.log("Time-based Automations: Decision Logic Complete")
|
node.log("Time-based Automations: Decision Logic Complete")
|
||||||
|
|
||||||
// ---------- Service Calls ----------
|
// ---------- Service Calls ----------
|
||||||
|
|
||||||
let sendTriggered = {
|
|
||||||
"payload": {
|
|
||||||
"action": "input_boolean.turn_on",
|
|
||||||
"target": {
|
|
||||||
"entity_id": ["input_boolean.sunset_lights_triggered"]
|
|
||||||
},
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sendLights = {
|
let sendLights = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "light.turn_off",
|
"domain": "light",
|
||||||
|
"service": "turn_off",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": lightsOff
|
"entity_id": lightsOff
|
||||||
},
|
},
|
||||||
@ -122,7 +138,8 @@ let sendLights = {
|
|||||||
|
|
||||||
let sendSleepOff = {
|
let sendSleepOff = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "switch.turn_off",
|
"domain": "switch",
|
||||||
|
"service": "turn_off",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": adaptiveSleep
|
"entity_id": adaptiveSleep
|
||||||
},
|
},
|
||||||
@ -132,7 +149,8 @@ let sendSleepOff = {
|
|||||||
|
|
||||||
let sendBooleanOff = {
|
let sendBooleanOff = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "input_boolean.turn_off",
|
"domain": "input_boolean",
|
||||||
|
"service": "turn_off",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": booleanOff
|
"entity_id": booleanOff
|
||||||
},
|
},
|
||||||
@ -142,7 +160,8 @@ let sendBooleanOff = {
|
|||||||
|
|
||||||
let sendAdaptive = {
|
let sendAdaptive = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "switch.turn_" + setAdaptive,
|
"domain": "switch",
|
||||||
|
"service": "turn_" + setAdaptive,
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": switchAdaptive
|
"entity_id": switchAdaptive
|
||||||
},
|
},
|
||||||
@ -152,7 +171,8 @@ let sendAdaptive = {
|
|||||||
|
|
||||||
let sendSceneResetMain = {
|
let sendSceneResetMain = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "input_text.set_value",
|
"domain": "input_text",
|
||||||
|
"service": "set_value",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": selScenesMain
|
"entity_id": selScenesMain
|
||||||
},
|
},
|
||||||
@ -164,7 +184,8 @@ let sendSceneResetMain = {
|
|||||||
|
|
||||||
let sendSceneResetDesk = {
|
let sendSceneResetDesk = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "input_text.set_value",
|
"domain": "input_text",
|
||||||
|
"service": "set_value",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": selScenesTinaDesk
|
"entity_id": selScenesTinaDesk
|
||||||
},
|
},
|
||||||
@ -176,7 +197,8 @@ let sendSceneResetDesk = {
|
|||||||
|
|
||||||
let sendHoliday = {
|
let sendHoliday = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "switch.turn_" + setHoliday,
|
"domain": "switch",
|
||||||
|
"service": "turn_" + setHoliday,
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": switchHoliday
|
"entity_id": switchHoliday
|
||||||
},
|
},
|
||||||
@ -184,9 +206,34 @@ let sendHoliday = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let sendTimer = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "timer",
|
||||||
|
"service": "start",
|
||||||
|
"target": {
|
||||||
|
"entity_id": timerEntity
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"duration": timerDuration
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sendTimerCancel = {
|
||||||
|
"payload": {
|
||||||
|
"domain": "timer",
|
||||||
|
"service": "cancel",
|
||||||
|
"target": {
|
||||||
|
"entity_id": timerEntity
|
||||||
|
},
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let sendNotifyPhone = {
|
let sendNotifyPhone = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "script.text_notify",
|
"domain": "script",
|
||||||
|
"service": "text_notify",
|
||||||
"data": {
|
"data": {
|
||||||
"who": "all",
|
"who": "all",
|
||||||
"title": notifyTitle,
|
"title": notifyTitle,
|
||||||
@ -199,7 +246,8 @@ let sendNotifyPhone = {
|
|||||||
|
|
||||||
let sendNotifyTV = {
|
let sendNotifyTV = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "script.tv_notify",
|
"domain": "script",
|
||||||
|
"service": "tv_notify",
|
||||||
"data": {
|
"data": {
|
||||||
"who": "all",
|
"who": "all",
|
||||||
"title": notifyTitle,
|
"title": notifyTitle,
|
||||||
@ -215,7 +263,8 @@ let sendNotifyTV = {
|
|||||||
|
|
||||||
let sendFirstFloorScene = {
|
let sendFirstFloorScene = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "script.evening_on_first_floor",
|
"domain": "script",
|
||||||
|
"service": "evening_on_first_floor",
|
||||||
"data": {
|
"data": {
|
||||||
"sunset_lights": 1
|
"sunset_lights": 1
|
||||||
}
|
}
|
||||||
@ -224,7 +273,8 @@ let sendFirstFloorScene = {
|
|||||||
|
|
||||||
let sendSecondFloorScene = {
|
let sendSecondFloorScene = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "script.evening_on_second_floor",
|
"domain": "script",
|
||||||
|
"service": "evening_on_second_floor",
|
||||||
"data": {
|
"data": {
|
||||||
"sunset_lights": 1
|
"sunset_lights": 1
|
||||||
}
|
}
|
||||||
@ -233,7 +283,8 @@ let sendSecondFloorScene = {
|
|||||||
|
|
||||||
let sendDeskScene = {
|
let sendDeskScene = {
|
||||||
"payload": {
|
"payload": {
|
||||||
"action": "input_select.select_option",
|
"domain": "input_select",
|
||||||
|
"service": "select_option",
|
||||||
"target": {
|
"target": {
|
||||||
"entity_id": ["input_select.tina_desk_scenes"]
|
"entity_id": ["input_select.tina_desk_scenes"]
|
||||||
},
|
},
|
||||||
@ -261,6 +312,11 @@ node.log("lightsOff: " + lightsOff)
|
|||||||
node.log("holidayMode: " + holidayMode)
|
node.log("holidayMode: " + holidayMode)
|
||||||
node.log("eventCall: " + eventCall)
|
node.log("eventCall: " + eventCall)
|
||||||
if (time === 'night') {
|
if (time === 'night') {
|
||||||
|
node.log("luxLivingRoom: " + luxLivingRoom)
|
||||||
|
node.log("luxThresholdLivingRoom: " + luxThresholdLivingRoom)
|
||||||
|
node.log("luxStairwell: " + luxStairwell)
|
||||||
|
node.log("luxThresholdStairwell: " + luxThresholdStairwell)
|
||||||
|
node.log("delay: " + delay)
|
||||||
node.log("sunsetStatus: " + sunsetStatus)
|
node.log("sunsetStatus: " + sunsetStatus)
|
||||||
}
|
}
|
||||||
if (holidayMode === 'on') {
|
if (holidayMode === 'on') {
|
||||||
@ -282,13 +338,18 @@ if (vacation === 'off') {
|
|||||||
}
|
}
|
||||||
}, 5000)
|
}, 5000)
|
||||||
} else if (time === "night") {
|
} else if (time === "night") {
|
||||||
if (triggered === 'off') {
|
node.status({fill:"green",shape:"dot",text:"Sunset Flow"})
|
||||||
node.status({fill:"green",shape:"dot",text:"Sunset Flow"})
|
node.send([null,sendAdaptive,null,null])
|
||||||
node.send([null,[sendAdaptive,sendTriggered],null,null])
|
if (holidayMode === 'on') {
|
||||||
if (holidayMode === 'on') {
|
setTimeout(() => {
|
||||||
setTimeout(() => {
|
node.send([null,sendHoliday,null,null])
|
||||||
node.send([null,sendHoliday,null,null])
|
}, 1000)
|
||||||
}, 1000)
|
}
|
||||||
|
if (delay === 'on') {
|
||||||
|
node.send([null,sendTimer,null,null])
|
||||||
|
} else {
|
||||||
|
if (topic === 'lux') {
|
||||||
|
node.send([null,sendTimerCancel,null,null])
|
||||||
}
|
}
|
||||||
node.send([null,null,[sendFirstFloorScene,sendSecondFloorScene],sendExtraLights])
|
node.send([null,null,[sendFirstFloorScene,sendSecondFloorScene],sendExtraLights])
|
||||||
if (deskLights === 'on') {
|
if (deskLights === 'on') {
|
||||||
@ -297,8 +358,6 @@ if (vacation === 'off') {
|
|||||||
if (topic != 'manual-trigger') {
|
if (topic != 'manual-trigger') {
|
||||||
node.send([[sendNotifyPhone,sendNotifyTV],null,null,null])
|
node.send([[sendNotifyPhone,sendNotifyTV],null,null,null])
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
node.status({fill:'green',shape:'dot',text:'Sunset Flow (Already Triggered)'})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
let tomorrow = msg.tomorrow
|
|
||||||
let today = msg.today
|
|
||||||
let number = {}
|
|
||||||
let work_tomorrow = {}
|
|
||||||
|
|
||||||
// Check if calendar data exists
|
|
||||||
if (!msg.payload || msg.payload.length === 0) {
|
|
||||||
msg.payload = [{
|
|
||||||
date: "No Data",
|
|
||||||
eventStart: "No Data",
|
|
||||||
eventEnd: "No Data",
|
|
||||||
summary: "No Data",
|
|
||||||
location: "No Data",
|
|
||||||
isRecurring: "No Data",
|
|
||||||
allDay: "No Data",
|
|
||||||
calendarName: "No Data",
|
|
||||||
countdown: "No Data",
|
|
||||||
uid: { date: "No Data" }
|
|
||||||
}]
|
|
||||||
work_tomorrow = "false"
|
|
||||||
number = 0
|
|
||||||
} else {
|
|
||||||
if (tomorrow > 0) {
|
|
||||||
work_tomorrow = "true"
|
|
||||||
if (today == 0) {
|
|
||||||
number = 0
|
|
||||||
} else {
|
|
||||||
number = 1
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
work_tomorrow = "false"
|
|
||||||
number = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.work_tomorrow = work_tomorrow
|
|
||||||
|
|
||||||
node.status({fill:"green",shape:"dot",text:`Number ${number}`})
|
|
||||||
|
|
||||||
if (number == 0) {
|
|
||||||
node.send([msg,null])
|
|
||||||
} else {
|
|
||||||
node.send([null,msg])
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
const severeWarningEvents = ["Severe Thunderstorm Warning", "Destructive Severe Thunderstorm Warning", "Considerable Destructive Severe Thunderstorm Warning"]
|
|
||||||
const tornadoWarningEvents = ["Tornado Warning", "Radar Indicated Tornado Warning", "Confirmed Tornado Warning", "Tornado Emergency"]
|
|
||||||
|
|
||||||
let alerts = msg.payload
|
|
||||||
|
|
||||||
// Helper function to safely access nested properties
|
|
||||||
const getNestedProperty = (obj, path, defaultValue = undefined) => {
|
|
||||||
return path.reduce((acc, key) => (acc && acc[key] !== undefined ? acc[key] : defaultValue), obj)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter function
|
|
||||||
const filterAlerts = (alerts, condition) => {
|
|
||||||
return alerts.filter(alert => {
|
|
||||||
try {
|
|
||||||
return condition(alert)
|
|
||||||
} catch (e) {
|
|
||||||
node.warn(`Error processing alert: ${e.message}`)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filtering logic
|
|
||||||
const ts = filterAlerts(alerts, alert => {
|
|
||||||
const event = getNestedProperty(alert, ['raw', 'properties', 'event'])
|
|
||||||
return severeWarningEvents.includes(event)
|
|
||||||
})
|
|
||||||
|
|
||||||
const tstp = filterAlerts(alerts, alert => {
|
|
||||||
const event = getNestedProperty(alert, ['raw', 'properties', 'event'])
|
|
||||||
const tornadoDetection = getNestedProperty(alert, ['raw', 'properties', 'parameters', 'tornadoDetection'], [])
|
|
||||||
return severeWarningEvents.includes(event) && tornadoDetection.includes("POSSIBLE")
|
|
||||||
})
|
|
||||||
|
|
||||||
const cdst = filterAlerts(alerts, alert => {
|
|
||||||
const event = getNestedProperty(alert, ['raw', 'properties', 'event'])
|
|
||||||
return event === "Considerable Destructive Severe Thunderstorm Warning"
|
|
||||||
})
|
|
||||||
|
|
||||||
const tornado = filterAlerts(alerts, alert => {
|
|
||||||
const event = getNestedProperty(alert, ['raw', 'properties', 'event'])
|
|
||||||
return tornadoWarningEvents.includes(event)
|
|
||||||
})
|
|
||||||
|
|
||||||
const confirmed_tornado = filterAlerts(alerts, alert => {
|
|
||||||
const event = getNestedProperty(alert, ['raw', 'properties', 'event'])
|
|
||||||
return event === "Confirmed Tornado Warning"
|
|
||||||
})
|
|
||||||
|
|
||||||
// Output messages
|
|
||||||
let tstormMsg = {
|
|
||||||
"payload": {
|
|
||||||
"alerts": ts,
|
|
||||||
"count": ts.length,
|
|
||||||
"tornado_possible": tstp.length,
|
|
||||||
"considerable_destructive": cdst.length
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let tornadoWarnMsg = {
|
|
||||||
"payload": {
|
|
||||||
"alerts": tornado,
|
|
||||||
"count": tornado.length,
|
|
||||||
"confirmed": confirmed_tornado.length
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
node.send([tstormMsg, tornadoWarnMsg])
|
|
||||||
node.status({ fill: 'green', shape: 'dot', text: `${alerts.length} alerts processed at ${new Date().toLocaleString()}`})
|
|
@ -1,150 +0,0 @@
|
|||||||
const severeWarningEvents = ["Severe Thunderstorm Warning","Destructive Severe Thunderstorm Warning","Considerable Destructive Severe Thunderstorm Warning"]
|
|
||||||
const tornadoWarningEvents = ["Tornado Warning","Radar Indicated Tornado Warning","Confirmed Tornado Warning","Tornado Emergency"]
|
|
||||||
const tornadoWatchEvents = ["Tornado Watch"]
|
|
||||||
const severeThunderstormWatchEvents = ["Severe Thunderstorm Watch"]
|
|
||||||
const area = msg.area
|
|
||||||
const mqttTopic = "weather/alerts/" + area
|
|
||||||
const allTopic = mqttTopic + "/alerts"
|
|
||||||
const tstormTopic = mqttTopic + "/severe_thunderstorm_warning"
|
|
||||||
const tornadoWarnTopic = mqttTopic + "/tornado_warning"
|
|
||||||
const tornadoWatchTopic = mqttTopic + "/tornado_watch"
|
|
||||||
const severeThunderstormWatchTopic = mqttTopic + "/severe_thunderstorm_watch"
|
|
||||||
|
|
||||||
let alerts = msg.payload.features
|
|
||||||
let tornado_possible = false
|
|
||||||
let considerable_destructive = false
|
|
||||||
let confirmed = false
|
|
||||||
|
|
||||||
// Filter for Severe Thunderstorm Warnings
|
|
||||||
|
|
||||||
let ts = alerts.filter(function(alert) {
|
|
||||||
if (alert.properties &&
|
|
||||||
severeWarningEvents.includes(alert.properties.event)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Filter for Severe Thunderstorm Warnings with tornado detection
|
|
||||||
// that have a tornado possible parameter
|
|
||||||
|
|
||||||
let tstp = alerts.filter(function(alert) {
|
|
||||||
if (alert.properties &&
|
|
||||||
severeWarningEvents.includes(alert.properties.event) &&
|
|
||||||
alert.properties.parameters &&
|
|
||||||
alert.properties.parameters.tornadoDetection &&
|
|
||||||
alert.properties.parameters.tornadoDetection.length > 0) {
|
|
||||||
let tornadoPossible = alert.properties.parameters.tornadoDetection[0]
|
|
||||||
return tornadoPossible === "POSSIBLE"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (tstp.length > 0) {
|
|
||||||
tornado_possible = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter for considerable destructive severe thunderstorm warnings
|
|
||||||
|
|
||||||
let cdst = alerts.filter(function(alert) {
|
|
||||||
if (alert.properties &&
|
|
||||||
alert.properties.event === "Considerable Destructive Severe Thunderstorm Warning") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (cdst.length > 0) {
|
|
||||||
considerable_destructive = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter for Tornado Warnings
|
|
||||||
|
|
||||||
let tornado = alerts.filter(function(alert) {
|
|
||||||
if (alert.properties &&
|
|
||||||
tornadoWarningEvents.includes(alert.properties.event)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
let confirmed_tornado = alerts.filter(function(alert) {
|
|
||||||
if (alert.properties &&
|
|
||||||
alert.properties.event === "Confirmed Tornado Warning") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (confirmed_tornado.length > 0) {
|
|
||||||
confirmed = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter for Tornado Watches
|
|
||||||
|
|
||||||
let tornado_watch = alerts.filter(function(alert) {
|
|
||||||
if (alert.properties &&
|
|
||||||
tornadoWatchEvents.includes(alert.properties.event)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Filter for Severe Thunderstorm Watches
|
|
||||||
|
|
||||||
let severe_thunderstorm_watch = alerts.filter(function(alert) {
|
|
||||||
if (alert.properties &&
|
|
||||||
severeThunderstormWatchEvents.includes(alert.properties.event)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// If there are any alerts, return them
|
|
||||||
|
|
||||||
let allAlerts = {
|
|
||||||
"payload": msg.payload.features,
|
|
||||||
"topic": allTopic
|
|
||||||
}
|
|
||||||
|
|
||||||
let tstormMsg = {
|
|
||||||
"payload": {
|
|
||||||
"alerts": ts,
|
|
||||||
"count": ts.length,
|
|
||||||
"tornado_possible": tornado_possible,
|
|
||||||
"considerable_destructive": considerable_destructive
|
|
||||||
},
|
|
||||||
"topic": tstormTopic
|
|
||||||
}
|
|
||||||
|
|
||||||
let tornadoWarnMsg = {
|
|
||||||
"payload": {
|
|
||||||
"alerts": tornado,
|
|
||||||
"count": tornado.length,
|
|
||||||
"confirmed": confirmed
|
|
||||||
},
|
|
||||||
"topic": tornadoWarnTopic
|
|
||||||
}
|
|
||||||
|
|
||||||
let tornadoWatchMsg = {
|
|
||||||
"payload": {
|
|
||||||
"alerts": tornado_watch,
|
|
||||||
"count": tornado_watch.length
|
|
||||||
},
|
|
||||||
"topic": tornadoWatchTopic
|
|
||||||
}
|
|
||||||
|
|
||||||
let severeThunderstormWatchMsg = {
|
|
||||||
"payload": {
|
|
||||||
"alerts": severe_thunderstorm_watch,
|
|
||||||
"count": severe_thunderstorm_watch.length
|
|
||||||
},
|
|
||||||
"topic": severeThunderstormWatchTopic
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create status message for node
|
|
||||||
|
|
||||||
let statusMsg = {
|
|
||||||
"status": {
|
|
||||||
"fill": "green",
|
|
||||||
"shape": "dot",
|
|
||||||
"text": `${alerts.length} alerts processed at ${new Date().toLocaleString()}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send messages to output nodes
|
|
||||||
|
|
||||||
node.send([allAlerts,tstormMsg,tornadoWarnMsg,tornadoWatchMsg,severeThunderstormWatchMsg,statusMsg])
|
|
@ -1,17 +0,0 @@
|
|||||||
const states = global.get('homeassistant.homeAssistant.states')
|
|
||||||
const precipType = states['sensor.home_tempest_precipitation_type'].state
|
|
||||||
const precipIntensity = states['sensor.home_tempest_cloud_sensors_precipitation_intensity'].state
|
|
||||||
|
|
||||||
const typeStatesRaining = ['rain','hail','rain_hail']
|
|
||||||
const intensityStatesRaining = ['very_light','light','moderate','heavy','very_heavy','extreme']
|
|
||||||
|
|
||||||
const isTypeRaining = typeStatesRaining.includes(precipType)
|
|
||||||
const isIntensityRaining = intensityStatesRaining.includes(precipIntensity)
|
|
||||||
|
|
||||||
const isRaining = isTypeRaining || isIntensityRaining
|
|
||||||
|
|
||||||
flow.set('typeStatesRaining', typeStatesRaining)
|
|
||||||
flow.set('intensityStatesRaining', intensityStatesRaining)
|
|
||||||
flow.set('isRaining', isRaining)
|
|
||||||
|
|
||||||
return null
|
|
@ -1,41 +0,0 @@
|
|||||||
const states = global.get('homeassistant.homeAssistant.states')
|
|
||||||
const temp_F = states['sensor.home_tempest_temperature'].state
|
|
||||||
const elevation_ft = 693
|
|
||||||
|
|
||||||
// Get the pressure from the payload
|
|
||||||
let pressure_inHg = msg.payload
|
|
||||||
|
|
||||||
if (isNaN(pressure_inHg)) {
|
|
||||||
node.error("Invalid pressure value in msg.payload: " + msg.payload)
|
|
||||||
msg.payload = null
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert pressure from inHg to hPa
|
|
||||||
let pressure_hPa = pressure_inHg * 33.8639
|
|
||||||
|
|
||||||
// Convert temperature to °C
|
|
||||||
let temp_C = (temp_F - 32) * (5 / 9)
|
|
||||||
|
|
||||||
// Convert elevation from feet to meters
|
|
||||||
let elevation_m = elevation_ft / 3.28084
|
|
||||||
|
|
||||||
// Apply the barometric formula
|
|
||||||
let slp = pressure_hPa * Math.pow(
|
|
||||||
1 - ((0.0065 * elevation_m) / (temp_C + (0.0065 * elevation_m) + 273.15)),
|
|
||||||
-5.257
|
|
||||||
)
|
|
||||||
|
|
||||||
// Optional: Convert back to inHg
|
|
||||||
let slp_inHg = slp / 33.8639
|
|
||||||
|
|
||||||
// Round both values
|
|
||||||
slp = Math.round(slp * 100) / 100
|
|
||||||
slp_inHg = Math.round(slp_inHg * 100) / 100
|
|
||||||
|
|
||||||
// Return the SLP value
|
|
||||||
msg.payload = slp_inHg
|
|
||||||
|
|
||||||
node.status({fill:'Success',shape:'dot',text:'green'})
|
|
||||||
|
|
||||||
return msg
|
|
Reference in New Issue
Block a user