From af57fdfb9f51f5f81ac210fdabbd0290965e33b4 Mon Sep 17 00:00:00 2001 From: mjallen18 Date: Fri, 21 Nov 2025 13:47:11 -0600 Subject: [PATCH] testing --- .../homeassistant/automations/default.nix | 292 +++++++++--------- 1 file changed, 147 insertions(+), 145 deletions(-) diff --git a/modules/nixos/homeassistant/automations/default.nix b/modules/nixos/homeassistant/automations/default.nix index 9a8ecf8..4bad14d 100644 --- a/modules/nixos/homeassistant/automations/default.nix +++ b/modules/nixos/homeassistant/automations/default.nix @@ -12,152 +12,154 @@ let yamlFormat = pkgs.formats.yaml { }; - mkLightswitchAutomation = name: lscfg: - # Use explicit ordering to ensure proper YAML structure - listToAttrs [ - (nameValuePair "actions" [ - { - choose = [ - { - conditions = [ - { - condition = "trigger"; - id = [ "on press" ]; - } - ]; - sequence = [ - { - action = "light.turn_on"; - data = { - brightness_pct = lscfg.brightnessPercent; - kelvin = lscfg.lightTemperature; - transition = lscfg.transitionTime; - }; - metadata = {}; - target.entity_id = [ lscfg.lightEntityId ]; - } - ]; - } - { - conditions = [ - { - condition = "trigger"; - id = [ "off press" ]; - } - ]; - sequence = [ - { - action = "light.turn_off"; - data.transition = lscfg.transitionTime; - metadata = {}; - target.entity_id = [ lscfg.lightEntityId ]; - } - ]; - } - { - conditions = [ - { - condition = "trigger"; - id = [ "up press" ]; - } - ]; - sequence = [ - { - action = "light.turn_on"; - data.brightness_step_pct = lscfg.brightnessStepPercent; - metadata = {}; - target.entity_id = lscfg.lightEntityId; - } - ]; - } - { - conditions = [ - { - condition = "trigger"; - id = [ "down press" ]; - } - ]; - sequence = [ - { - action = "light.turn_on"; - data.brightness_step_pct = -lscfg.brightnessStepPercent; - metadata = {}; - target.entity_id = lscfg.lightEntityId; - } - ]; - } - { - conditions = [ - { - condition = "trigger"; - id = [ "on hold" ]; - } - ]; - sequence = [ - { - action = "light.turn_on"; - data = { - brightness_pct = 100; - rgb_color = [ 255 0 0 ]; - transition = 0; - }; - metadata = {}; - target.entity_id = [ lscfg.lightEntityId ]; - } - ]; - } - ]; - } - ]) - (nameValuePair "alias" lscfg.alias) - (nameValuePair "conditions" []) - (nameValuePair "description" lscfg.description) - (nameValuePair "id" (toString lscfg.id)) - (nameValuePair "mode" "single") - (nameValuePair "triggers" [ - { - device_id = lscfg.mqttDeviceId; - domain = "mqtt"; - id = "on press"; - subtype = "on-press"; - trigger = "device"; - type = "action"; - } - { - device_id = lscfg.mqttDeviceId; - domain = "mqtt"; - id = "off press"; - subtype = "off-press"; - trigger = "device"; - type = "action"; - } - { - device_id = lscfg.mqttDeviceId; - domain = "mqtt"; - id = "up press"; - subtype = "up-press"; - trigger = "device"; - type = "action"; - } - { - device_id = lscfg.mqttDeviceId; - domain = "mqtt"; - id = "down press"; - subtype = "down-press"; - trigger = "device"; - type = "action"; - } - { - device_id = lscfg.mqttDeviceId; - domain = "mqtt"; - id = "on hold"; - subtype = "on-hold"; - trigger = "device"; - type = "action"; - } - ]) + mkLightswitchAutomation = name: lscfg: { + id = lscfg.id; + alias = lscfg.alias; + description = lscfg.description; + + triggers = [ + { + device_id = lscfg.mqttDeviceId; + domain = "mqtt"; + id = "on press"; + subtype = "on-press"; + trigger = "device"; + type = "action"; + } + { + device_id = lscfg.mqttDeviceId; + domain = "mqtt"; + id = "off press"; + subtype = "off-press"; + trigger = "device"; + type = "action"; + } + { + device_id = lscfg.mqttDeviceId; + domain = "mqtt"; + id = "up press"; + subtype = "up-press"; + trigger = "device"; + type = "action"; + } + { + device_id = lscfg.mqttDeviceId; + domain = "mqtt"; + id = "down press"; + subtype = "down-press"; + trigger = "device"; + type = "action"; + } + { + device_id = lscfg.mqttDeviceId; + domain = "mqtt"; + id = "on hold"; + subtype = "on-hold"; + trigger = "device"; + type = "action"; + } ]; - + + conditions = []; + + actions = [ + { + choose = [ + { + conditions = [ + { + condition = "trigger"; + id = [ "on press" ]; + } + ]; + sequence = [ + { + action = "light.turn_on"; + data = { + brightness_pct = lscfg.brightnessPercent; + kelvin = lscfg.lightTemperature; + transition = lscfg.transitionTime; + }; + metadata = {}; + target.entity_id = [ lscfg.lightEntityId ]; + } + ]; + } + { + conditions = [ + { + condition = "trigger"; + id = [ "off press" ]; + } + ]; + sequence = [ + { + action = "light.turn_off"; + data.transition = lscfg.transitionTime; + metadata = {}; + target.entity_id = [ lscfg.lightEntityId ]; + } + ]; + } + { + conditions = [ + { + condition = "trigger"; + id = [ "up press" ]; + } + ]; + sequence = [ + { + action = "light.turn_on"; + data.brightness_step_pct = lscfg.brightnessStepPercent; + metadata = {}; + target.entity_id = lscfg.lightEntityId; + } + ]; + } + { + conditions = [ + { + condition = "trigger"; + id = [ "down press" ]; + } + ]; + sequence = [ + { + action = "light.turn_on"; + data.brightness_step_pct = -lscfg.brightnessStepPercent; + metadata = {}; + target.entity_id = lscfg.lightEntityId; + } + ]; + } + { + conditions = [ + { + condition = "trigger"; + id = [ "on hold" ]; + } + ]; + sequence = [ + { + action = "light.turn_on"; + data = { + brightness_pct = 100; + rgb_color = [ 255 0 0 ]; + transition = 0; + }; + metadata = {}; + target.entity_id = [ lscfg.lightEntityId ]; + } + ]; + } + ]; + } + ]; + + mode = "single"; + }; + # Generate all automations as list lightswitchAutomations = mapAttrsToList mkLightswitchAutomation cfg.lightswitch; in