57 lines
1.9 KiB
JavaScript
57 lines
1.9 KiB
JavaScript
const states = global.get('homeassistant.homeAssistant.states')
|
|
const allowed = states["binary_sensor.audible_weather_alerts_allowed"].state
|
|
const occupied = states["binary_sensor.basement_occupied"].state
|
|
const quiet = states["input_boolean.studio_quiet"].state
|
|
const deskState = states["light.tina_desk_lights"].state
|
|
const livingRoomState = states["light.living_room_lights"].state
|
|
const basementState = states["light.basement_studio_lights"].state
|
|
const who = states["binary_sensor.audible_weather_alerts_allowed"].attributes.location
|
|
const duration = msg.duration
|
|
const payload = msg.payload
|
|
|
|
let firstFloorLights = []
|
|
let basementLights = []
|
|
|
|
if (deskState === 'on') {
|
|
firstFloorLights.push('light.tina_lamp_top','light.tina_lamp_side')
|
|
}
|
|
|
|
if (livingRoomState === 'on') {
|
|
firstFloorLights.push('light.living_room_color_1','light.living_room_color_2','light.living_room_color_3','light.living_room_led_strip')
|
|
}
|
|
|
|
if (basementState === 'on') {
|
|
basementLights.push('light.basement_tall_lamp','light.basement_short_lamp','light.basement_stairwell','light.basement_led_strip_1')
|
|
}
|
|
|
|
flow.set("deskState", deskState)
|
|
flow.set("livingRoomState", livingRoomState)
|
|
flow.set("basementState", basementState)
|
|
|
|
let firstFloorMsg = {
|
|
"payload": payload,
|
|
"duration": duration,
|
|
"backup": firstFloorLights,
|
|
"who": who
|
|
}
|
|
|
|
let basementMsg = {
|
|
"payload": payload,
|
|
"duration": duration,
|
|
"backup": basementLights
|
|
}
|
|
|
|
if (allowed === 'on') {
|
|
if (occupied === 'on' && quiet === 'off') {
|
|
flow.set("basementTrigger","true")
|
|
node.status({fill:"green",shape:"dot",text:"Both"})
|
|
return[firstFloorMsg,basementMsg]
|
|
} else {
|
|
flow.set("basementTrigger","false")
|
|
node.status({fill:"green",shape:"dot",text:"Living Room"})
|
|
return[firstFloorMsg,null]
|
|
}
|
|
} else {
|
|
node.status({fill:"red",shape:"ring",text:"Blocked"})
|
|
return null
|
|
} |