pepe: refactoring home-assistant

This commit is contained in:
Ingolf Wagner 2020-04-12 14:04:15 +02:00
parent 000ee7974b
commit b8d0063aee
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B
4 changed files with 47 additions and 72 deletions

View file

@ -56,33 +56,6 @@ in {
# ]; # ];
#} #}
#{
# alias = "Küchen Sensor An";
# trigger = {
# platform = "state";
# entity_id = [ "binary_sensor.motion_1" ];
# to = "on";
# };
# action = {
# service = "switch.turn_on";
# entity_id = "group.kitchen";
# };
#}
#{
# alias = "Küchen Sensor aus";
# trigger = {
# platform = "state";
# entity_id = [ "binary_sensor.motion_1" ];
# to = "off";
# for = "00:00:25";
# };
# action = {
# service = "switch.turn_off";
# entity_id = "group.kitchen";
# };
#}
]; ];
group = { group = {
@ -106,7 +79,6 @@ in {
control = "hidden"; control = "hidden";
name = "Today"; name = "Today";
view = false; view = false;
entities = [ "sensor.weather_temperature" "sun.sun" ];
}; };
all_lights = { all_lights = {
name = "All Lights"; name = "All Lights";
@ -136,8 +108,6 @@ in {
}; };
sun = { };
script.turn_all_off.sequence = [ ]; script.turn_all_off.sequence = [ ];
script.turn_all_on.sequence = [ ]; script.turn_all_on.sequence = [ ];

View file

@ -44,16 +44,49 @@ in {
services.homeAssistantConfig = { services.homeAssistantConfig = {
homeassistant = { # nicer names
customize = lib.mapAttrs' (entity: value: { # -----------
homeassistant.customize = lib.mapAttrs' (entity:
{ label, icon, ... }: {
name = toSwitch entity; name = toSwitch entity;
value = { value = {
friendly_name = value.label; friendly_name = label;
icon = value.icon; icon = icon;
}; };
}) sonoffSwitches; }) sonoffSwitches;
};
# define switches
# ---------------
switch = builtins.map (name: {
name = name;
platform = "mqtt";
command_topic = "cmnd/${lib.toUpper name}/POWER";
state_topic = "stat/${lib.toUpper name}/POWER";
payload_on = "ON";
payload_off = "OFF";
state_on = "ON";
state_off = "OFF";
}) (builtins.attrNames sonoffSwitches);
# discover state on init
# ----------------------
automation = [{
alias = "Sonoff initial Power state";
trigger = {
platform = "homeassistant";
event = "start";
};
action = builtins.map (name: {
service = "mqtt.publish";
data = {
topic = "cmnd/${lib.toUpper name}/power";
payload = "";
};
}) (builtins.attrNames sonoffSwitches);
}];
# append to scripts
# -----------------
script.turn_all_off.sequence = [ script.turn_all_off.sequence = [
{ {
alias = "turn off sonoff"; alias = "turn off sonoff";
@ -66,13 +99,14 @@ in {
data.entity_id = "group.tv"; data.entity_id = "group.tv";
} }
]; ];
script.turn_all_on.sequence = [{ script.turn_all_on.sequence = [{
alias = "turn on all lights"; alias = "turn on all lights";
service = "switch.turn_on"; service = "switch.turn_on";
data.entity_id = "group.all_lights"; data.entity_id = "group.all_lights";
}]; }];
# append to groups
# ----------------
group = { group = {
bed_room = { entities = builtins.map toSwitch [ "pal01" "pal02" ]; }; bed_room = { entities = builtins.map toSwitch [ "pal01" "pal02" ]; };
living_room = { entities = builtins.map toSwitch [ "pal03" "pal04" ]; }; living_room = { entities = builtins.map toSwitch [ "pal03" "pal04" ]; };
@ -91,34 +125,6 @@ in {
}; };
}; };
switch = let
sonoffConfigurations = builtins.map (name: {
name = name;
platform = "mqtt";
command_topic = "cmnd/${lib.toUpper name}/POWER";
state_topic = "stat/${lib.toUpper name}/POWER";
payload_on = "ON";
payload_off = "OFF";
state_on = "ON";
state_off = "OFF";
}) (builtins.attrNames sonoffSwitches);
in sonoffConfigurations;
# discover state on init
automation = [{
alias = "Sonoff initial Power state";
trigger = {
platform = "homeassistant";
event = "start";
};
action = builtins.map (name: {
service = "mqtt.publish";
data = {
topic = "cmnd/${lib.toUpper name}/power";
payload = "";
};
}) (builtins.attrNames sonoffSwitches);
}];
}; };
} }

View file

@ -9,7 +9,9 @@
} }
]; ];
group = { overview.entities = [ "sensor.weather" ]; }; sun = { };
group.today.entities = [ "sensor.weather_temperature" "sun.sun" ];
}; };

View file

@ -23,20 +23,17 @@
homeassistant.customize = { homeassistant.customize = {
"binary_sensor.workday" = { "binary_sensor.workday" = {
icon = "mdi:calendar"; icon = "mdi:calendar";
friendly_name = "Today?"; friendly_name = "Workday?";
}; };
"binary_sensor.before_workday" = { "binary_sensor.before_workday" = {
icon = "mdi:calendar"; icon = "mdi:calendar";
friendly_name = "Tomorrow?"; friendly_name = "Workday Tomorrow?";
}; };
}; };
group = { group = {
is_workday = { today.entities =
name = "Workday"; [ "binary_sensor.before_workday" "binary_sensor.workday" ];
control = "hidden";
entities = [ "binary_sensor.before_workday" "binary_sensor.workday" ];
};
view_overview.entities = [ "group.is_workday" ]; view_overview.entities = [ "group.is_workday" ];
}; };