Most of the effect and restore flow is now working
This commit is contained in:
303
lightfx/reset.js
303
lightfx/reset.js
@ -3,30 +3,313 @@ 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)
|
||||
|
||||
let sendDebug = {
|
||||
"scenesLivingRoom": scenesLivingRoom,
|
||||
"scenesBasement": scenesBasement,
|
||||
"scenesTinaDesk": scenesTinaDesk,
|
||||
"definedLivingRoom": definedLivingRoom,
|
||||
"definedBasement": definedBasement,
|
||||
"definedTinaDesk": definedTinaDesk
|
||||
// Define variables
|
||||
let setSceneLivingRoom = []
|
||||
let setSceneTinaDesk = []
|
||||
let setSceneBasement = []
|
||||
let setSceneDiningRoom = []
|
||||
let setServiceLivingRoom = []
|
||||
let setServiceTinaDesk = []
|
||||
let setServiceDiningRoom = []
|
||||
let setServiceBasement = []
|
||||
let restoreLivingRoom = {}
|
||||
let restoreTinaDesk = {}
|
||||
let restoreBasement = {}
|
||||
let inputTexts = []
|
||||
|
||||
// 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'
|
||||
inputTexts.push('input_text.living_room_selected_scene')
|
||||
}
|
||||
} else {
|
||||
restoreLivingRoom = 'off'
|
||||
setServiceLivingRoom = 'turn_off'
|
||||
inputTexts.push('input_text.living_room_selected_scene')
|
||||
}
|
||||
|
||||
node.send([sendDebug,null,null,null])
|
||||
node.status({fill:"green",shape:"dot",text:"Success"})
|
||||
if (stateTinaDesk === 'on') {
|
||||
setServiceTinaDesk = 'turn_on'
|
||||
if (definedTinaDesk === true) {
|
||||
restoreTinaDesk = 'defined'
|
||||
setSceneTinaDesk = currentSceneTinaDesk
|
||||
} else {
|
||||
restoreTinaDesk = 'adaptive'
|
||||
setSceneTinaDesk = 'Reset'
|
||||
}
|
||||
} else {
|
||||
restoreTinaDesk = 'off'
|
||||
setServiceTinaDesk = 'turn_off'
|
||||
inputTexts.push('input_text.tina_desk_selected_scene')
|
||||
}
|
||||
|
||||
if (stateDiningRoom === 'on') {
|
||||
setServiceDiningRoom = 'turn_on'
|
||||
if (nightDiningRoom === 'on') {
|
||||
setSceneDiningRoom = 'Nightlight'
|
||||
} else {
|
||||
setSceneDiningRoom = 'Adaptive'
|
||||
}
|
||||
} else {
|
||||
setServiceDiningRoom = 'turn_off'
|
||||
inputTexts.push('input_text.dining_room_lamp_selected_scene')
|
||||
}
|
||||
|
||||
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'
|
||||
inputTexts.push('input_text.basement_studio_selected_scene')
|
||||
}
|
||||
} else {
|
||||
restoreBasement = 'off'
|
||||
setServiceBasement = 'turn_off'
|
||||
inputTexts.push('input_text.basement_studio_selected_scene')
|
||||
}
|
||||
|
||||
// Define messages
|
||||
let sendInputTexts = {
|
||||
"payload": {
|
||||
"domain": "input_text",
|
||||
"service": "set_value",
|
||||
"target": {
|
||||
"entity_id": inputTexts
|
||||
},
|
||||
"data": "Adaptive"
|
||||
}
|
||||
}
|
||||
|
||||
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 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 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,null])
|
||||
} else {
|
||||
node.send([sendSceneLivingRoom,null,null,null,null])
|
||||
}
|
||||
|
||||
if (restoreTinaDesk === 'backup') {
|
||||
node.send([null,sendRestoreTinaDesk,null,null,null])
|
||||
} else {
|
||||
node.send([null,sendSceneTinaDesk,null,null,null])
|
||||
}
|
||||
|
||||
if (stateDiningRoom === 'off') {
|
||||
node.send([null,null,sendStateDiningRoom,null,null])
|
||||
} else {
|
||||
node.send([null,null,sendSceneDiningRoomLamp,null,null])
|
||||
}
|
||||
|
||||
if (restoreBasement === 'backup') {
|
||||
node.send([null,null,null,restoreBasement,null])
|
||||
} else {
|
||||
node.send([null,null,null,sendSceneBasement,null])
|
||||
}
|
||||
|
||||
if (stateStairwell === 'on') {
|
||||
node.send([sendStairwellScript,null,null,null,null])
|
||||
} else {
|
||||
node.send([sendStairwellOff,null,null,null,null])
|
||||
}
|
||||
|
||||
node.send([null,null,null,null,sendInputTexts])
|
Reference in New Issue
Block a user