From f66b93ab324af7b869544981a4d8eaa3e1e96952 Mon Sep 17 00:00:00 2001 From: makefu Date: Tue, 18 Jan 2022 09:38:28 +0100 Subject: tint_wohnzimmer: refactor --- makefu/2configs/home/ham/light/tint_wohnzimmer.nix | 49 +++++++++++++++------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/makefu/2configs/home/ham/light/tint_wohnzimmer.nix b/makefu/2configs/home/ham/light/tint_wohnzimmer.nix index c9aeb850..3811972e 100644 --- a/makefu/2configs/home/ham/light/tint_wohnzimmer.nix +++ b/makefu/2configs/home/ham/light/tint_wohnzimmer.nix @@ -15,32 +15,39 @@ # {% endif -%} let + # effect - color + # Solid Pattern - Hult group_id_1 = 16388; group_id_2 = 16389; group_id_3 = 16390; - remote = "sensor.schlafzimmer_remote1_action"; - main_light_1 = "light.wled"; - default_scene_1 = "Solid"; - default_color_1 = "Default"; - main_color_select_1 = "select.wled_color_palette"; - light_group_1 = { entity_id = [ main_light_1 ];}; + # main_light_1 = "light.wled"; + # default_scene_1 = "Solid"; + # default_color_1 = "Default"; + # main_color_select_1 = "select.wled_color_palette"; # contains only the actually changeable lights - light_group_2 = { entity_id = [ - "light.wohnzimmer_komode_osram" - "light.wohnzimmer_schrank_osram" - "light.wohnzimmer_fenster_lichterkette_licht" - ]; - }; - light_group_3 = { entity_id = [ "light.wohnzimmer_stehlampe_osram" ]; }; statecond = cond: { # cond must be a list condition = "template"; value_template = "{{ trigger.to_state.attributes.action in ( " + (lib.concatMapStringsSep "," (x: "'${x}'") cond) + ") }}"; - }; -in { - services.home-assistant.config.automation = [ + }; + + # The remote manages WLED on ID1, and basic lights on ID2 and ID3 + tint_remote = { remote + , wled_name_1 + , lights_2 ? [] + , lights_3 ? [] + , main_light_1 ? "light.${wled_name_1}" + , main_color_select_1 ? "select.${wled_name_1}_color_plaette" + , default_scene_1 ? "Solid" + , default_color_1 ? "Default" + }: + let + light_group_1.entity_id = [ main_light_1 ]; + light_group_2.entity_id = lights_2; + light_group_3.entity_id = lights_2; + in { alias = "Perform Actions with ${remote}"; mode = "queued"; @@ -288,5 +295,15 @@ in { } ]; } + + ; +in { + services.home-assistant.config.automation = [ + (tint_remote { + remote = "sensor.schlafzimmer_remote1_action"; + wled_name_1 = "wled"; + lights_2 = [ "light.wohnzimmer_komode_osram" "light.wohnzimmer_schrank_osram" "light.wohnzimmer_fenster_lichterkette_licht" ]; + lights_3 = [ "light.wohnzimmer_stehlampe_osram" ]; + }) ]; } -- cgit v1.2.3 From ef48f536a3e539b215bb004b512e62c2d0f96907 Mon Sep 17 00:00:00 2001 From: makefu Date: Thu, 20 Jan 2022 23:48:09 +0100 Subject: ma ham: init tint remote control for arbeitszimmer --- makefu/2configs/home/ham/light/arbeitszimmer.nix | 13 +- .../2configs/home/ham/light/tint_arbeitszimmer.nix | 278 +++++++++++++++++++++ makefu/2configs/home/ham/light/tint_wohnzimmer.nix | 51 ++-- makefu/2configs/home/ham/light/wohnzimmer.nix | 7 + 4 files changed, 305 insertions(+), 44 deletions(-) create mode 100644 makefu/2configs/home/ham/light/tint_arbeitszimmer.nix diff --git a/makefu/2configs/home/ham/light/arbeitszimmer.nix b/makefu/2configs/home/ham/light/arbeitszimmer.nix index 45fbfb57..6e572c76 100644 --- a/makefu/2configs/home/ham/light/arbeitszimmer.nix +++ b/makefu/2configs/home/ham/light/arbeitszimmer.nix @@ -10,6 +10,8 @@ let "light.arbeitszimmer_pflanzenlicht" ]; in { + imports = [ ./tint_arbeitszimmer.nix ]; + services.home-assistant.config.light = [ { platform = "group"; @@ -27,16 +29,5 @@ in { } ]; services.home-assistant.config.automation = [ - { - alias = "Toggle Arbeitszimmerbeleuchtung via Remote"; - trigger = { - platform = "state"; - entity_id = "sensor.arbeitszimmer_remote1_action"; - }; - action = { - service = "light.toggle"; - data.entity_id = "light.arbeitszimmerbeleuchtung"; - }; - } ]; } diff --git a/makefu/2configs/home/ham/light/tint_arbeitszimmer.nix b/makefu/2configs/home/ham/light/tint_arbeitszimmer.nix new file mode 100644 index 00000000..37c961ad --- /dev/null +++ b/makefu/2configs/home/ham/light/tint_arbeitszimmer.nix @@ -0,0 +1,278 @@ +{ lib, ...}: + +let + # effect - color + # Solid Pattern - Hult + group_id_1 = 16388; + group_id_2 = 16389; + group_id_3 = 16390; + remote = "sensor.arbeitszimmer_remote1_action"; + main_light_1 = "light.wled_4"; + default_scene_1 = "Solid"; + default_color_1 = "Default"; + main_color_select_1 = "select.wled_color_palette_4"; + light_group_1 = { entity_id = [ main_light_1 ];}; + + # contains only the actually changeable lights + light_group_2 = { entity_id = [ + "light.arbeitszimmer_schrank_dimmer" + ]; + }; + light_group_3 = { entity_id = [ "light.arbeitszimmer_pflanzenlicht" ]; }; + + statecond = cond: { # cond must be a list + condition = "template"; + value_template = "{{ trigger.to_state.attributes.action in ( " + + (lib.concatMapStringsSep "," (x: "'${x}'") cond) + ") }}"; + }; +in { + services.home-assistant.config.automation = [ + { + alias = "Perform Actions with ${remote}"; + mode = "queued"; + max = 5; + max_exceeded = "silent"; + trigger = { + platform = "state"; + entity_id = remote; + }; + condition = { + condition = "and"; + conditions = [ + { + condition = "template"; + value_template = "{{ trigger.from_state.state != trigger.to_state.state }}"; + } + ( statecond [ "off" "on" "color_wheel" + "brightness_up_click" "brightness_down_click" + "color_temp" "color_temperature_move" + "brightness_step_down" "brightness_step_up" "brightness_down_hold" "brightness_down_release" "brightness_up_hold" "brightness_up_release" + "scene_3" "scene_1" "scene_2" # working sunset party + "scene_6" "scene_4" "scene_5" # night campfire romantic + ]) + ]; + }; + action = [ + { service = "system_log.write"; + data = { + level = "info"; + message = "Tint Button pressed: {{ trigger.to_state.state }} Group: {{ trigger.to_state.attributes.action_group }} Length {{ input_working_scene_1 | length }}"; + }; + } + { + choose = [ + { # light group 1 + conditions = { + condition = "template"; + value_template = "{{ trigger.to_state.attributes.action_group == ${toString group_id_1} }}"; + }; + sequence = [ + { + choose = [ + { + conditions = statecond [ "on" "off" ]; + sequence = { + service = "light.turn_{{ trigger.to_state.state }}"; + target = light_group_1; + }; + } + { + conditions = statecond [ "color_wheel" ]; + sequence = { + data.xy_color = [ + "{{ trigger.to_state.attributes.action_color.x | float }}" + "{{ trigger.to_state.attributes.action_color.y | float }}" + ]; + service = "light.turn_on"; + target = light_group_1; + }; + } + { + conditions = statecond [ "color_temp" ]; + sequence = { + data.color_temp = "{{ trigger.to_state.attributes.action_color_temperature | float }}"; + service = "light.turn_on"; + target = light_group_1; + }; + } + { + conditions = statecond [ "brightness_up_click" "brightness_down_click" ]; + sequence = [ + { + variables.factor = ''{% if trigger.to_state.state in ( "brightness_down_click") %} -12 {% else %} 12 {% endif %}''; + } + { + data.brightness_step_pct = "{{ factor | int }}"; + service = "light.turn_on"; + target = light_group_1; + } + ]; + } + { + conditions = statecond [ + "scene_3" # working => previous scene + "scene_1" # sunset => default scene (solid) + "scene_2" # party => next scene + + ]; + sequence = [ + { + data.effect = '' + {% set options = state_attr("${main_light_1}","effect_list") -%} + {% set selection = options.index(state_attr("${main_light_1}","effect")) -%} + {% if trigger.to_state.attributes.action == "scene_2" -%} + {% if (selection + 1) >= options | length -%} + {{ options[0] }} + {% else -%} + {{ options[selection + 1] }} + {% endif %} + {% elif trigger.to_state.attributes.action == "scene_1" -%} + ${default_scene_1} + {% elif trigger.to_state.attributes.action == "scene_3" -%} + {{ options[selection - 1] }} + {% endif -%} + ''; + service = "light.turn_on"; + target.entity_id = main_light_1; + } + ]; + } + { + conditions = statecond [ + "scene_6" # night => previous color + "scene_4" # campfire => default Color (Default) + "scene_5" # romance => next color + + ]; + sequence = [ + { + data.option = '' + {% set options = state_attr("${main_color_select_1}","options") -%} + {% set selection = options.index(states("${main_color_select_1}")) -%} + {% if trigger.to_state.attributes.action == "scene_5" -%} + {% if (selection + 1) >= options | length -%} + {{ options[0] }} + {% else -%} + {{ options[selection + 1] }} + {% endif %} + {% elif trigger.to_state.attributes.action == "scene_4" -%} + ${default_color_1} + {% elif trigger.to_state.attributes.action == "scene_6" -%} + {{ options[selection - 1] }} + {% endif -%} + ''; + service = "select.select_option"; + target.entity_id = main_color_select_1; + } + ]; + } + ]; + } + ]; + } + { # light group 2 + conditions = { + condition = "template"; + value_template = "{{ trigger.to_state.attributes.action_group == ${toString group_id_2} }}"; + }; + sequence = [ + { + choose = [ + { conditions = statecond [ "on" "off" ]; + sequence = { + service = "light.turn_{{ trigger.to_state.state }}"; + target = light_group_2; + }; + } + { + conditions = statecond [ "color_wheel" ]; + sequence = { + data.xy_color = [ + "{{ trigger.to_state.attributes.action_color.x | float }}" + "{{ trigger.to_state.attributes.action_color.y | float }}" + ]; + service = "light.turn_on"; + target = light_group_2; + }; + } + { + conditions = statecond [ "color_temp" ]; + sequence = { + data.color_temp = "{{ trigger.to_state.attributes.action_color_temperature | float }}"; + service = "light.turn_on"; + target = light_group_2; + }; + } + { + conditions = statecond [ "brightness_up_click" "brightness_down_click" ]; + sequence = [ + { + variables.factor = ''{% if trigger.to_state.state in ( "brightness_down_click") %} -12 {% else %} 12 {% endif %}''; + } + { + data.brightness_step_pct = "{{ factor | int }}"; + service = "light.turn_on"; + target = light_group_2; + } + ]; + } + ]; + } + ]; + } + { # light group 3 + conditions = { + condition = "template"; + value_template = "{{ trigger.to_state.attributes.action_group == ${toString group_id_3} }}"; + }; + sequence = [ + { + choose = [ + { conditions = statecond [ "on" "off" ]; + sequence = { + service = "light.turn_{{ trigger.to_state.state }}"; + target = light_group_3; + }; + } + { + conditions = statecond [ "color_wheel" ]; + sequence = { + data.xy_color = [ + "{{ trigger.to_state.attributes.action_color.x | float }}" + "{{ trigger.to_state.attributes.action_color.y | float }}" + ]; + service = "light.turn_on"; + target = light_group_3; + }; + } + { + conditions = statecond [ "color_temperature_move" ]; + sequence = { + data.color_temp = "{{ trigger.to_state.attributes.action_color_temperature | float }}"; + service = "light.turn_on"; + target = light_group_3; + }; + } + { + conditions = statecond [ "brightness_up_click" "brightness_down_click" ]; + sequence = [ + { + variables.factor = ''{% if trigger.to_state.state in ( "brightness_down_click") %} -12 {% else %} 12 {% endif %}''; + } + { + data.brightness_step_pct = "{{ factor | int }}"; + service = "light.turn_on"; + target = light_group_3; + } + ]; + } + ]; + } + ]; + } + ]; + } + ]; + } + ]; +} diff --git a/makefu/2configs/home/ham/light/tint_wohnzimmer.nix b/makefu/2configs/home/ham/light/tint_wohnzimmer.nix index 3811972e..18e69a77 100644 --- a/makefu/2configs/home/ham/light/tint_wohnzimmer.nix +++ b/makefu/2configs/home/ham/light/tint_wohnzimmer.nix @@ -15,39 +15,34 @@ # {% endif -%} let - # effect - color - # Solid Pattern - Hult + # Solid Pattern + # Hult group_id_1 = 16388; group_id_2 = 16389; group_id_3 = 16390; - # main_light_1 = "light.wled"; - # default_scene_1 = "Solid"; - # default_color_1 = "Default"; - # main_color_select_1 = "select.wled_color_palette"; + remote = "sensor.schlafzimmer_remote1_action"; + main_light_1 = "light.wled"; + default_scene_1 = "Solid"; + default_color_1 = "Default"; + main_color_select_1 = "select.wled_color_palette"; + light_group_1 = { entity_id = [ main_light_1 ];}; # contains only the actually changeable lights + light_group_2 = { entity_id = [ + "light.wohnzimmer_komode_osram" + "light.wohnzimmer_schrank_osram" + "light.wohnzimmer_fenster_lichterkette_licht" + ]; + }; + light_group_3 = { entity_id = [ "light.wohnzimmer_stehlampe_osram" ]; }; statecond = cond: { # cond must be a list condition = "template"; value_template = "{{ trigger.to_state.attributes.action in ( " + (lib.concatMapStringsSep "," (x: "'${x}'") cond) + ") }}"; - }; - - # The remote manages WLED on ID1, and basic lights on ID2 and ID3 - tint_remote = { remote - , wled_name_1 - , lights_2 ? [] - , lights_3 ? [] - , main_light_1 ? "light.${wled_name_1}" - , main_color_select_1 ? "select.${wled_name_1}_color_plaette" - , default_scene_1 ? "Solid" - , default_color_1 ? "Default" - }: - let - light_group_1.entity_id = [ main_light_1 ]; - light_group_2.entity_id = lights_2; - light_group_3.entity_id = lights_2; - in + }; +in { + services.home-assistant.config.automation = [ { alias = "Perform Actions with ${remote}"; mode = "queued"; @@ -295,15 +290,5 @@ let } ]; } - - ; -in { - services.home-assistant.config.automation = [ - (tint_remote { - remote = "sensor.schlafzimmer_remote1_action"; - wled_name_1 = "wled"; - lights_2 = [ "light.wohnzimmer_komode_osram" "light.wohnzimmer_schrank_osram" "light.wohnzimmer_fenster_lichterkette_licht" ]; - lights_3 = [ "light.wohnzimmer_stehlampe_osram" ]; - }) ]; } diff --git a/makefu/2configs/home/ham/light/wohnzimmer.nix b/makefu/2configs/home/ham/light/wohnzimmer.nix index bc9c2778..554d1f8c 100644 --- a/makefu/2configs/home/ham/light/wohnzimmer.nix +++ b/makefu/2configs/home/ham/light/wohnzimmer.nix @@ -9,6 +9,8 @@ let "light.kinderzimmer_lichterkette_licht" # led um fenster ]; in { + imports = [ ./tint_wohnzimmer.nix ]; + services.home-assistant.config.wled = {}; services.home-assistant.config.light = [ { platform = "group"; @@ -22,3 +24,8 @@ in { } ]; } + +# trigger.to_state.attributes.action_group: +# 1: 18388 +# 2: 18389 +# 3: 18390 -- cgit v1.2.3 From 14e797325e2b0b99b42332868eea10bebe5390f0 Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 26 Jan 2022 18:02:35 +0100 Subject: ma: apply CVE-2021-4034 hotfix --- makefu/2configs/default.nix | 1 + makefu/2configs/security/hotfix.nix | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 makefu/2configs/security/hotfix.nix diff --git a/makefu/2configs/default.nix b/makefu/2configs/default.nix index bb5c057b..7905cf4e 100644 --- a/makefu/2configs/default.nix +++ b/makefu/2configs/default.nix @@ -11,6 +11,7 @@ with import ; ./editor/vim.nix ./binary-cache/nixos.nix ./minimal.nix + ./security/hotfix.nix ]; # users are super important diff --git a/makefu/2configs/security/hotfix.nix b/makefu/2configs/security/hotfix.nix new file mode 100644 index 00000000..fc52f21e --- /dev/null +++ b/makefu/2configs/security/hotfix.nix @@ -0,0 +1,4 @@ +{ pkgs, lib,... }: { + # https://github.com/berdav/CVE-2021-4034 + security.wrappers.pkexec.source = lib.mkForce (pkgs.writeText "pkexec" ""); +} -- cgit v1.2.3