diff --git a/modules/nixos/homeassistant/automations/default.nix b/modules/nixos/homeassistant/automations/default.nix index 278fc9f..9a8ecf8 100644 --- a/modules/nixos/homeassistant/automations/default.nix +++ b/modules/nixos/homeassistant/automations/default.nix @@ -12,11 +12,12 @@ let yamlFormat = pkgs.formats.yaml { }; - mkLightswitchAutomation = name: lscfg: { - actions = [ + mkLightswitchAutomation = name: lscfg: + # Use explicit ordering to ensure proper YAML structure + listToAttrs [ + (nameValuePair "actions" [ { choose = [ - # On Press { conditions = [ { @@ -37,7 +38,6 @@ let } ]; } - # Off Press { conditions = [ { @@ -54,7 +54,6 @@ let } ]; } - # Up Press { conditions = [ { @@ -67,11 +66,10 @@ let action = "light.turn_on"; data.brightness_step_pct = lscfg.brightnessStepPercent; metadata = {}; - target.entity_id = lscfg.lightEntityId; # String, not list + target.entity_id = lscfg.lightEntityId; } ]; } - # Down Press { conditions = [ { @@ -84,11 +82,10 @@ let action = "light.turn_on"; data.brightness_step_pct = -lscfg.brightnessStepPercent; metadata = {}; - target.entity_id = lscfg.lightEntityId; # String, not list + target.entity_id = lscfg.lightEntityId; } ]; } - # On Hold { conditions = [ { @@ -101,7 +98,7 @@ let action = "light.turn_on"; data = { brightness_pct = 100; - rgb_color = lscfg.holdRgbColor; + rgb_color = [ 255 0 0 ]; transition = 0; }; metadata = {}; @@ -111,15 +108,13 @@ let } ]; } - ]; - - alias = lscfg.alias; - conditions = []; - description = lscfg.description; - id = lscfg.id; - mode = lscfg.mode; - - triggers = [ + ]) + (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"; @@ -160,8 +155,8 @@ let trigger = "device"; type = "action"; } - ]; - }; + ]) + ]; # Generate all automations as list lightswitchAutomations = mapAttrsToList mkLightswitchAutomation cfg.lightswitch;