From 5dba2190b54bbafbafc6319eb81b99ec34fbe66d Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Tue, 17 Oct 2023 18:47:35 -0400 Subject: [PATCH] Starting to work on post-alert restoration --- flows.json | 73 +++++++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 42 deletions(-) diff --git a/flows.json b/flows.json index f41055c..4fcb398 100644 --- a/flows.json +++ b/flows.json @@ -1575,9 +1575,7 @@ "6b5d3e550ad76528" ], "x": 34, - "y": 39, - "w": 692, - "h": 82 + "y": 39 }, { "id": "4329e464360d0afa", @@ -1620,9 +1618,7 @@ "f47a0d107875d550" ], "x": 34, - "y": 139, - "w": 1592, - "h": 422 + "y": 139 }, { "id": "395da9d5d5f7e232", @@ -13836,11 +13832,11 @@ "type": "function", "z": "ce9c810396e540b6", "name": "Processing", - "func": "// Set constants\nconst states = global.get('homeassistant.homeAssistant.states')\nconst occupied = states[\"binary_sensor.basement_occupied\"].state\nconst quiet = states[\"input_boolean.studio_quiet\"].state\nconst stateTinaDesk = states[\"light.tina_desk_lights\"].state\nconst stateLivingRoom = states[\"light.living_room_lights\"].state\nconst stateDiningRoom = states[\"light.dining_room_lamp\"].state\nconst stateBasement = states[\"light.basement_studio_lights\"].state\nconst adaptLivingRoom = states[\"switch.adaptive_lighting_living_room\"].state\nconst adaptBasement = states[\"switch.adaptive_lighting_basement_studio\"].state\nconst nightLivingRoom = states[\"switch.adaptive_lighting_sleep_mode_living_room\"].state\nconst nightBasement = states[\"switch.adaptive_lighting_sleep_mode_basement_studio\"].state\nconst currentSceneBasement = states[\"input_text.basement_studio_selected_scene\"].state\nconst currentSceneLivingRoom = states[\"input_text.living_room_selected_scene\"].state\nconst currentSceneTinaDesk = states[\"input_text.tina_desk_selected_scene\"].state\nconst effectBasement = msg.payload.event.basement\nconst effectFirstFloor = msg.payload.event.first_floor\nconst effectType = msg.payload.event.type\nconst effectDivide = msg.payload.event.divide\nconst duration = msg.payload.event.duration\nconst delay = duration * 1000\nconst adaptiveSwitchFirstFloor = flow.get(\"adaptiveFirstFloor\", \"diskCon\")\nconst adaptiveSwitchBasement = flow.get(\"adaptiveBasement\", \"diskCon\")\n\n// Set flow contexts to be used later in the reset node\nflow.set(\"currentSceneBasement\", currentSceneBasement)\nflow.set(\"currentSceneLivingRoom\", currentSceneLivingRoom)\nflow.set(\"currentSceneTinaDesk\", currentSceneTinaDesk)\nflow.set(\"adaptLivingRoom\", adaptLivingRoom)\nflow.set(\"adaptBasement\", adaptBasement)\nflow.set(\"nightLivingRoom\", nightLivingRoom)\nflow.set(\"nightBasement\", nightBasement)\nflow.set(\"stateTinaDesk\", stateTinaDesk)\nflow.set(\"stateLivingRoom\", stateLivingRoom)\nflow.set(\"stateDiningRoom\", stateDiningRoom)\nflow.set(\"stateBasement\", stateBasement)\n\n// Define empty arrays for backup scenes\nlet firstFloorLights = []\nlet basementLights = []\n// Define empty arrays for basement LED strip zones\nlet basement1 = []\nlet basement2 = []\nlet basementFull = []\n// Define empty arrays for living room LED strip zones\nlet livingRoom1 = []\nlet livingRoom2 = []\nlet livingRoomFull = []\n// Color names are set by default, however certain effects can override them below\nlet colorName1 = effectType\nlet colorName2 = \"white\"\n\n// Get lights to add to the backup scenes\nif (stateTinaDesk === 'on') {\n firstFloorLights.push('light.tina_desk_strip','light.tina_lamp_top','light.tina_lamp_side')\n}\n\nif (stateLivingRoom === 'on') {\n firstFloorLights.push('light.living_room_color_1','light.living_room_color_2','light.living_room_color_3','light.living_room_led_strip')\n}\n\nif (stateDiningRoom === 'on') {\n firstFloorLights.push('light.dining_room_lamp')\n}\n\nif (stateBasement === 'on') {\n basementLights.push('light.basement_tall_lamp','light.basement_short_lamp','light.basement_stairwell','light.basement_led_strip_1')\n}\n\n// Setup the proper zones to use for the effect\nif (effectDivide === 'half') {\n basement1 = flow.get(\"halfBasement1\", \"diskCon\")\n basement2 = flow.get(\"halfBasement2\", \"diskCon\")\n livingRoom1 = flow.get(\"halfLivingRoom1\", \"diskCon\")\n livingRoom2 = flow.get(\"halfLivingRoom2\", \"diskCon\")\n} else if (effectDivide === 'quarter') {\n basement1 = flow.get(\"effectSegBasement1\", \"diskCon\")\n basement2 = flow.get(\"effectSegBasement2\", \"diskCon\")\n livingRoom1 = flow.get(\"effectSegLivingRoom1\", \"diskCon\")\n livingRoom2 = flow.get(\"effectSegLivingRoom2\", \"diskCon\")\n} else if (effectDivide === 'full') {\n basementFull = flow.get(\"basementFull\", \"diskCon\")\n livingRoomFull = flow.get(\"livingRoomFull\", \"diskCon\")\n}\n\n// Set/change colors if necessary\nif (effectType === 'police') {\n colorName1 = 'red'\n colorName2 = 'blue'\n}\n\n// Set message payloads\nlet sendBasementStripFX = {\n \"payload\": {\n \"domain\": \"lifx\",\n \"service\": \"effect_move\",\n \"target\": {\n \"entity_id\": [\"light.basement_led_strip_1\"]\n },\n \"data\": {\n \"speed\": 0.5,\n \"direction\": \"right\",\n \"power_on\": false\n }\n }\n}\n\nlet sendBasementStrip1 = {\n \"payload\": {\n \"domain\": \"lifx\",\n \"service\": \"set_state\",\n \"target\": {\n \"entity_id\": [\"light.basement_led_strip_1\"]\n },\n \"data\": {\n \"zones\": basement1,\n \"color_name\": colorName1,\n \"brightness\": 255\n }\n }\n}\n\nlet sendBasementStrip2 = {\n \"payload\": {\n \"domain\": \"lifx\",\n \"service\": \"set_state\",\n \"target\": {\n \"entity_id\": [\"light.basement_led_strip_1\"]\n },\n \"data\": {\n \"zones\": basement2,\n \"color_name\": colorName2,\n \"brightness\": 255,\n \"power\": true\n }\n }\n}\n\nlet sendBasementLights = {\n \"payload\": {\n \"domain\": \"light\",\n \"service\": \"turn_on\",\n \"target\": {\n \"entity_id\": [\n \"light.basement_tall_lamp\",\n \"light.basement_short_lamp\",\n \"light.basement_stairwell\"\n ]\n },\n \"data\": {\n \"color_name\": colorName1,\n \"brightness\": 255\n }\n }\n}\n\nlet sendLivingRoomStripFX = {\n \"payload\": {\n \"domain\": \"lifx\",\n \"service\": \"effect_move\",\n \"target\": {\n \"entity_id\": [\"light.living_room_led_strip\"]\n },\n \"data\": {\n \"speed\": 0.5,\n \"direction\": \"right\",\n \"power_on\": false\n }\n }\n}\n\nlet sendLivingRoomStrip1 = {\n \"payload\": {\n \"domain\": \"lifx\",\n \"service\": \"set_state\",\n \"target\": {\n \"entity_id\": [\"light.living_room_led_strip\"]\n },\n \"data\": {\n \"zones\": livingRoom1,\n \"color_name\": colorName1,\n \"brightness\": 255\n }\n }\n}\n\nlet sendLivingRoomStrip2 = {\n \"payload\": {\n \"domain\": \"lifx\",\n \"service\": \"set_state\",\n \"target\": {\n \"entity_id\": [\"light.living_room_led_strip\"]\n },\n \"data\": {\n \"zones\": livingRoom2,\n \"color_name\": colorName2,\n \"brightness\": 255\n }\n }\n}\n\nlet sendLivingRoomLights = {\n \"payload\": {\n \"domain\": \"light\",\n \"service\": \"turn_on\",\n \"target\": {\n \"entity_id\": [\n \"light.living_room_color_1\",\n \"light.living_room_color_2\",\n \"light.living_room_color_3\"\n ]\n },\n \"data\": {\n \"color_name\": colorName1,\n \"brightness\": 255\n }\n }\n}\n\nlet sendTinaDeskLights = {\n \"payload\": {\n \"domain\": \"light\",\n \"service\": \"turn_on\",\n \"target\": {\n \"entity_id\": [\"light.tina_desk_lights\"]\n },\n \"data\": {\n \"color_name\": colorName1,\n \"brightness\": 255\n }\n }\n}\n\nlet sendDiningRoomLamp = {\n \"payload\": {\n \"domain\": \"light\",\n \"service\": \"turn_off\",\n \"target\": {\n \"entity_id\": [\"light.dining_room_lamp\"]\n },\n \"data\": {}\n }\n}\n\nlet sendReset = {\n \"delay\": delay\n}\n\n// Send effect messages\nif (effectBasement === true) {\n node.send([null,null,null,null,[sendBasementStripFX,sendBasementLights,sendBasementStrip1,sendBasementStrip2],null])\n}\n\nif (effectFirstFloor === true) {\n node.send([null,[sendLivingRoomStripFX,sendLivingRoomLights,sendLivingRoomStrip1,sendLivingRoomStrip2],sendTinaDeskLights,sendDiningRoomLamp,null,null])\n}\n\n// Send the reset message to start the timer\nnode.send([null,null,null,null,null,sendReset])", + "func": "// Set constants\nconst states = global.get('homeassistant.homeAssistant.states')\nconst occupied = states[\"binary_sensor.basement_occupied\"].state\nconst quiet = states[\"input_boolean.studio_quiet\"].state\nconst stateTinaDesk = states[\"light.tina_desk_lights\"].state\nconst stateLivingRoom = states[\"light.living_room_lights\"].state\nconst stateDiningRoom = states[\"light.dining_room_lamp\"].state\nconst stateStairwell = states[\"light.stairwell_led_strip\"].state\nconst stateBasement = states[\"light.basement_studio_lights\"].state\nconst adaptLivingRoom = states[\"switch.adaptive_lighting_living_room\"].state\nconst adaptBasement = states[\"switch.adaptive_lighting_basement_studio\"].state\nconst nightLivingRoom = states[\"switch.adaptive_lighting_sleep_mode_living_room\"].state\nconst nightBasement = states[\"switch.adaptive_lighting_sleep_mode_basement_studio\"].state\nconst currentSceneBasement = states[\"input_text.basement_studio_selected_scene\"].state\nconst currentSceneLivingRoom = states[\"input_text.living_room_selected_scene\"].state\nconst currentSceneTinaDesk = states[\"input_text.tina_desk_selected_scene\"].state\nconst effectBasement = msg.payload.event.basement\nconst effectFirstFloor = msg.payload.event.first_floor\nconst effectType = msg.payload.event.type\nconst effectDivide = msg.payload.event.divide\nconst duration = msg.payload.event.duration\nconst delay = duration * 1000\nconst adaptiveSwitchFirstFloor = flow.get(\"adaptiveFirstFloor\", \"diskCon\")\nconst adaptiveSwitchBasement = flow.get(\"adaptiveBasement\", \"diskCon\")\n\n// Set flow contexts to be used later in the reset node\nflow.set(\"currentSceneBasement\", currentSceneBasement)\nflow.set(\"currentSceneLivingRoom\", currentSceneLivingRoom)\nflow.set(\"currentSceneTinaDesk\", currentSceneTinaDesk)\nflow.set(\"adaptLivingRoom\", adaptLivingRoom)\nflow.set(\"adaptBasement\", adaptBasement)\nflow.set(\"nightLivingRoom\", nightLivingRoom)\nflow.set(\"nightBasement\", nightBasement)\nflow.set(\"stateTinaDesk\", stateTinaDesk)\nflow.set(\"stateLivingRoom\", stateLivingRoom)\nflow.set(\"stateDiningRoom\", stateDiningRoom)\nflow.set(\"stateStairwell\", stateStairwell)\nflow.set(\"stateBasement\", stateBasement)\n\n// Define empty arrays for backup scenes\nlet firstFloorLights = []\nlet basementLights = []\n// Define empty arrays for basement LED strip zones\nlet basement1 = []\nlet basement2 = []\nlet basementFull = []\n// Define empty arrays for living room LED strip zones\nlet livingRoom1 = []\nlet livingRoom2 = []\nlet livingRoomFull = []\n// Color names are set by default, however certain effects can override them below\nlet colorName1 = effectType\nlet colorName2 = \"white\"\n\n// Get lights to add to the backup scenes\n//! We need to change this from one entire first floor scene to individual room scenes\nif (stateTinaDesk === 'on') {\n firstFloorLights.push('light.tina_desk_strip','light.tina_lamp_top','light.tina_lamp_side')\n}\n\nif (stateLivingRoom === 'on') {\n firstFloorLights.push('light.living_room_color_1','light.living_room_color_2','light.living_room_color_3','light.living_room_led_strip')\n}\n\nif (stateDiningRoom === 'on') {\n firstFloorLights.push('light.dining_room_lamp')\n}\n\nif (stateStairwell === 'on') {\n firstFloorLights.push('light.stairwell_led_strip')\n}\n\nif (stateBasement === 'on') {\n basementLights.push('light.basement_tall_lamp','light.basement_short_lamp','light.basement_stairwell','light.basement_led_strip_1')\n}\n\n// Setup the proper zones to use for the effect\nif (effectDivide === 'half') {\n basement1 = flow.get(\"halfBasement1\", \"diskCon\")\n basement2 = flow.get(\"halfBasement2\", \"diskCon\")\n livingRoom1 = flow.get(\"halfLivingRoom1\", \"diskCon\")\n livingRoom2 = flow.get(\"halfLivingRoom2\", \"diskCon\")\n} else if (effectDivide === 'quarter') {\n basement1 = flow.get(\"effectSegBasement1\", \"diskCon\")\n basement2 = flow.get(\"effectSegBasement2\", \"diskCon\")\n livingRoom1 = flow.get(\"effectSegLivingRoom1\", \"diskCon\")\n livingRoom2 = flow.get(\"effectSegLivingRoom2\", \"diskCon\")\n} else if (effectDivide === 'full') {\n basementFull = flow.get(\"basementFull\", \"diskCon\")\n livingRoomFull = flow.get(\"livingRoomFull\", \"diskCon\")\n}\n\n// Set/change colors if necessary\nif (effectType === 'police') {\n colorName1 = 'red'\n colorName2 = 'blue'\n}\n\n// Set message payloads\nlet sendBasementStripFX = {\n \"payload\": {\n \"domain\": \"lifx\",\n \"service\": \"effect_move\",\n \"target\": {\n \"entity_id\": [\"light.basement_led_strip_1\"]\n },\n \"data\": {\n \"speed\": 0.5,\n \"direction\": \"right\",\n \"power_on\": false\n }\n }\n}\n\nlet sendBasementStrip1 = {\n \"payload\": {\n \"domain\": \"lifx\",\n \"service\": \"set_state\",\n \"target\": {\n \"entity_id\": [\"light.basement_led_strip_1\"]\n },\n \"data\": {\n \"zones\": basement1,\n \"color_name\": colorName1,\n \"brightness\": 255\n }\n }\n}\n\nlet sendBasementStrip2 = {\n \"payload\": {\n \"domain\": \"lifx\",\n \"service\": \"set_state\",\n \"target\": {\n \"entity_id\": [\"light.basement_led_strip_1\"]\n },\n \"data\": {\n \"zones\": basement2,\n \"color_name\": colorName2,\n \"brightness\": 255,\n \"power\": true\n }\n }\n}\n\nlet sendBasementLights = {\n \"payload\": {\n \"domain\": \"light\",\n \"service\": \"turn_on\",\n \"target\": {\n \"entity_id\": [\n \"light.basement_tall_lamp\",\n \"light.basement_short_lamp\",\n \"light.basement_stairwell\"\n ]\n },\n \"data\": {\n \"color_name\": colorName1,\n \"brightness\": 255\n }\n }\n}\n\nlet sendLivingRoomStripFX = {\n \"payload\": {\n \"domain\": \"lifx\",\n \"service\": \"effect_move\",\n \"target\": {\n \"entity_id\": [\"light.living_room_led_strip\"]\n },\n \"data\": {\n \"speed\": 0.5,\n \"direction\": \"right\",\n \"power_on\": false\n }\n }\n}\n\nlet sendLivingRoomStrip1 = {\n \"payload\": {\n \"domain\": \"lifx\",\n \"service\": \"set_state\",\n \"target\": {\n \"entity_id\": [\"light.living_room_led_strip\"]\n },\n \"data\": {\n \"zones\": livingRoom1,\n \"color_name\": colorName1,\n \"brightness\": 255\n }\n }\n}\n\nlet sendLivingRoomStrip2 = {\n \"payload\": {\n \"domain\": \"lifx\",\n \"service\": \"set_state\",\n \"target\": {\n \"entity_id\": [\"light.living_room_led_strip\"]\n },\n \"data\": {\n \"zones\": livingRoom2,\n \"color_name\": colorName2,\n \"brightness\": 255,\n \"power\": true\n }\n }\n}\n\nlet sendLivingRoomLights = {\n \"payload\": {\n \"domain\": \"light\",\n \"service\": \"turn_on\",\n \"target\": {\n \"entity_id\": [\n \"light.living_room_color_1\",\n \"light.living_room_color_2\",\n \"light.living_room_color_3\"\n ]\n },\n \"data\": {\n \"color_name\": colorName1,\n \"brightness\": 255\n }\n }\n}\n\nlet sendTinaDeskLights = {\n \"payload\": {\n \"domain\": \"light\",\n \"service\": \"turn_on\",\n \"target\": {\n \"entity_id\": [\"light.tina_desk_lights\"]\n },\n \"data\": {\n \"color_name\": colorName1,\n \"brightness\": 255\n }\n }\n}\n\nlet sendDiningRoomLamp = {\n \"payload\": {\n \"domain\": \"light\",\n \"service\": \"turn_off\",\n \"target\": {\n \"entity_id\": [\"light.dining_room_lamp\"]\n },\n \"data\": {}\n }\n}\n\nlet sendAdaptiveFirstFloor = {\n \"payload\": {\n \"domain\": \"switch\",\n \"service\": \"turn_off\",\n \"target\": {\n \"entity_id\": adaptiveSwitchFirstFloor\n },\n \"data\": {}\n }\n}\n\nlet sendAdaptiveBasement = {\n \"payload\": {\n \"domain\": \"switch\",\n \"service\": \"turn_off\",\n \"target\": {\n \"entity_id\": adaptiveSwitchBasement\n },\n \"data\": {}\n }\n}\n\nlet backupFirstFloor = {\n \"payload\": {\n \"domain\": \"scene\",\n \"service\": \"create\",\n \"data\": {\n \"scene_id\": \"first_floor_alert_restore\",\n \"snapshot_entities\": firstFloorLights\n }\n }\n}\n\nlet backupBasement = {\n \"payload\": {\n \"domain\": \"scene\",\n \"service\": \"create\",\n \"data\": {\n \"scene_id\": \"basement_alert_restore\",\n \"snapshot_entities\": basementLights\n }\n }\n}\n\nlet sendReset = {\n \"delay\": delay\n}\n\nif (stateLivingRoom === 'on' && currentSceneLivingRoom != 'Alert') {\n node.send([[backupFirstFloor],null,null,null,null,null])\n}\n\nif (stateBasement === 'on' && currentSceneBasement != 'Alert') {\n node.send([[backupBasement],null,null,null,null,null])\n}\n\n// Send effect messages\nif (effectBasement === true) {\n node.send([null,null,null,null,[sendBasementStripFX,sendBasementLights,sendBasementStrip1,sendBasementStrip2],null])\n}\n\nif (effectFirstFloor === true) {\n node.send([null,[sendLivingRoomStripFX,sendLivingRoomLights,sendLivingRoomStrip1,sendLivingRoomStrip2],sendTinaDeskLights,sendDiningRoomLamp,null,null])\n}\n\n// Send the reset message to start the timer\nnode.send([null,null,null,null,null,sendReset])", "outputs": 6, "timeout": 0, "noerr": 0, - "initialize": "const states = global.get('homeassistant.homeAssistant.states')\n// Set some constants for all of the lights\n\n// Half and half for living room LED strip\nconst halfLivingRoom1 = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]\nconst halfLivingRoom2 = [20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39]\n\n// Quarters for living room LED strip\nconst segLivingRoom1 = [0,1,2,3,4,5,6,7,8,9]\nconst segLivingRoom2 = [10,11,12,13,14,15,16,17,18,19]\nconst segLivingRoom3 = [20,21,22,23,24,25,26,27,28,29]\nconst segLivingRoom4 = [30,31,32,33,34,35,36,37,38,39]\n\n// Preset effect segments for living room LED strip\nconst effectSegLivingRoom1 = [].concat(segLivingRoom1, segLivingRoom3)\nconst effectSegLivingRoom2 = [].concat(segLivingRoom2, segLivingRoom4)\n\n// Full strip for living room LED strip\nconst livingRoomFull = [].concat(halfLivingRoom1, halfLivingRoom2)\n\n// Half and half for basement LED strip\nconst halfBasement1 = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]\nconst halfBasement2 = [16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]\n\n// Quarters for basement LED strip\nconst segBasement1 = [0,1,2,3,4,5,6,7]\nconst segBasement2 = [8,9,10,11,12,13,14,15]\nconst segBasement3 = [16,17,18,19,20,21,22,23]\nconst segBasement4 = [24,25,26,27,28,29,30,31]\n\n// Preset effect segments for basement LED strip\nconst effectSegBasement1 = [].concat(segBasement1, segBasement3)\nconst effectSegBasement2 = [].concat(segBasement2, segBasement4)\n\n// Full strip for basement LED strip\nconst basementFull = [].concat(halfBasement1, halfBasement2)\n\n// Adaptive Lighting switches\nconst adaptiveFirstFloor = [\n \"switch.adaptive_lighting_living_room\",\n \"switch.adaptive_lighting_dining_room_lamp\",\n \"switch.adaptive_lighting_tina_lamp\"]\n\nconst adaptiveBasement = [\n \"switch.adaptive_lighting_basement_studio\"\n]\n\n// Room scene options\nconst scenesLivingRoom = states[\"input_select.living_room_scenes\"].attributes.options\nconst scenesBasement = states[\"input_select.basement_studio_scenes\"].attributes.options\nconst scenesTinaDesk = states[\"input_select.tina_desk_scenes\"].attributes.options\n\n// Write flow variables\nflow.set(\"halfLivingRoom1\", halfLivingRoom1, \"diskCon\")\nflow.set(\"halfLivingRoom2\", halfLivingRoom2, \"diskCon\")\n\nflow.set(\"segLivingRoom1\", segLivingRoom1, \"diskCon\")\nflow.set(\"segLivingRoom2\", segLivingRoom2, \"diskCon\")\nflow.set(\"segLivingRoom3\", segLivingRoom3, \"diskCon\")\nflow.set(\"segLivingRoom4\", segLivingRoom4, \"diskCon\")\n\nflow.set(\"effectSegLivingRoom1\", effectSegLivingRoom1, \"diskCon\")\nflow.set(\"effectSegLivingRoom2\", effectSegLivingRoom2, \"diskCon\")\n\nflow.set(\"livingRoomFull\", livingRoomFull, \"diskCon\")\n\nflow.set(\"halfBasement1\", halfBasement1, \"diskCon\")\nflow.set(\"halfBasement2\", halfBasement2, \"diskCon\")\n\nflow.set(\"segBasement1\", segBasement1, \"diskCon\")\nflow.set(\"segBasement2\", segBasement2, \"diskCon\")\nflow.set(\"segBasement3\", segBasement3, \"diskCon\")\nflow.set(\"segBasement4\", segBasement4, \"diskCon\")\n\nflow.set(\"effectSegBasement1\", effectSegBasement1, \"diskCon\")\nflow.set(\"effectSegBasement2\", effectSegBasement2, \"diskCon\")\n\nflow.set(\"basementFull\", basementFull, \"diskCon\")\n\nflow.set(\"adaptiveFirstFloor\", adaptiveFirstFloor, \"diskCon\")\nflow.set(\"adaptiveBasement\", adaptiveBasement, \"diskCon\")\n\nflow.set(\"scenesLivingRoom\", scenesLivingRoom, \"diskCon\")\nflow.set(\"scenesBasement\", scenesBasement, \"diskCon\")\nflow.set(\"scenesTinaDesk\", scenesTinaDesk, \"diskCon\")\n", + "initialize": "// Set some constants for all of the lights\n\n// Half and half for living room LED strip\nconst halfLivingRoom1 = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]\nconst halfLivingRoom2 = [20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39]\n\n// Quarters for living room LED strip\nconst segLivingRoom1 = [0,1,2,3,4,5,6,7,8,9]\nconst segLivingRoom2 = [10,11,12,13,14,15,16,17,18,19]\nconst segLivingRoom3 = [20,21,22,23,24,25,26,27,28,29]\nconst segLivingRoom4 = [30,31,32,33,34,35,36,37,38,39]\n\n// Preset effect segments for living room LED strip\nconst effectSegLivingRoom1 = [].concat(segLivingRoom1, segLivingRoom3)\nconst effectSegLivingRoom2 = [].concat(segLivingRoom2, segLivingRoom4)\n\n// Full strip for living room LED strip\nconst livingRoomFull = [].concat(halfLivingRoom1, halfLivingRoom2)\n\n// Half and half for basement LED strip\nconst halfBasement1 = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]\nconst halfBasement2 = [16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]\n\n// Quarters for basement LED strip\nconst segBasement1 = [0,1,2,3,4,5,6,7]\nconst segBasement2 = [8,9,10,11,12,13,14,15]\nconst segBasement3 = [16,17,18,19,20,21,22,23]\nconst segBasement4 = [24,25,26,27,28,29,30,31]\n\n// Preset effect segments for basement LED strip\nconst effectSegBasement1 = [].concat(segBasement1, segBasement3)\nconst effectSegBasement2 = [].concat(segBasement2, segBasement4)\n\n// Full strip for basement LED strip\nconst basementFull = [].concat(halfBasement1, halfBasement2)\n\n// Adaptive Lighting switches\nconst adaptiveFirstFloor = [\n \"switch.adaptive_lighting_living_room\",\n \"switch.adaptive_lighting_dining_room_lamp\",\n \"switch.adaptive_lighting_tina_lamp\"]\n\nconst adaptiveBasement = [\n \"switch.adaptive_lighting_basement_studio\"\n]\n\n// Write flow variables\nflow.set(\"halfLivingRoom1\", halfLivingRoom1, \"diskCon\")\nflow.set(\"halfLivingRoom2\", halfLivingRoom2, \"diskCon\")\n\nflow.set(\"segLivingRoom1\", segLivingRoom1, \"diskCon\")\nflow.set(\"segLivingRoom2\", segLivingRoom2, \"diskCon\")\nflow.set(\"segLivingRoom3\", segLivingRoom3, \"diskCon\")\nflow.set(\"segLivingRoom4\", segLivingRoom4, \"diskCon\")\n\nflow.set(\"effectSegLivingRoom1\", effectSegLivingRoom1, \"diskCon\")\nflow.set(\"effectSegLivingRoom2\", effectSegLivingRoom2, \"diskCon\")\n\nflow.set(\"livingRoomFull\", livingRoomFull, \"diskCon\")\n\nflow.set(\"halfBasement1\", halfBasement1, \"diskCon\")\nflow.set(\"halfBasement2\", halfBasement2, \"diskCon\")\n\nflow.set(\"segBasement1\", segBasement1, \"diskCon\")\nflow.set(\"segBasement2\", segBasement2, \"diskCon\")\nflow.set(\"segBasement3\", segBasement3, \"diskCon\")\nflow.set(\"segBasement4\", segBasement4, \"diskCon\")\n\nflow.set(\"effectSegBasement1\", effectSegBasement1, \"diskCon\")\nflow.set(\"effectSegBasement2\", effectSegBasement2, \"diskCon\")\n\nflow.set(\"basementFull\", basementFull, \"diskCon\")\n\nflow.set(\"adaptiveFirstFloor\", adaptiveFirstFloor, \"diskCon\")\nflow.set(\"adaptiveBasement\", adaptiveBasement, \"diskCon\")\n", "finalize": "", "libs": [], "x": 430, @@ -13875,35 +13871,6 @@ ], "icon": "font-awesome/fa-bolt" }, - { - "id": "523ee0d4f375eb6b", - "type": "inject", - "z": "ce9c810396e540b6", - "name": "", - "props": [ - { - "p": "payload" - }, - { - "p": "topic", - "vt": "str" - } - ], - "repeat": "", - "crontab": "", - "once": false, - "onceDelay": 0.1, - "topic": "", - "payload": "", - "payloadType": "date", - "x": 240, - "y": 340, - "wires": [ - [ - "70925e3cac1396e1" - ] - ] - }, { "id": "b38f12483048e1ac", "type": "api-call-service", @@ -13958,7 +13925,7 @@ ], "event_type": "", "x": 220, - "y": 280, + "y": 300, "wires": [ [ "9932b8210843f84e", @@ -13998,7 +13965,7 @@ "type": "comment", "z": "ce9c810396e540b6", "name": "Things still to implement from yaml script", - "info": "If current scene is a defined scene, take note of it\n\nIf the lights are on, and another alert isn't being interrupted, create a backup scene to restore at the end\n\nDefine variable for restoration of the current scene if the backup is not needed\n\nIf the lights were off, turn them back off\n\nIf the lights were in night mode, put them back to it\n\nIf the lights were in adaptive, put them back to it\n\nIf the current scene was a defined scene, activate that scene\n\nOtherwise, restore the backup scene from above\n\nCleanup", + "info": "If current scene is a defined scene, take note of it\n\nDefine variable for restoration of the current scene if the backup is not needed\n\nIf the lights were off, turn them back off\n\nIf the lights were in night mode, put them back to it\n\nIf the lights were in adaptive, put them back to it\n\nIf the current scene was a defined scene, activate that scene\n\nOtherwise, restore the backup scene from above\n\nCleanup", "x": 260, "y": 540, "wires": [] @@ -14159,7 +14126,7 @@ "type": "function", "z": "ce9c810396e540b6", "name": "Reset", - "func": "// Set constants\nconst states = global.get('homeassistant.homeAssistant.states')\nconst currentSceneBasement = flow.get('currentSceneBasement')\nconst currentSceneLivingRoom = flow.get('currentSceneLivingRoom')\nconst currentSceneTinaDesk = flow.get('currentSceneTinaDesk')\nconst adaptLivingRoom = flow.get('adaptLivingRoom')\nconst adaptBasement = flow.get('adaptBasement')\nconst nightLivingRoom = flow.get('nightLivingRoom')\nconst nightBasement = flow.get('nightBasement')\nconst stateTinaDesk = flow.get('stateTinaDesk')\nconst stateLivingRoom = flow.get('stateLivingRoom')\nconst stateDiningRoom = flow.get('stateDiningRoom')\nconst stateBasement = flow.get('stateBasement')\nconst scenesLivingRoom = flow.get('scenesLivingRoom', 'diskCon')\nconst scenesBasement = flow.get('scenesBasement', 'diskCon')\nconst scenesTinaDesk = flow.get('scenesTinaDesk', 'diskCon')\n\n// Reset code goes here\n\nnode.status({fill:\"green\",shape:\"dot\",text:\"Success\"})", + "func": "// Set constants\nconst states = global.get('homeassistant.homeAssistant.states')\nconst currentSceneBasement = flow.get('currentSceneBasement')\nconst currentSceneLivingRoom = flow.get('currentSceneLivingRoom')\nconst currentSceneTinaDesk = flow.get('currentSceneTinaDesk')\nconst adaptLivingRoom = flow.get('adaptLivingRoom')\nconst adaptBasement = flow.get('adaptBasement')\nconst nightLivingRoom = flow.get('nightLivingRoom')\nconst nightBasement = flow.get('nightBasement')\nconst stateTinaDesk = flow.get('stateTinaDesk')\nconst stateLivingRoom = flow.get('stateLivingRoom')\nconst stateDiningRoom = flow.get('stateDiningRoom')\nconst stateBasement = flow.get('stateBasement')\nconst scenesLivingRoom = states[\"input_select.living_room_scenes\"].attributes.options\nconst scenesBasement = states[\"input_select.basement_studio_scenes\"].attributes.options\nconst scenesTinaDesk = states[\"input_select.tina_desk_scenes\"].attributes.options\n\nconst definedLivingRoom = scenesLivingRoom.includes(currentSceneLivingRoom)\nconst definedBasement = scenesBasement.includes(currentSceneBasement)\nconst definedTinaDesk = scenesTinaDesk.includes(currentSceneTinaDesk)\n\nlet sendDebug = {\n \"scenesLivingRoom\": scenesLivingRoom,\n \"scenesBasement\": scenesBasement,\n \"scenesTinaDesk\": scenesTinaDesk,\n \"definedLivingRoom\": definedLivingRoom,\n \"definedBasement\": definedBasement,\n \"definedTinaDesk\": definedTinaDesk\n}\n\nnode.send([sendDebug,null,null,null])\nnode.status({fill:\"green\",shape:\"dot\",text:\"Success\"})", "outputs": 4, "timeout": 0, "noerr": 0, @@ -14169,7 +14136,9 @@ "x": 410, "y": 420, "wires": [ - [], + [ + "f41a46f3aa27ac1b" + ], [], [], [] @@ -14179,7 +14148,8 @@ "Tina Desk", "Dining Room", "Basement" - ] + ], + "icon": "node-red-contrib-actionflows/loopflow.png" }, { "id": "fa1e1b2739ff28f5", @@ -14249,6 +14219,23 @@ "y": 160, "wires": [] }, + { + "id": "f41a46f3aa27ac1b", + "type": "debug", + "z": "ce9c810396e540b6", + "name": "Temp Debug", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "true", + "targetType": "full", + "statusVal": "", + "statusType": "auto", + "x": 670, + "y": 460, + "wires": [] + }, { "id": "7611921cadb91b1e", "type": "api-call-service", @@ -24118,6 +24105,7 @@ "name": "Events Today", "func": "const states = global.get('homeassistant.homeAssistant.states')\nconst teams = flow.get(\"teams\", \"diskCon\")\nlet teamsToday = []\nlet options = []\n\nfor (let index = 0; index < teams.length; index++) {\n const element = teams[index];\n let sensor = \"sensor.\" + element\n let binary_today = \"binary_sensor.\" + element + \"_event_today\"\n let binary_inhibit = \"binary_sensor.\" + element + \"_inhibit\"\n let today = states[binary_today].state\n let inhibit = states[binary_inhibit].state\n let teamName = states[sensor].attributes.friendly_name\n if (today === 'on' && inhibit === 'off') {\n teamsToday.push(teamName)\n }\n}\n\nflow.set(\"teamsToday\", teamsToday, \"diskCon\")\n\nif (teamsToday.length > 0) {\n options = teamsToday\n node.status({fill:\"green\",shape:\"dot\",text:\"Events today: \" + teamsToday.length})\n} else {\n options = ['No events today']\n node.status({fill:\"red\",shape:\"ring\",text:\"No events today\"});\n}\n\nmsg.payload = {\n \"options\": options\n}\n\nnode.send(msg)\nnode.done", "outputs": 1, + "timeout": "", "noerr": 0, "initialize": "", "finalize": "", @@ -24205,6 +24193,7 @@ "name": "Scores", "func": "// Get sensor\nconst states = global.get('homeassistant.homeAssistant.states')\nconst active = states['switch.watching_sports'].state\n\nif (active === 'on') {\n // Get scores\n const team = flow.get(\"team\", \"diskCon\")\n const teamSensor = states[\"sensor.\" + team]\n const status = teamSensor.state\n if (status === 'IN') {\n const teamScore = teamSensor.attributes.team_score\n const oppScore = teamSensor.attributes.opponent_score\n msg = {\n \"teamscore\": teamScore,\n \"oppscore\": oppScore\n }\n node.status({ fill: \"green\", shape: \"dot\", text: \"Score: \" + teamScore + \"-\" + oppScore })\n node.send(msg)\n } else {\n node.status({ fill: \"red\", shape: \"ring\", text: \"Not in game\" })\n }\n} else {\n node.status({ fill: \"red\", shape: \"ring\", text: \"Inactive\" })\n}", "outputs": 1, + "timeout": "", "noerr": 0, "initialize": "", "finalize": "",