Progress made on setting the necessary variables for lighting effects

This commit is contained in:
2023-10-16 14:15:09 -04:00
parent 3349a315d7
commit c1373fc084

View File

@ -1052,7 +1052,9 @@
"f463df7e17e045e9" "f463df7e17e045e9"
], ],
"x": 34, "x": 34,
"y": 19 "y": 19,
"w": 1272,
"h": 502
}, },
{ {
"id": "208284848b13b85b", "id": "208284848b13b85b",
@ -1160,7 +1162,9 @@
"f5fb96bf1a33b3cd" "f5fb96bf1a33b3cd"
], ],
"x": 54, "x": 54,
"y": 19 "y": 19,
"w": 1492,
"h": 282
}, },
{ {
"id": "0c81dfaed25d225c", "id": "0c81dfaed25d225c",
@ -1194,7 +1198,9 @@
"37bdac2c9a4e2837" "37bdac2c9a4e2837"
], ],
"x": 54, "x": 54,
"y": 39 "y": 39,
"w": 1652,
"h": 382
}, },
{ {
"id": "8aee4d340a136bac", "id": "8aee4d340a136bac",
@ -1437,7 +1443,9 @@
"99c141f21de4feda" "99c141f21de4feda"
], ],
"x": 74, "x": 74,
"y": 39 "y": 39,
"w": 1132,
"h": 262
}, },
{ {
"id": "a6de35af12739885", "id": "a6de35af12739885",
@ -1459,7 +1467,9 @@
"724f186878227dad" "724f186878227dad"
], ],
"x": 74, "x": 74,
"y": 339 "y": 339,
"w": 1132,
"h": 202
}, },
{ {
"id": "0804d9edeca1c9fa", "id": "0804d9edeca1c9fa",
@ -1480,7 +1490,9 @@
"4523045453de0a33" "4523045453de0a33"
], ],
"x": 74, "x": 74,
"y": 579 "y": 579,
"w": 1092,
"h": 202
}, },
{ {
"id": "385f03591bc34bcc", "id": "385f03591bc34bcc",
@ -1559,7 +1571,9 @@
"8146f43fea5aec03" "8146f43fea5aec03"
], ],
"x": 34, "x": 34,
"y": 539 "y": 539,
"w": 1192,
"h": 502
}, },
{ {
"id": "b9ffa3fa5af46ec3", "id": "b9ffa3fa5af46ec3",
@ -1575,7 +1589,9 @@
"6b5d3e550ad76528" "6b5d3e550ad76528"
], ],
"x": 34, "x": 34,
"y": 39 "y": 39,
"w": 692,
"h": 82
}, },
{ {
"id": "4329e464360d0afa", "id": "4329e464360d0afa",
@ -13832,26 +13848,32 @@
"type": "function", "type": "function",
"z": "ce9c810396e540b6", "z": "ce9c810396e540b6",
"name": "Processing", "name": "Processing",
"func": "const states = global.get('homeassistant.homeAssistant.states')\nconst occupied = states[\"binary_sensor.basement_occupied\"].state\nconst quiet = states[\"input_boolean.studio_quiet\"].state\nconst deskState = states[\"light.tina_desk_lights\"].state\nconst livingRoomState = states[\"light.living_room_lights\"].state\nconst diningRoomState = states[\"light.dining_room_lamp\"].state\nconst basementState = states[\"light.basement_studio_lights\"].state\nconst where = msg.payload.event.where\nconst type = msg.payload.event.type\nconst duration = msg.payload.event.duration\n\nlet firstFloorLights = []\nlet basementLights = []\n\nif (deskState === 'on') {\n firstFloorLights.push('light.tina_desk_strip','light.tina_lamp_top','light.tina_lamp_side')\n}\n\nif (livingRoomState === '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 (diningRoomState === 'on') {\n firstFloorLights.push('light.dining_room_lamp')\n}\n\nif (basementState === 'on') {\n basementLights.push('light.basement_tall_lamp','light.basement_short_lamp','light.basement_stairwell','light.basement_led_strip_1')\n}\n\nflow.set(\"deskState\", deskState)\nflow.set(\"livingRoomState\", livingRoomState)\nflow.set(\"diningRoomState\", diningRoomState)\nflow.set(\"basementState\", basementState)\n\n// let segLivingRoom = [].concat(segLivingRoom1, segLivingRoom2)\n", "func": "const 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\")\nconst adaptiveSwitchBasement = flow.get(\"adaptiveBasement\")\n\n//! Use delay in service calls, not duration\n\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\nlet firstFloorLights = []\nlet basementLights = []\nlet basement1 = []\nlet basement2 = []\nlet basementFull = []\nlet livingRoom1 = []\nlet livingRoom2 = []\nlet livingRoomFull = []\n\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\nif (effectDivide === 'half') {\n basement1 = flow.get(\"halfBasement1\")\n basement2 = flow.get(\"halfBasement2\")\n livingRoom1 = flow.get(\"halfLivingRoom1\")\n livingRoom2 = flow.get(\"halfLivingRoom2\")\n} else if (effectDivide === 'quarter') {\n basement1 = flow.get(\"effectSegBasement1\")\n basement2 = flow.get(\"effectSegBasement2\")\n livingRoom1 = flow.get(\"effectSegLivingRoom1\")\n livingRoom2 = flow.get(\"effectSegLivingRoom2\")\n} else if (effectDivide === 'full') {\n basementFull = flow.get(\"basementFull\")\n livingRoomFull = flow.get(\"livingRoomFull\")\n}\n\n//! Implement setting of colors here\n\n// Set message payloads\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 }\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 }\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 }\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 }\n }\n}\n",
"outputs": 4, "outputs": 6,
"timeout": 0, "timeout": 0,
"noerr": 0, "noerr": 0,
"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// 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\nflow.set(\"halfLivingRoom1\", halfLivingRoom1, \"diskCon\")\nflow.set(\"halfLivingRoom2\", halfLivingRoom1, \"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(\"halfBasement1\", halfBasement1, \"diskCon\")\nflow.set(\"halfBasement2\", halfBasement1, \"diskCon\")\n\nflow.set(\"segBasement1\", segBasement1, \"diskCon\")\nflow.set(\"segBasement2\", segBasement2, \"diskCon\")\nflow.set(\"segBasement3\", segBasement3, \"diskCon\")\nflow.set(\"segBasement4\", segBasement4, \"diskCon\")\n", "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\", halfLivingRoom1, \"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\", halfBasement1, \"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",
"finalize": "", "finalize": "",
"libs": [], "libs": [],
"x": 430, "x": 430,
"y": 280, "y": 300,
"wires": [ "wires": [
[], [],
[], [],
[], [],
[],
[
"4165ae582e799463"
],
[] []
], ],
"outputLabels": [ "outputLabels": [
"Backup",
"First Floor", "First Floor",
"Tina Desk", "Tina Desk",
"Dining Room", "Dining Room",
"Basement" "Basement",
"Reset"
], ],
"icon": "font-awesome/fa-bolt" "icon": "font-awesome/fa-bolt"
}, },
@ -13905,8 +13927,8 @@
"mustacheAltTags": false, "mustacheAltTags": false,
"outputProperties": [], "outputProperties": [],
"queue": "none", "queue": "none",
"x": 750, "x": 310,
"y": 200, "y": 80,
"wires": [ "wires": [
[] []
] ]
@ -13941,10 +13963,46 @@
"y": 280, "y": 280,
"wires": [ "wires": [
[ [
"9932b8210843f84e" "9932b8210843f84e",
"70925e3cac1396e1"
] ]
] ]
}, },
{
"id": "4165ae582e799463",
"type": "api-call-service",
"z": "ce9c810396e540b6",
"name": "Basement Effect",
"server": "9e87348d.9c1c48",
"version": 5,
"debugenabled": false,
"domain": "",
"service": "",
"areaId": [],
"deviceId": [],
"entityId": [],
"data": "",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 680,
"y": 320,
"wires": [
[]
]
},
{
"id": "335639590303cd1c",
"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",
"x": 500,
"y": 440,
"wires": []
},
{ {
"id": "7611921cadb91b1e", "id": "7611921cadb91b1e",
"type": "api-call-service", "type": "api-call-service",