hass: instantly change situation changes now

This commit is contained in:
Ingolf Wagner 2020-04-22 23:28:26 +02:00
parent 8bad618631
commit 0e2afa4fd1
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B

View file

@ -52,7 +52,9 @@ in {
automation = let
# todo : at night only turn trigger essential groups
allRooms =
[ "living_room" "floor_room" "bath_room" "bed_room" "kitchen_room" ];
roomPresents = {
# group of the room that should be turned on
roomGroup,
@ -117,6 +119,74 @@ in {
];
}
];
situationSwitch = { fromRoomGroup, toRoomGroup, presentsGroup
, fromSituation, toSituation,
# brightness for dimable lights
brightness ? 255 }: [
{
alias =
"${fromSituation} -> ${toSituation} for ${fromRoomGroup} -> ${toRoomGroup} on";
trigger = {
platform = "state";
entity_id = "input_select.situation";
from = fromSituation;
to = toSituation;
};
condition = {
condition = "state";
entity_id = "group.${presentsGroup}";
state = "on";
};
action = [
{
service = "switch.turn_off";
data.entity_id = "group.${fromRoomGroup}";
}
{
service = "light.turn_off";
data.entity_id = "group.${fromRoomGroup}";
}
{
service = "switch.turn_on";
data.entity_id = "group.${toRoomGroup}";
}
{
service = "light.turn_on";
data = {
entity_id = "group.${toRoomGroup}";
brightness = brightness;
};
}
];
}
{
alias =
"${fromSituation} -> ${toSituation} for ${fromRoomGroup} -> ${toRoomGroup} off";
trigger = {
platform = "state";
entity_id = "input_select.situation";
from = fromSituation;
to = toSituation;
};
condition = {
condition = "state";
entity_id = "group.${presentsGroup}";
state = "off";
};
action = [
{
service = "switch.turn_off";
data.entity_id = "group.${fromRoomGroup}";
}
{
service = "light.turn_off";
data.entity_id = "group.${fromRoomGroup}";
}
];
}
];
in lib.flatten (map roomPresents (lib.flatten (map (name: [
{
roomGroup = "${name}_lights";
@ -130,8 +200,7 @@ in {
situation = "essential";
brightness = 30;
}
]) [ "living_room" "floor_room" "bath_room" "bed_room" "kitchen_room" ])))
++ [
]) allRooms))) ++ [
# control situation with buttons
{
@ -166,7 +235,23 @@ in {
};
};
}
];
] ++ (lib.flatten (map situationSwitch (lib.flatten (map (name: [
{
presentsGroup = "${name}_present";
fromSituation = "dark";
toSituation = "essential";
fromRoomGroup = "${name}_lights";
toRoomGroup = "${name}_essential";
brightness = 30;
}
{
presentsGroup = "${name}_present";
fromSituation = "essential";
toSituation = "dark";
fromRoomGroup = "${name}_essential";
toRoomGroup = "${name}_lights";
}
]) allRooms))));
group = let
create_room = { name, description }: {