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 { };
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;