pepe: add home-assistant button automation

This commit is contained in:
Ingolf Wagner 2020-04-12 21:42:11 +02:00
parent aad74d7393
commit 957bf38595
Signed by: palo
GPG key ID: 76BF5F1928B9618B
4 changed files with 54 additions and 39 deletions

View file

@ -115,13 +115,13 @@ in {
control = "hidden";
name = "Not Used";
view = false;
entities = [ ];
};
};
script.turn_all_off.sequence = [ ];
script.turn_all_on.sequence = [ ];
script.turn_all_lights_off.sequence = [ ];
};

View file

@ -70,7 +70,8 @@
};
};
group.tv.entities = [ "script.watch_tv" "script.stop_watch_tv" ];
group.tv.entities =
[ "script.watch_tv" "script.stop_watch_tv" "script.test_display" ];
};

View file

@ -102,19 +102,19 @@ in {
# -----------------
script.turn_all_off.sequence = [
{
alias = "turn off sonoff";
alias = "turn off sonoff lights";
service = "switch.turn_off";
data.entity_id = "group.all_lights";
}
{
alias = "turn off sonoff";
alias = "turn off tv";
service = "switch.turn_off";
data.entity_id = "group.tv";
}
];
script.turn_all_on.sequence = [{
alias = "turn on all lights";
service = "switch.turn_on";
script.turn_all_lights_off.sequence = [{
alias = "turn off sonoff lights";
service = "switch.turn_off";
data.entity_id = "group.all_lights";
}];
@ -125,16 +125,15 @@ in {
flatSonoffSwitches =
lib.mapAttrsToList (name: values: { name = name; } // values)
sonoffSwitches;
allRooms' =
lib.groupBy ({ room ? "unknown", ... }: room) flatSonoffSwitches;
allRooms = lib.mapAttrs (_: devices: {
entities = map ({ name, ... }: "switch.${name}") devices;
}) allRooms';
allLights' = lib.filter ({ type ? "unknown", ... }: type == "light")
flatSonoffSwitches;
allLights = {
all_lights.entities = map ({ name, ... }: "switch.${name}") allLights';
};
allRooms' = lib.groupBy ({ room ? "unknown", ... }: room) allLights';
allRooms = lib.mapAttrs (_: devices: {
entities = map ({ name, ... }: "switch.${name}") devices;
}) allRooms';
in allRooms // allLights // {
# this is a quick hack. it should not be the norm to define this stuff down here
tv = { entities = builtins.map toSwitch [ "pal05" ]; };

View file

@ -262,8 +262,23 @@ in {
# todo : this belongs in the home-assistant.nix
automation = let
lights = map (button: {
alias = "Toggle all lights, on click";
# hold, turn off the lights everywhere
all_lights_off = map (button: {
alias = "turn all lights off on holding a button";
trigger = {
platform = "mqtt";
topic = "zigbee2mqtt/${button}";
};
condition = {
condition = "template";
value_template = ''{{ "hold" == trigger.payload_json.action }}'';
};
action = { service = "script.turn_all_off"; };
}) [ "button_1" "button_2" "button_3" ];
# one click, turn on the light in the room
room_lights_on = map ({ button, room }: {
alias = "turn on lights in ${room}, on ${button} click";
trigger = {
platform = "mqtt";
topic = "zigbee2mqtt/${button}";
@ -273,32 +288,32 @@ in {
value_template = ''{{ "single" == trigger.payload_json.click }}'';
};
action = {
service = "switch.toggle";
entity_id = "group.all_lights";
service = "switch.turn_on";
entity_id = "group.${room}";
};
}) [ "button_1" "button_2" "button_3" ];
}) [
{
button = "button_1";
room = "living_room";
}
{
button = "button_2";
room = "bed_room";
}
{
button = "button_3";
room = "bed_room";
}
];
#mpd = map (button: {
# alias = "Toggle mpd, on double click";
# trigger = {
# platform = "mqtt";
# topic = "zigbee2mqtt/${button}";
# };
# condition = {
# condition = "template";
# value_template = ''{{ "double" == trigger.payload_json.click }}'';
# };
# action = {
# service = "media_player.toggle";
# # todo use a group here
# entity_id = "media_player.mpd";
# };
#}) [ "button_1" "button_2" "button_3" ];
# todo : double click, turn on the light in this room and every where else turn it off
# kitchen light automation
# ------------------------
# https://www.home-assistant.io/integrations/binary_sensor.template/
kitchen_lights = map (motion: [
{
alias = "turn on lights, on motion";
alias = "turn on kitchen lights, on motion detected";
trigger = {
platform = "state";
entity_id = "binary_sensor.${motion}";
@ -307,11 +322,11 @@ in {
};
action = {
service = "switch.turn_on";
entity_id = "group.kitchen";
entity_id = "group.kitchen_room";
};
}
{
alias = "turn off lights, on no motion";
alias = "turn off kitchen lights, on motion clear";
trigger = {
platform = "state";
entity_id = "binary_sensor.${motion}";
@ -320,12 +335,12 @@ in {
};
action = {
service = "switch.turn_off";
entity_id = "group.kitchen";
entity_id = "group.kitchen_room";
};
}
]) [ "motion_sensor_1" ];
in lib.flatten (lights ++ kitchen_lights);
in lib.flatten (kitchen_lights ++ all_lights_off ++ room_lights_on);
# click = double => music an aus