From afd0a285cd809a13ac4607ffb753be420f87cabe Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Thu, 16 Apr 2020 01:26:02 +0200 Subject: [PATCH] pepe: control situations --- configs/pepe/home-assistant.nix | 166 +++++++++++++----- .../home-assistant/zigbee2mqtt/buttons.nix | 3 + .../home-assistant/zigbee2mqtt/lights.nix | 2 +- 3 files changed, 128 insertions(+), 43 deletions(-) diff --git a/configs/pepe/home-assistant.nix b/configs/pepe/home-assistant.nix index fcf9d32..feede04 100644 --- a/configs/pepe/home-assistant.nix +++ b/configs/pepe/home-assistant.nix @@ -33,72 +33,154 @@ in { prometheus.namespace = "hass"; + input_select.situation = { + icon = "mdi:brightness-auto"; + options = [ "on" "off" "essential" ]; + }; input_boolean.bed_room_buttons.icon = "mdi:toggle-switch"; + input_boolean.situation_toggle.icon = "mdi:toggle-switch"; automation = let # todo : at night only turn trigger essential groups - roomPresents = { roomGroup, presentsGroup }: [ - { - alias = "presents -> turn on ${roomGroup} lights"; - trigger = { - platform = "state"; - entity_id = "group.${presentsGroup}"; - from = "off"; - to = "on"; - }; - action = [ - { - service = "switch.turn_on"; - entity_id = "group.${roomGroup}"; - } - { - service = "light.turn_on"; - entity_id = "group.${roomGroup}"; - } - ]; - } - { - alias = "absents -> turn off ${roomGroup} lights"; - trigger = { - platform = "state"; - entity_id = "group.${presentsGroup}"; - from = "on"; - to = "off"; - }; - action = [ - { - service = "switch.turn_off"; - entity_id = "group.${roomGroup}"; - } - { - service = "light.turn_off"; - entity_id = "group.${roomGroup}"; - } - ]; - } - ]; + roomPresents = + { roomGroup, presentsGroup, situation, brightness ? 255 }: [ + { + alias = "presents -> turn on ${roomGroup} lights"; + trigger = { + platform = "state"; + entity_id = "group.${presentsGroup}"; + from = "off"; + to = "on"; + }; + condition = { + condition = "state"; + entity_id = "input_select.situation"; + state = situation; + }; + action = [ + { + service = "switch.turn_on"; + data.entity_id = "group.${roomGroup}"; + } + { + service = "light.turn_on"; + data = { + entity_id = "group.${roomGroup}"; + brightness = brightness; + }; + } + ]; + } + { + alias = "absents -> turn off ${roomGroup} lights"; + trigger = { + platform = "state"; + entity_id = "group.${presentsGroup}"; + from = "on"; + to = "off"; + }; + action = [ + { + service = "switch.turn_off"; + data.entity_id = "group.${roomGroup}"; + } + { + service = "light.turn_off"; + data.entity_id = "group.${roomGroup}"; + } + ]; + } + ]; in lib.flatten (map roomPresents [ { roomGroup = "kitchen_room_lights"; presentsGroup = "kitchen_room_present"; + situation = "on"; } { roomGroup = "living_room_lights"; presentsGroup = "living_room_present"; + situation = "on"; } { roomGroup = "floor_room_lights"; presentsGroup = "floor_room_present"; + situation = "on"; } { roomGroup = "bath_room_lights"; presentsGroup = "bath_room_present"; + situation = "on"; } { roomGroup = "bed_room_lights"; presentsGroup = "bed_room_present"; + situation = "on"; } - ]); + { + roomGroup = "kitchen_room_essentials"; + presentsGroup = "kitchen_room_present"; + situation = "essential"; + brightness = 30; + } + { + roomGroup = "living_room_essential"; + presentsGroup = "living_room_present"; + situation = "essential"; + brightness = 30; + } + { + roomGroup = "floor_room_essential"; + presentsGroup = "floor_room_present"; + situation = "essential"; + brightness = 30; + } + { + roomGroup = "bath_room_essential"; + presentsGroup = "bath_room_present"; + situation = "essential"; + brightness = 30; + } + { + roomGroup = "bed_room_essential"; + presentsGroup = "bed_room_present"; + situation = "essential"; + brightness = 30; + } + ]) ++ [ + { + alias = "set essential"; + trigger = { + platform = "state"; + entity_id = "input_boolean.situation_toggle"; + from = "off"; + to = "on"; + }; + action = { + service = "input_select.select_option"; + data = { + entity_id = "input_select.situation"; + option = "essential"; + }; + }; + } + { + alias = "unset essential"; + trigger = { + platform = "state"; + entity_id = "input_boolean.situation_toggle"; + from = "on"; + to = "off"; + }; + action = { + service = "input_select.select_option"; + data = { + entity_id = "input_select.situation"; + option = "on"; + }; + }; + } + ]; group = let create_room = { name, description }: { @@ -133,7 +215,6 @@ in { "group.${name}_lights" "group.${name}_present" "group.${name}_essential" - "group.${name}_essential_present" ]; }; }; @@ -185,6 +266,7 @@ in { control = "hidden"; name = "Today"; view = false; + entities = [ "input_select.situation" ]; }; view_overview = { name = "Übersicht"; diff --git a/configs/pepe/home-assistant/zigbee2mqtt/buttons.nix b/configs/pepe/home-assistant/zigbee2mqtt/buttons.nix index b6a8d2c..c9d814b 100644 --- a/configs/pepe/home-assistant/zigbee2mqtt/buttons.nix +++ b/configs/pepe/home-assistant/zigbee2mqtt/buttons.nix @@ -13,16 +13,19 @@ let id = "0x00158d0002b04f65"; # states = { click = "input_boolean.living_room_button"; } # input state to hold (optional) (default "input_boolean.single_${name}") groups = [ "living_room" "living_room_present" ]; + states.double = "input_boolean.situation_toggle"; }; "button_2" = { id = "0x00158d0002b04f09"; groups = [ "bed_room" "bed_room_present" ]; states.single = "input_boolean.bed_room_buttons"; + states.double = "input_boolean.situation_toggle"; }; "button_3" = { id = "0x00158d0002b00e04"; groups = [ "bed_room" "bed_room_present" ]; states.single = "input_boolean.bed_room_buttons"; + states.double = "input_boolean.situation_toggle"; }; }; diff --git a/configs/pepe/home-assistant/zigbee2mqtt/lights.nix b/configs/pepe/home-assistant/zigbee2mqtt/lights.nix index f33addd..dd4d406 100644 --- a/configs/pepe/home-assistant/zigbee2mqtt/lights.nix +++ b/configs/pepe/home-assistant/zigbee2mqtt/lights.nix @@ -13,7 +13,7 @@ let }; "light_3" = { id = "0x7cb03eaa0a033a86"; - groups = [ "living_room" "living_room_lights" ]; + groups = [ "living_room" "living_room_essential" "living_room_lights" ]; }; "light_4" = { id = "0x7cb03eaa0a04aabf";