From 9d7222b995f719aea628379d1648d417a67aacb0 Mon Sep 17 00:00:00 2001
From: matt <matthiashermeling@gmail.com>
Date: Tue, 31 Jan 2023 23:09:37 +0100
Subject: [PATCH] esphome & home assistant cleanup

---
 .../templates/config/esphome_plug05.yaml         |  7 +++++++
 .../templates/config/esphome_plug06.yaml         |  7 +++++++
 .../templates/config/esphome_plug07.yaml         |  9 ++++++++-
 .../templates/config/esphome_plug08.yaml         |  7 +++++++
 .../templates/config/esphome_status.yaml         | 16 ++++------------
 .../templates/config/esphome_vortragsraum.yaml   |  2 +-
 .../templates/includes/common.inc.yaml           |  5 ++---
 .../templates/includes/common_info.inc.yaml      |  4 ++--
 .../templates/config/configuration.yaml          |  8 ++++----
 9 files changed, 42 insertions(+), 23 deletions(-)

diff --git a/intern/docker_esphome/templates/config/esphome_plug05.yaml b/intern/docker_esphome/templates/config/esphome_plug05.yaml
index b32bad33..9608a94e 100644
--- a/intern/docker_esphome/templates/config/esphome_plug05.yaml
+++ b/intern/docker_esphome/templates/config/esphome_plug05.yaml
@@ -66,6 +66,13 @@ sensor:
       id: "${plug_name}_Wattage"
     change_mode_every: 8
     update_interval: 10s
+  - platform: total_daily_energy
+    name: ${plug_name}_Energy
+    power_id: "${plug_name}_Wattage"
+
+# Enable time for energy monitoring
+time:
+  - platform: sntp
     
 output:
   # Relay state led
diff --git a/intern/docker_esphome/templates/config/esphome_plug06.yaml b/intern/docker_esphome/templates/config/esphome_plug06.yaml
index c6cb37bf..595a4dbf 100644
--- a/intern/docker_esphome/templates/config/esphome_plug06.yaml
+++ b/intern/docker_esphome/templates/config/esphome_plug06.yaml
@@ -66,6 +66,13 @@ sensor:
       id: "${plug_name}_Wattage"
     change_mode_every: 8
     update_interval: 10s
+  - platform: total_daily_energy
+    name: ${plug_name}_Energy
+    power_id: "${plug_name}_Wattage"
+
+# Enable time for energy monitoring
+time:
+  - platform: sntp
     
 output:
   # Relay state led
diff --git a/intern/docker_esphome/templates/config/esphome_plug07.yaml b/intern/docker_esphome/templates/config/esphome_plug07.yaml
index 6155b29f..89f76ab4 100644
--- a/intern/docker_esphome/templates/config/esphome_plug07.yaml
+++ b/intern/docker_esphome/templates/config/esphome_plug07.yaml
@@ -66,7 +66,14 @@ sensor:
       id: "${plug_name}_Wattage"
     change_mode_every: 8
     update_interval: 10s
-    
+  - platform: total_daily_energy
+    name: ${plug_name}_Energy
+    power_id: "${plug_name}_Wattage"
+
+# Enable time for energy monitoring
+time:
+  - platform: sntp
+
 output:
   # Relay state led
   - platform: esp8266_pwm
diff --git a/intern/docker_esphome/templates/config/esphome_plug08.yaml b/intern/docker_esphome/templates/config/esphome_plug08.yaml
index de646e6b..5c118347 100644
--- a/intern/docker_esphome/templates/config/esphome_plug08.yaml
+++ b/intern/docker_esphome/templates/config/esphome_plug08.yaml
@@ -66,6 +66,13 @@ sensor:
       id: "${plug_name}_Wattage"
     change_mode_every: 8
     update_interval: 10s
+  - platform: total_daily_energy
+    name: ${plug_name}_Energy
+    power_id: "${plug_name}_Wattage"
+
+# Enable time for energy monitoring
+time:
+  - platform: sntp
     
 output:
   # Relay state led
diff --git a/intern/docker_esphome/templates/config/esphome_status.yaml b/intern/docker_esphome/templates/config/esphome_status.yaml
index 1cbf48a2..74d52b1c 100644
--- a/intern/docker_esphome/templates/config/esphome_status.yaml
+++ b/intern/docker_esphome/templates/config/esphome_status.yaml
@@ -17,7 +17,8 @@ sensor:
         input: true
         pullup: true
     unit_of_measurement: 'kW'
-    name: 'Stromverbrauch'
+    device_class: "power"
+    name: esphome_status_Power
     # Herausfilterung von fehlerhaften Impulsen < 20ms
     internal_filter: 20ms
     # Genauigkeit auf 1 Watt
@@ -28,20 +29,11 @@ sensor:
     # Totaler Stromverbrauch seitdem der ESP läuft
     # Eventuell noch abändern auf Stromverbrauch Heute / Woche / Monat und reset durch time (sntp?)
     total:
-      name: "Strom total"
+      device_class: "energy"
+      name: esphome_status_Energy
       unit_of_measurement: "kWh"
       # Genauigkeit auf 1 Watt
       accuracy_decimals: 3
       filters:
         # (800 Impulse / kWh)^-1 = 0.00125kWh
         - multiply: 0.00125
-binary_sensor:
-  - platform: gpio
-    pin: 
-      number: GPIO12
-      mode:
-        input: true
-        pullup: true
-      inverted: true
-    name: "warpzone Status"
-    device_class: presence
diff --git a/intern/docker_esphome/templates/config/esphome_vortragsraum.yaml b/intern/docker_esphome/templates/config/esphome_vortragsraum.yaml
index 7f51d33a..68db8372 100644
--- a/intern/docker_esphome/templates/config/esphome_vortragsraum.yaml
+++ b/intern/docker_esphome/templates/config/esphome_vortragsraum.yaml
@@ -79,4 +79,4 @@ sensor:
       - sliding_window_moving_average:
           window_size: 3
           send_every: 3
-          send_first_at: 3
\ No newline at end of file
+          send_first_at: 3
diff --git a/intern/docker_esphome/templates/includes/common.inc.yaml b/intern/docker_esphome/templates/includes/common.inc.yaml
index cf2ff845..ad3183c9 100644
--- a/intern/docker_esphome/templates/includes/common.inc.yaml
+++ b/intern/docker_esphome/templates/includes/common.inc.yaml
@@ -1,4 +1,3 @@
-
 # WiFi settings 
 wifi:
   ssid: "Internet-of-Shit"
@@ -25,8 +24,8 @@ logger:
 web_server:
 #  local: true
 
-# Activates prometheus /metrics endpoint
-prometheus:
+# Activates api for home assistant
+api:
 
 # MQTT config 
 mqtt:
diff --git a/intern/docker_esphome/templates/includes/common_info.inc.yaml b/intern/docker_esphome/templates/includes/common_info.inc.yaml
index cac792ee..ff181270 100644
--- a/intern/docker_esphome/templates/includes/common_info.inc.yaml
+++ b/intern/docker_esphome/templates/includes/common_info.inc.yaml
@@ -27,8 +27,8 @@ logger:
 web_server:
 #  local: true
 
-# Activates prometheus /metrics endpoint
-prometheus:
+# Activates api for home assistant
+api:
 
 # MQTT config 
 mqtt:
diff --git a/intern/docker_homeassistant/templates/config/configuration.yaml b/intern/docker_homeassistant/templates/config/configuration.yaml
index 48410ea4..a6b7b6b6 100644
--- a/intern/docker_homeassistant/templates/config/configuration.yaml
+++ b/intern/docker_homeassistant/templates/config/configuration.yaml
@@ -104,9 +104,9 @@ sensor:
       - 'date'
       - 'date_time'
 
-automation zonenstatus:
+automation ansible:
   # set zonenstatus
-  - alias: zonenstatus_set
+  - alias: ANSIBLE_zonenstatus_set
     description: Speichert Zonenstatus in einem Helper
     trigger:
       - platform: state
@@ -145,7 +145,7 @@ automation zonenstatus:
     mode: single
 
   # send zonenstatus to MQTT, REST
-  - alias: zonenstatus_send_MQTT_REST
+  - alias: ANSIBLE_zonenstatus_send_MQTT_REST
     description: Sendet den Zonenstatus per MQTT und REST für Shutdown und SpaceAPI
     trigger:
     - platform: time_pattern
@@ -178,7 +178,7 @@ automation zonenstatus:
     mode: single
 
   # send zonenstatus to telegram
-  - alias: zonenstatus_send_telegram
+  - alias: ANSIBLE_zonenstatus_send_telegram
     description: Sendet den Zonenstatus per Telegram-Bot
     trigger:
       - platform: state
-- 
GitLab