This commit is contained in:
mjallen18
2025-11-21 12:14:07 -06:00
parent 8705f7336b
commit 81b8bd9ec5

View File

@@ -12,11 +12,12 @@ let
yamlFormat = pkgs.formats.yaml { }; yamlFormat = pkgs.formats.yaml { };
mkLightswitchAutomation = name: lscfg: { mkLightswitchAutomation = name: lscfg:
actions = [ # Use explicit ordering to ensure proper YAML structure
listToAttrs [
(nameValuePair "actions" [
{ {
choose = [ choose = [
# On Press
{ {
conditions = [ conditions = [
{ {
@@ -37,7 +38,6 @@ let
} }
]; ];
} }
# Off Press
{ {
conditions = [ conditions = [
{ {
@@ -54,7 +54,6 @@ let
} }
]; ];
} }
# Up Press
{ {
conditions = [ conditions = [
{ {
@@ -67,11 +66,10 @@ let
action = "light.turn_on"; action = "light.turn_on";
data.brightness_step_pct = lscfg.brightnessStepPercent; data.brightness_step_pct = lscfg.brightnessStepPercent;
metadata = {}; metadata = {};
target.entity_id = lscfg.lightEntityId; # String, not list target.entity_id = lscfg.lightEntityId;
} }
]; ];
} }
# Down Press
{ {
conditions = [ conditions = [
{ {
@@ -84,11 +82,10 @@ let
action = "light.turn_on"; action = "light.turn_on";
data.brightness_step_pct = -lscfg.brightnessStepPercent; data.brightness_step_pct = -lscfg.brightnessStepPercent;
metadata = {}; metadata = {};
target.entity_id = lscfg.lightEntityId; # String, not list target.entity_id = lscfg.lightEntityId;
} }
]; ];
} }
# On Hold
{ {
conditions = [ conditions = [
{ {
@@ -101,7 +98,7 @@ let
action = "light.turn_on"; action = "light.turn_on";
data = { data = {
brightness_pct = 100; brightness_pct = 100;
rgb_color = lscfg.holdRgbColor; rgb_color = [ 255 0 0 ];
transition = 0; transition = 0;
}; };
metadata = {}; metadata = {};
@@ -111,15 +108,13 @@ let
} }
]; ];
} }
]; ])
(nameValuePair "alias" lscfg.alias)
alias = lscfg.alias; (nameValuePair "conditions" [])
conditions = []; (nameValuePair "description" lscfg.description)
description = lscfg.description; (nameValuePair "id" (toString lscfg.id))
id = lscfg.id; (nameValuePair "mode" "single")
mode = lscfg.mode; (nameValuePair "triggers" [
triggers = [
{ {
device_id = lscfg.mqttDeviceId; device_id = lscfg.mqttDeviceId;
domain = "mqtt"; domain = "mqtt";
@@ -160,8 +155,8 @@ let
trigger = "device"; trigger = "device";
type = "action"; type = "action";
} }
]; ])
}; ];
# Generate all automations as list # Generate all automations as list
lightswitchAutomations = mapAttrsToList mkLightswitchAutomation cfg.lightswitch; lightswitchAutomations = mapAttrsToList mkLightswitchAutomation cfg.lightswitch;