From 4288276116a5e1340f1ba21615c87286dd3d0b53 Mon Sep 17 00:00:00 2001
From: 3D <3d@n3rd3d.com>
Date: Sun, 15 Jan 2023 22:59:02 +0100
Subject: [PATCH] update HA config yaml

---
 .../templates/config/configuration.yaml       | 120 ++++++++++++++++--
 1 file changed, 110 insertions(+), 10 deletions(-)

diff --git a/intern/docker_homeassistant/templates/config/configuration.yaml b/intern/docker_homeassistant/templates/config/configuration.yaml
index 54aa79b2..48410ea4 100644
--- a/intern/docker_homeassistant/templates/config/configuration.yaml
+++ b/intern/docker_homeassistant/templates/config/configuration.yaml
@@ -1,4 +1,3 @@
-
 # Loads default set of integrations. Do not remove.
 default_config:
 
@@ -71,24 +70,93 @@ rest_command:
     url: "https://api.warpzone.ms/setstatus?newstatus=CLOSED&update_key={{ warpai_status_update_key }}"
     method: GET 
 
+# https://www.home-assistant.io/integrations/telegram/
+telegram_bot:
+  - platform: polling
+    api_key: "{{ telegram_statusbot_token }}"
+    allowed_chat_ids:
+      - -1001893089134
+      - -1001341516106
+
+notify:
+  - platform: telegram
+    name: zonenstatus
+    chat_id: -1001893089134
+  - platform: telegram
+    name: stromverbrauch
+    chat_id: -1001341516106
 
 ## Automatisierungen ################################################################
 
+# helper to store zonenstatus 
+input_select:
+  zonenstatus:
+    options:
+      - open
+      - closed
+    icon: mdi:door-open
+
+# current time for 
+sensor:
+  - platform: time_date
+    display_options:
+      - 'time'
+      - 'date'
+      - 'date_time'
+
 automation zonenstatus:
+  # set zonenstatus
+  - alias: zonenstatus_set
+    description: Speichert Zonenstatus in einem Helper
+    trigger:
+      - platform: state
+        entity_id:
+          - binary_sensor.switch02
+        from: "off"
+        to: "on"
+      - platform: state
+        entity_id:
+          - binary_sensor.switch02
+        from: "on"
+        to: "off"
+    condition: []
+    action:
+      - choose:
+          - conditions:
+              - condition: state
+                entity_id: binary_sensor.switch02
+                state: "on"
+            sequence:
+              - service: input_select.select_option
+                data:
+                  option: open
+                target:
+                  entity_id: input_select.zonenstatus
+          - conditions:
+              - condition: state
+                entity_id: binary_sensor.switch02
+                state: "off"
+            sequence:
+              - service: input_select.select_option
+                data:
+                  option: closed
+                target:
+                  entity_id: input_select.zonenstatus
+    mode: single
 
-  - alias: Zonenstatus
-    description: Sendet den Zonenstatus per MQTT und REST
+  # send zonenstatus to MQTT, REST
+  - alias: zonenstatus_send_MQTT_REST
+    description: Sendet den Zonenstatus per MQTT und REST für Shutdown und SpaceAPI
     trigger:
-    - platform: state
-      entity_id:
-      - binary_sensor.switch02
+    - platform: time_pattern
+      seconds: /10
     condition: []
     action:
     - choose:
       - conditions:
         - condition: state
-          entity_id: binary_sensor.switch02
-          state: 'on'
+          entity_id: input_select.zonenstatus
+          state: 'open'
         sequence:
         - service: mqtt.publish
           data:
@@ -98,8 +166,8 @@ automation zonenstatus:
           data: {}
       - conditions:
         - condition: state
-          entity_id: binary_sensor.switch02
-          state: 'off'
+          entity_id: input_select.zonenstatus
+          state: 'closed'
         sequence:
         - service: mqtt.publish
           data:
@@ -108,3 +176,35 @@ automation zonenstatus:
         - service: rest_command.set_zone_status_closed
           data: {}
     mode: single
+
+  # send zonenstatus to telegram
+  - alias: zonenstatus_send_telegram
+    description: Sendet den Zonenstatus per Telegram-Bot
+    trigger:
+      - platform: state
+        entity_id:
+          - input_select.zonenstatus
+    condition: []
+    action:
+      - choose:
+          - conditions:
+              - condition: state
+                entity_id: input_select.zonenstatus
+                state: open
+            sequence:
+              - service: telegram_bot.send_message
+                data:
+                  target: -1001893089134
+                  timeout: 30
+                  message: Die warpzone ist seit {{ '{{' }} states('sensor.time') {{ '}}' }} geöffnet!
+          - conditions:
+              - condition: state
+                entity_id: input_select.zonenstatus
+                state: closed
+            sequence:
+              - service: telegram_bot.send_message
+                data:
+                  target: -1001893089134
+                  timeout: 30
+                  message: Die warpzone ist seit {{ '{{' }} states('sensor.time') {{ '}}' }} geschlossen!
+    mode: single
-- 
GitLab