home-assistant: setup position_tracking

This commit is contained in:
Ingolf Wagner 2020-05-05 23:46:51 +02:00
parent 98fef3c291
commit 3576374285
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B
2 changed files with 154 additions and 27 deletions

View file

@ -47,11 +47,10 @@ in {
"essential" "essential"
]; ];
}; };
input_boolean.bed_room_buttons.icon = "mdi:toggle-switch";
input_boolean.situation_toggle.icon = "mdi:toggle-switch"; input_boolean.situation_toggle.icon = "mdi:toggle-switch";
# room presents when I'm alone # enable presents_tracking
input_boolean.alone.icon = "mdi:account"; input_boolean.presents_tracking.icon = "mdi:account";
input_select.room_present = { input_select.room_present = {
icon = "mdi:map-marker"; icon = "mdi:map-marker";
options = [ options = [
@ -97,9 +96,9 @@ in {
to = "on"; to = "on";
}; };
condition = { condition = {
condition = "state"; condition = "template";
entity_id = "input_select.situation"; value_template =
state = situation; "{{ states( 'input_select.situation' ) == '${situation}' }}";
}; };
action = [ action = [
{ {
@ -118,31 +117,36 @@ in {
{ {
alias = alias =
"absents in ${presentsGroup} -> turn lights off ${turnOffGroup} in ${situation}"; "absents in ${presentsGroup} -> turn lights off ${turnOffGroup} in ${situation}";
trigger = { trigger = map (minutes: {
platform = "state"; platform = "state";
entity_id = "group.${presentsGroup}"; entity_id = "group.${presentsGroup}";
from = "on"; from = "on";
to = "off"; to = "off";
for.seconds = 2 * 60; for.seconds = minutes * 60;
}; }) [ 2 5 10 15 20 25 30 35 40 45 50 55 ];
condition = { condition = {
condition = "and"; condition = "and";
conditions = [ conditions = [
{
condition = "template";
value_template =
"{{ states( 'input_select.room_present' ) != '${presentsGroup}' }}";
}
{
condition = "template";
value_template =
"{{ states( 'input_boolean.alone' ) == 'on' }}";
}
{ {
condition = "template"; condition = "template";
value_template = value_template =
"{{ states( 'input_select.situation' ) == '${situation}' }}"; "{{ states( 'input_select.situation' ) == '${situation}' }}";
} }
{
condition = "or";
conditions = [
{
condition = "template";
value_template =
"{{ states( 'input_select.room_present' ) != '${presentsGroup}' }}";
}
{
condition = "template";
value_template =
"{{ states( 'input_boolean.presents_tracking' ) == 'off' }}";
}
];
}
]; ];
}; };
action = [ action = [
@ -156,6 +160,32 @@ in {
} }
]; ];
} }
{
alias =
"finally absents in ${presentsGroup} -> turn lights off ${turnOffGroup} in ${situation}";
trigger = [{
platform = "state";
entity_id = "group.${presentsGroup}";
from = "on";
to = "off";
for.seconds = 60 * 60;
}];
condition = {
condition = "template";
value_template =
"{{ states( 'input_select.situation' ) == '${situation}' }}";
};
action = [
{
service = "switch.turn_off";
data.entity_id = "group.${turnOffGroup}";
}
{
service = "light.turn_off";
data.entity_id = "group.${turnOffGroup}";
}
];
}
]; ];
onOffArguments = flatMap (name: [ onOffArguments = flatMap (name: [
{ {
@ -179,6 +209,92 @@ in {
]) allRooms; ]) allRooms;
in (flatMap roomPresents onOffArguments); in (flatMap roomPresents onOffArguments);
roomPresentSwitches = let
allRoomPresentGroups = map (name: "${name}_present") allRooms;
foo =
# group to determine presents
presentGroup:
let
otherRoomPresentGroups =
builtins.filter (name: name != presentGroup) allRoomPresentGroups;
in [
{
alias =
"select ${presentGroup} if all other rooms are longer not present/active";
trigger = {
platform = "state";
entity_id = "group.${presentGroup}";
from = "on";
to = "off";
for.seconds = (2 * 60) - 15;
};
condition = {
condition = "and";
conditions = flatMap (otherRoomPresent: {
condition = "state";
entity_id = "group.${otherRoomPresent}";
state = "off";
for.seconds = 1 * 60;
}) otherRoomPresentGroups;
};
action = [{
service = "input_select.select_option";
data = {
entity_id = "input_select.room_present";
option = presentGroup;
};
}];
}
{
alias =
"select ${presentGroup} if no other room is present/active but ${presentGroup} is";
trigger = {
platform = "time_pattern";
minutes = "/1";
};
condition = {
condition = "and";
conditions = [{
condition = "state";
entity_id = "group.${presentGroup}";
state = "on";
for.seconds = 1 * 60;
}] ++ (flatMap (otherRoomPresent: {
condition = "state";
entity_id = "group.${otherRoomPresent}";
state = "off";
for.seconds = 1 * 60;
}) otherRoomPresentGroups);
};
action = [{
service = "input_select.select_option";
data = {
entity_id = "input_select.room_present";
option = presentGroup;
};
}];
}
{
alias = "select ${presentGroup} when entering the room";
trigger = {
platform = "state";
entity_id = "group.${presentGroup}";
from = "off";
to = "on";
};
action = [{
service = "input_select.select_option";
data = {
entity_id = "input_select.room_present";
option = presentGroup;
};
}];
}
];
in flatMap foo allRoomPresentGroups;
# change light scene in rooms when changing situation # change light scene in rooms when changing situation
# --------------------------------------------------- # ---------------------------------------------------
situationSwitches = let situationSwitches = let
@ -308,7 +424,7 @@ in {
]) allRooms; ]) allRooms;
in flatMap situationSwitch allArguments; in flatMap situationSwitch allArguments;
in situationSwitches ++ roomSwitches ++ [ in situationSwitches ++ roomSwitches ++ roomPresentSwitches ++ [
# control situation with buttons # control situation with buttons
{ {
@ -427,6 +543,17 @@ in {
]; ];
}; };
all_room_presents = {
name = "Alle Anwesenheits Raum Sensoren";
entities = [
"group.floor_room_present"
"group.bed_room_present"
"group.living_room_present"
"group.kitchen_room_present"
"group.bath_room_present"
];
};
# overview # overview
# -------- # --------
all_sensors = { all_sensors = {
@ -440,7 +567,7 @@ in {
entities = [ entities = [
"input_select.situation" "input_select.situation"
"input_select.room_present" "input_select.room_present"
"input_boolean.alone" "input_boolean.presents_tracking"
]; ];
}; };
view_overview = { view_overview = {

View file

@ -11,20 +11,20 @@ let
allDevices = { allDevices = {
"button_1" = { "button_1" = {
id = "0x00158d0002b04f65"; id = "0x00158d0002b04f65";
# states = { click = "input_boolean.living_room_button"; } # input state to hold (optional) (default "input_boolean.single_${name}") groups = [ "living_room" ];
groups = [ "living_room" "living_room_present" ]; states.single = "input_boolean.presents_tracking";
states.double = "input_boolean.situation_toggle"; states.double = "input_boolean.situation_toggle";
}; };
"button_2" = { "button_2" = {
id = "0x00158d0002b04f09"; id = "0x00158d0002b04f09";
groups = [ "bed_room" "bed_room_present" ]; groups = [ "bed_room" ];
states.single = "input_boolean.bed_room_buttons"; states.single = "input_boolean.presents_tracking";
states.double = "input_boolean.situation_toggle"; states.double = "input_boolean.situation_toggle";
}; };
"button_3" = { "button_3" = {
id = "0x00158d0002b00e04"; id = "0x00158d0002b00e04";
groups = [ "bed_room" "bed_room_present" ]; groups = [ "bed_room" ];
states.single = "input_boolean.bed_room_buttons"; states.single = "input_boolean.presents_tracking";
states.double = "input_boolean.situation_toggle"; states.double = "input_boolean.situation_toggle";
}; };
}; };