This commit is contained in:
mjallen18
2025-11-21 11:46:34 -06:00
parent 71b8fc9d0f
commit 8705f7336b

View File

@@ -12,59 +12,11 @@ let
yamlFormat = pkgs.formats.yaml { };
mkLightswitchAutomation = name: lscfg: {
"${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 = [];
mkLightswitchAutomation = name: lscfg: {
actions = [
{
choose = [
# On Press
{
conditions = [
{
@@ -75,16 +27,17 @@ let
sequence = [
{
action = "light.turn_on";
metadata = {};
data = {
transition = lscfg.transitionTime;
brightness_pct = lscfg.brightnessPercent;
kelvin = lscfg.lightTemperature;
transition = lscfg.transitionTime;
};
metadata = {};
target.entity_id = [ lscfg.lightEntityId ];
}
];
}
# Off Press
{
conditions = [
{
@@ -95,12 +48,13 @@ let
sequence = [
{
action = "light.turn_off";
metadata = {};
data.transition = lscfg.transitionTime;
metadata = {};
target.entity_id = [ lscfg.lightEntityId ];
}
];
}
# Up Press
{
conditions = [
{
@@ -111,12 +65,13 @@ let
sequence = [
{
action = "light.turn_on";
metadata = {};
data.brightness_step_pct = lscfg.brightnessStepPercent;
target.entity_id = lscfg.lightEntityId;
metadata = {};
target.entity_id = lscfg.lightEntityId; # String, not list
}
];
}
# Down Press
{
conditions = [
{
@@ -127,12 +82,13 @@ let
sequence = [
{
action = "light.turn_on";
metadata = {};
data.brightness_step_pct = -lscfg.brightnessStepPercent;
target.entity_id = lscfg.lightEntityId;
metadata = {};
target.entity_id = lscfg.lightEntityId; # String, not list
}
];
}
# On Hold
{
conditions = [
{
@@ -143,12 +99,12 @@ let
sequence = [
{
action = "light.turn_on";
metadata = {};
data = {
transition = 0;
brightness_pct = 100;
rgb_color = [ 255 38 0 ];
rgb_color = lscfg.holdRgbColor;
transition = 0;
};
metadata = {};
target.entity_id = [ lscfg.lightEntityId ];
}
];
@@ -157,9 +113,55 @@ let
}
];
mode = "single";
alias = lscfg.alias;
conditions = [];
description = lscfg.description;
id = lscfg.id;
mode = lscfg.mode;
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";
}
];
};
};
# Generate all automations as list
lightswitchAutomations = mapAttrsToList mkLightswitchAutomation cfg.lightswitch;