From 599a889e2cca174df8865307fe25abfc1d32d4e2 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Thu, 5 Nov 2020 00:23:44 +0100 Subject: [PATCH] hass: frequently enforce state of heater and fyrtur --- configs/pepe/home-assistant.nix | 331 ++++++++++-------- .../home-assistant/zigbee2mqtt/buttons.nix | 3 + 2 files changed, 179 insertions(+), 155 deletions(-) diff --git a/configs/pepe/home-assistant.nix b/configs/pepe/home-assistant.nix index 4000bef..903b1cc 100644 --- a/configs/pepe/home-assistant.nix +++ b/configs/pepe/home-assistant.nix @@ -63,6 +63,14 @@ in { input_boolean.situation_toggle.icon = "mdi:toggle-switch"; input_boolean.printer_toggle.icon = "mdi:toggle-switch"; + input_boolean.windows_up.icon = "mdi:toggle-switch"; + + # heater scenes + input_select.heater_state = { + #icon = "mdi:brightness-auto"; + options = [ "off" "on1" "on2" ]; + }; + automation = [ { @@ -178,203 +186,122 @@ in { }; }; } + # window roles { - alias = "windows down in the evening"; + alias = "windows state = down in the evening"; trigger = [{ platform = "sun"; event = "sunset"; offset = "+00:01:00"; # 10 min after sunset }]; - action = [ - { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/fyrtur1/set"; # office - payload_template = ''{"position":"15"}''; - }; - } - { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/fyrtur2/set"; # office - payload_template = ''{"position":"15"}''; - }; - } - { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/fyrtur3/set"; - payload_template = ''{"position":"21"}''; - }; - } - { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/fyrtur4/set"; - payload_template = ''{"position":"21"}''; - }; - } - ]; + action = [{ + service = "input_select.select_option"; + data = { + entity_id = "input_select.windows_up"; + option = "off"; + }; + }]; } { - alias = "windows up in the morning"; + alias = "windows state = up in the morning"; trigger = [{ platform = "time"; at = "09:00:00"; }]; - action = [ + action = [{ + service = "input_select.select_option"; + data = { + entity_id = "input_select.windows_up"; + option = "on"; + }; + }]; + } + { + alias = "enforce window_up state"; + trigger = [ { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/fyrtur1/set"; - payload_template = ''{"position":"90"}''; - }; + platform = "time_pattern"; + minutes = "/5"; # every 5 minutes } { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/fyrtur3/set"; - payload_template = ''{"position":"99"}''; - }; - } - { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/fyrtur4/set"; - payload_template = ''{"position":"99"}''; - }; - } - { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/fyrtur2/set"; - payload_template = ''{"position":"90"}''; - }; + platform = "state"; + entity_id = "input_boolean.windows_up"; } ]; + action = [{ + service = "script.turn_on"; + data_template.entity_id = '' + {% if is_state('input_boolean.windows_up','on') -%} + script.fyrtur_up + {%- else -%} + script.fyrtur_down + {%- endif %} + ''; + }]; } + # heater { - alias = "heater on in the morning"; + alias = "heater state = on1 in the morning"; trigger = [{ platform = "time"; at = "09:00:00"; }]; - action = [ - { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/heater1/set"; # office - payload_template = - ''{"system_mode":"auto","current_heating_setpoint":28.0}''; - }; - } - { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/heater2/set"; # office - payload_template = - ''{"system_mode":"auto","current_heating_setpoint":28.0}''; - }; - } - { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/heater3/set"; # bed room - payload_template = - ''{"system_mode":"auto","current_heating_setpoint":19.0}''; - }; - } - { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/heater4/set"; # storage room - payload_template = - ''{"system_mode":"auto","current_heating_setpoint":19.0}''; - }; - } - ]; + action = [{ + service = "input_select.select_option"; + data = { + entity_id = "input_select.heater_state"; + option = "on1"; + }; + }]; } { - alias = "heater up in the early evening"; + alias = "heater state = on2 in the early evening"; trigger = [{ platform = "time"; at = "19:45:00"; }]; - action = [ - { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/heater1/set"; # office - payload_template = - ''{"system_mode":"auto","current_heating_setpoint":28.0}''; - }; - } - { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/heater2/set"; # office - payload_template = - ''{"system_mode":"auto","current_heating_setpoint":28.0}''; - }; - } - { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/heater3/set"; # bed room - payload_template = - ''{"system_mode":"auto","current_heating_setpoint":28.0}''; - }; - } - { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/heater4/set"; # storage room - payload_template = - ''{"system_mode":"auto","current_heating_setpoint":19.0}''; - }; - } - ]; + action = [{ + service = "input_select.select_option"; + data = { + entity_id = "input_select.heater_state"; + option = "on2"; + }; + }]; } { - alias = "heater off in the evening"; + alias = "heater state = off in the evening"; trigger = [{ platform = "time"; - at = "23:00:00"; + at = "23:30:00"; }]; - action = [ + action = [{ + service = "input_select.select_option"; + data = { + entity_id = "input_select.heater_state"; + option = "off"; + }; + }]; + } + { + alias = "enforce heater state"; + trigger = [ { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/heater1/set"; # office - payload_template = ''{"system_mode":"off"}''; - }; + platform = "time_pattern"; + minutes = "/5"; # every 5 minutes } { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/heater2/set"; # office - payload_template = ''{"system_mode":"off"}''; - }; - } - { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/heater3/set"; # bed room - payload_template = ''{"system_mode":"off"}''; - }; - } - { - service = "mqtt.publish"; - data_template = { - topic = "zigbee2mqtt/heater4/set"; # storage room - payload_template = ''{"system_mode":"off"}''; - }; + platform = "state"; + entity_id = "input_select.heater_state"; } ]; + action = [{ + service = "script.turn_on"; + data_template.entity_id = + "script.heater_{{ states('input_select.heater_state') }}"; + }]; } - ]; group = let @@ -429,6 +356,100 @@ in { }; + script = let + # delay in seconds + delay = 2; + + heater_on = heater: temperatur: { + service = "mqtt.publish"; + data_template = { + topic = "zigbee2mqtt/${heater}/set"; # office + payload_template = '' + {"system_mode":"auto","current_heating_setpoint":${ + toString temperatur + }}''; + }; + }; + heater_off = heater: { + service = "mqtt.publish"; + data_template = { + topic = "zigbee2mqtt/${heater}/set"; # office + payload_template = ''{"system_mode":"off"}''; + }; + }; + + hot = 28; + cold = 19; + + fyrtur_command = device: position: { + service = "mqtt.publish"; + data_template = { + topic = "zigbee2mqtt/${device}/set"; + payload_template = ''{"position":"${toString position}"}''; + }; + }; + + in { + heater_off = { + sequence = [ + (heater_off "heater1") # office + { delay = delay; } + (heater_off "heater2") # office + { delay = delay; } + (heater_off "heater3") # bed room + { delay = delay; } + (heater_off "heater4") # storage room + ]; + }; + heater_on1 = { + sequence = [ + (heater_on "heater1" hot) # office + { delay = delay; } + (heater_on "heater2" hot) # office + { delay = delay; } + (heater_on "heater3" cold) # bed room + { delay = delay; } + (heater_on "heater4" cold) # storage room + ]; + }; + heater_on2 = { + sequence = [ + (heater_on "heater1" hot) # office + { delay = delay; } + (heater_on "heater2" hot) # office + { delay = delay; } + (heater_on "heater3" hot) # bed room + { delay = delay; } + (heater_on "heater4" cold) # storage room + ]; + }; + + fyrtur_up = { + sequence = [ + (fyrtur_command "fyrtur1" 90) + { delay = delay; } + (fyrtur_command "fyrtur2" 90) + { delay = delay; } + (fyrtur_command "fyrtur3" 90) + { delay = delay; } + (fyrtur_command "fyrtur4" 99) + ]; + }; + + fyrtur_down = { + sequence = [ + (fyrtur_command "fyrtur1" 15) + { delay = delay; } + (fyrtur_command "fyrtur2" 15) + { delay = delay; } + (fyrtur_command "fyrtur3" 21) + { delay = delay; } + (fyrtur_command "fyrtur4" 21) + ]; + }; + + }; + }; services.home-assistant = { diff --git a/configs/pepe/home-assistant/zigbee2mqtt/buttons.nix b/configs/pepe/home-assistant/zigbee2mqtt/buttons.nix index da13c78..f10a2af 100644 --- a/configs/pepe/home-assistant/zigbee2mqtt/buttons.nix +++ b/configs/pepe/home-assistant/zigbee2mqtt/buttons.nix @@ -14,18 +14,21 @@ let #groups = [ "living_room" ]; states.single = "input_boolean.situation_toggle"; states.hold = "input_boolean.printer_toggle"; + states.double = "input_boolean.windows_up"; }; "button_2" = { id = "0x00158d0002b04f09"; #groups = [ "bed_room" ]; states.single = "input_boolean.situation_toggle"; states.hold = "input_boolean.printer_toggle"; + states.double = "input_boolean.windows_up"; }; "button_3" = { id = "0x00158d0002b00e04"; #groups = [ "bed_room" ]; states.single = "input_boolean.situation_toggle"; states.hold = "input_boolean.printer_toggle"; + states.double = "input_boolean.windows_up"; }; };