diff --git a/lightfx/processing-start.js b/lightfx/processing-start.js index 98490db..386efef 100644 --- a/lightfx/processing-start.js +++ b/lightfx/processing-start.js @@ -1,3 +1,4 @@ +const states = global.get('homeassistant.homeAssistant.states') // Set some constants for all of the lights // Half and half for living room LED strip @@ -10,6 +11,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 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 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] @@ -20,6 +28,29 @@ const segBasement2 = [8,9,10,11,12,13,14,15] const segBasement3 = [16,17,18,19,20,21,22,23] 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" +] + +// Room scene options +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 + +// Write flow variables flow.set("halfLivingRoom1", halfLivingRoom1, "diskCon") flow.set("halfLivingRoom2", halfLivingRoom1, "diskCon") @@ -28,6 +59,11 @@ flow.set("segLivingRoom2", segLivingRoom2, "diskCon") flow.set("segLivingRoom3", segLivingRoom3, "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("halfBasement2", halfBasement1, "diskCon") @@ -35,3 +71,15 @@ flow.set("segBasement1", segBasement1, "diskCon") flow.set("segBasement2", segBasement2, "diskCon") flow.set("segBasement3", segBasement3, "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("scenesLivingRoom", scenesLivingRoom, "diskCon") +flow.set("scenesBasement", scenesBasement, "diskCon") +flow.set("scenesTinaDesk", scenesTinaDesk, "diskCon") diff --git a/lightfx/processing.js b/lightfx/processing.js index e63fa15..b46616c 100644 --- a/lightfx/processing.js +++ b/lightfx/processing.js @@ -1,36 +1,131 @@ const states = global.get('homeassistant.homeAssistant.states') 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 diningRoomState = states["light.dining_room_lamp"].state -const basementState = states["light.basement_studio_lights"].state -const where = msg.payload.event.where -const type = msg.payload.event.type +const stateTinaDesk = states["light.tina_desk_lights"].state +const stateLivingRoom = states["light.living_room_lights"].state +const stateDiningRoom = states["light.dining_room_lamp"].state +const stateBasement = states["light.basement_studio_lights"].state +const adaptLivingRoom = states["switch.adaptive_lighting_living_room"].state +const adaptBasement = states["switch.adaptive_lighting_basement_studio"].state +const nightLivingRoom = states["switch.adaptive_lighting_sleep_mode_living_room"].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 effectBasement = msg.payload.event.basement +const effectFirstFloor = msg.payload.event.first_floor +const effectType = msg.payload.event.type +const effectDivide = msg.payload.event.divide const duration = msg.payload.event.duration +const delay = duration * 1000 +const adaptiveSwitchFirstFloor = flow.get("adaptiveFirstFloor") +const adaptiveSwitchBasement = flow.get("adaptiveBasement") + +//! Use delay in service calls, not duration + +flow.set("currentSceneBasement", currentSceneBasement) +flow.set("currentSceneLivingRoom", currentSceneLivingRoom) +flow.set("currentSceneTinaDesk", currentSceneTinaDesk) +flow.set("adaptLivingRoom", adaptLivingRoom) +flow.set("adaptBasement", adaptBasement) +flow.set("nightLivingRoom", nightLivingRoom) +flow.set("nightBasement", nightBasement) +flow.set("stateTinaDesk", stateTinaDesk) +flow.set("stateLivingRoom", stateLivingRoom) +flow.set("stateDiningRoom", stateDiningRoom) +flow.set("stateBasement", stateBasement) let firstFloorLights = [] let basementLights = [] +let basement1 = [] +let basement2 = [] +let basementFull = [] +let livingRoom1 = [] +let livingRoom2 = [] +let livingRoomFull = [] -if (deskState === 'on') { +if (stateTinaDesk === 'on') { firstFloorLights.push('light.tina_desk_strip','light.tina_lamp_top','light.tina_lamp_side') } -if (livingRoomState === 'on') { +if (stateLivingRoom === 'on') { firstFloorLights.push('light.living_room_color_1','light.living_room_color_2','light.living_room_color_3','light.living_room_led_strip') } -if (diningRoomState === 'on') { +if (stateDiningRoom === 'on') { firstFloorLights.push('light.dining_room_lamp') } -if (basementState === 'on') { +if (stateBasement === '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("diningRoomState", diningRoomState) -flow.set("basementState", basementState) +if (effectDivide === 'half') { + basement1 = flow.get("halfBasement1") + basement2 = flow.get("halfBasement2") + livingRoom1 = flow.get("halfLivingRoom1") + livingRoom2 = flow.get("halfLivingRoom2") +} else if (effectDivide === 'quarter') { + basement1 = flow.get("effectSegBasement1") + basement2 = flow.get("effectSegBasement2") + livingRoom1 = flow.get("effectSegLivingRoom1") + livingRoom2 = flow.get("effectSegLivingRoom2") +} else if (effectDivide === 'full') { + basementFull = flow.get("basementFull") + livingRoomFull = flow.get("livingRoomFull") +} -// let segLivingRoom = [].concat(segLivingRoom1, segLivingRoom2) +//! Implement setting of colors here + +// Set message payloads +let sendBasementStrip1 = { + "payload": { + "domain": "lifx", + "service": "set_state", + "target": { + "entity_id": ["light.basement_led_strip_1"] + }, + "data": { + "zones": basement1 + } + } +} + +let sendBasementStrip2 = { + "payload": { + "domain": "lifx", + "service": "set_state", + "target": { + "entity_id": ["light.basement_led_strip_1"] + }, + "data": { + "zones": basement2 + } + } +} + +let sendLivingRoomStrip1 = { + "payload": { + "domain": "lifx", + "service": "set_state", + "target": { + "entity_id": ["light.living_room_led_strip"] + }, + "data": { + "zones": livingRoom1 + } + } +} + +let sendLivingRoomStrip2 = { + "payload": { + "domain": "lifx", + "service": "set_state", + "target": { + "entity_id": ["light.living_room_led_strip"] + }, + "data": { + "zones": livingRoom2 + } + } +}