From 71b8fc9d0f09c7d30aba4e8dc9fd582e90765cc2 Mon Sep 17 00:00:00 2001 From: mjallen18 Date: Fri, 21 Nov 2025 11:34:39 -0600 Subject: [PATCH] testing --- .../homeassistant/automations/default.nix | 291 +++++++++--------- 1 file changed, 146 insertions(+), 145 deletions(-) diff --git a/modules/nixos/homeassistant/automations/default.nix b/modules/nixos/homeassistant/automations/default.nix index 38ceaae..de67fc7 100644 --- a/modules/nixos/homeassistant/automations/default.nix +++ b/modules/nixos/homeassistant/automations/default.nix @@ -13,151 +13,152 @@ let yamlFormat = pkgs.formats.yaml { }; mkLightswitchAutomation = name: lscfg: { - id = toString lscfg.id; - alias = lscfg.alias; - description = lscfg.description; - - triggers = [ - { - domain = "mqtt"; - device_id = lscfg.mqttDeviceId; - type = "action"; - subtype = "on-press"; - trigger = "device"; - id = "on press"; - } - { - domain = "mqtt"; - device_id = lscfg.mqttDeviceId; - type = "action"; - subtype = "off-press"; - trigger = "device"; - id = "off press"; - } - { - domain = "mqtt"; - device_id = lscfg.mqttDeviceId; - type = "action"; - subtype = "up-press"; - trigger = "device"; - id = "up press"; - } - { - domain = "mqtt"; - device_id = lscfg.mqttDeviceId; - type = "action"; - subtype = "down-press"; - trigger = "device"; - id = "down press"; - } - { - domain = "mqtt"; - device_id = lscfg.mqttDeviceId; - type = "action"; - subtype = "on-hold"; - trigger = "device"; - id = "on hold"; - } - ]; - - conditions = []; - - actions = [ - { - choose = [ - { - conditions = [ - { - condition = "trigger"; - id = [ "on press" ]; - } - ]; - sequence = [ - { - action = "light.turn_on"; - metadata = {}; - data = { - transition = lscfg.transitionTime; - brightness_pct = lscfg.brightnessPercent; - kelvin = lscfg.lightTemperature; - }; - target.entity_id = [ lscfg.lightEntityId ]; - } - ]; - } - { - conditions = [ - { - condition = "trigger"; - id = [ "off press" ]; - } - ]; - sequence = [ - { - action = "light.turn_off"; - metadata = {}; - data.transition = lscfg.transitionTime; - target.entity_id = [ lscfg.lightEntityId ]; - } - ]; - } - { - conditions = [ - { - condition = "trigger"; - id = [ "up press" ]; - } - ]; - sequence = [ - { - action = "light.turn_on"; - metadata = {}; - data.brightness_step_pct = lscfg.brightnessStepPercent; - target.entity_id = lscfg.lightEntityId; - } - ]; - } - { - conditions = [ - { - condition = "trigger"; - id = [ "down press" ]; - } - ]; - sequence = [ - { - action = "light.turn_on"; - metadata = {}; - data.brightness_step_pct = -lscfg.brightnessStepPercent; - target.entity_id = lscfg.lightEntityId; - } - ]; - } - { - conditions = [ - { - condition = "trigger"; - id = [ "on hold" ]; - } - ]; - sequence = [ - { - action = "light.turn_on"; - metadata = {}; - data = { - transition = 0; - brightness_pct = 100; - rgb_color = [ 255 38 0 ]; - }; - target.entity_id = [ lscfg.lightEntityId ]; - } - ]; - } - ]; - } - ]; - - mode = "single"; + "${toString lscfg.id}" = { + alias = lscfg.alias; + description = lscfg.description; + + triggers = [ + { + domain = "mqtt"; + device_id = lscfg.mqttDeviceId; + type = "action"; + subtype = "on-press"; + trigger = "device"; + id = "on press"; + } + { + domain = "mqtt"; + device_id = lscfg.mqttDeviceId; + type = "action"; + subtype = "off-press"; + trigger = "device"; + id = "off press"; + } + { + domain = "mqtt"; + device_id = lscfg.mqttDeviceId; + type = "action"; + subtype = "up-press"; + trigger = "device"; + id = "up press"; + } + { + domain = "mqtt"; + device_id = lscfg.mqttDeviceId; + type = "action"; + subtype = "down-press"; + trigger = "device"; + id = "down press"; + } + { + domain = "mqtt"; + device_id = lscfg.mqttDeviceId; + type = "action"; + subtype = "on-hold"; + trigger = "device"; + id = "on hold"; + } + ]; + + conditions = []; + + actions = [ + { + choose = [ + { + conditions = [ + { + condition = "trigger"; + id = [ "on press" ]; + } + ]; + sequence = [ + { + action = "light.turn_on"; + metadata = {}; + data = { + transition = lscfg.transitionTime; + brightness_pct = lscfg.brightnessPercent; + kelvin = lscfg.lightTemperature; + }; + target.entity_id = [ lscfg.lightEntityId ]; + } + ]; + } + { + conditions = [ + { + condition = "trigger"; + id = [ "off press" ]; + } + ]; + sequence = [ + { + action = "light.turn_off"; + metadata = {}; + data.transition = lscfg.transitionTime; + target.entity_id = [ lscfg.lightEntityId ]; + } + ]; + } + { + conditions = [ + { + condition = "trigger"; + id = [ "up press" ]; + } + ]; + sequence = [ + { + action = "light.turn_on"; + metadata = {}; + data.brightness_step_pct = lscfg.brightnessStepPercent; + target.entity_id = lscfg.lightEntityId; + } + ]; + } + { + conditions = [ + { + condition = "trigger"; + id = [ "down press" ]; + } + ]; + sequence = [ + { + action = "light.turn_on"; + metadata = {}; + data.brightness_step_pct = -lscfg.brightnessStepPercent; + target.entity_id = lscfg.lightEntityId; + } + ]; + } + { + conditions = [ + { + condition = "trigger"; + id = [ "on hold" ]; + } + ]; + sequence = [ + { + action = "light.turn_on"; + metadata = {}; + data = { + transition = 0; + brightness_pct = 100; + rgb_color = [ 255 38 0 ]; + }; + target.entity_id = [ lscfg.lightEntityId ]; + } + ]; + } + ]; + } + ]; + + mode = "single"; + }; }; # Generate all automations as list