From 4d2c5b0cbaf15c4b4bd63d789630887a47e23c03 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Sun, 25 Jun 2023 22:41:46 +0200 Subject: [PATCH] Completely new Energy monitoring, with cumulative import, export and consumption. --- configuration.yaml | 21 +------------- sensors.yaml | 23 +++++++++++++++ template.yaml | 71 +++++++++++++++++++++++++++++++++++++++++++++ utility_meters.yaml | 27 +++++++++++++++++ 4 files changed, 122 insertions(+), 20 deletions(-) create mode 100644 template.yaml diff --git a/configuration.yaml b/configuration.yaml index bc3aa48..f7b8c44 100644 --- a/configuration.yaml +++ b/configuration.yaml @@ -38,26 +38,7 @@ utility_meter: !include utility_meters.yaml mqtt: !include mqtt.yaml # Template sensors -template: - - sensor: - - name: "Leckstrom" - unit_of_measurement: "W" - icon: mdi:flash - state: > - {% set total = states('sensor.netzleistung') | float %} - {% set solar = states('sensor.balkonkraftwerk_power') | float %} - {% set raumduft = states('sensor.flur_raumduft_power') | float %} - {% set keller = states('sensor.keller_power') | float %} - {% set anrichte = states('sensor.kuche_anrichte_power') | float %} - {% set musik = states('sensor.kuche_musik_power') | float %} - {% set bett = states('sensor.schlafzimmer_bett_power') | float %} - {% set heimkino_sz = states('sensor.schlafzimmer_heimkino_power') | float %} - {% set deko = states('sensor.schreibtisch_deko_power') | float %} - {% set schreibtisch = states('sensor.schreibtisch_power') | float %} - {% set serverraum = states('sensor.serverraum_power') | float %} - {% set heimkino_wz = states('sensor.wohnzimmer_heimkino_power') | float %} - {% set spieleschrank = states('sensor.wohnzimmer_spieleschrank_power') | float %} - {{ (total + solar - raumduft - keller - musik - bett - heimkino_sz - deko - schreibtisch - serverraum - heimkino_wz - spieleschrank) | round(1) }} +template: !include template.yaml # calendar integration calendar: !include calendars.yaml diff --git a/sensors.yaml b/sensors.yaml index 160dce5..a7daa72 100644 --- a/sensors.yaml +++ b/sensors.yaml @@ -69,3 +69,26 @@ friendly_name: "Sun Setting Template" value_template: "{{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom ('%H:%M') }}" + # Sensor for Riemann sum of energy import (W -> Wh) + - platform: integration + source: sensor.power_import + name: energy_import_sum + unit_prefix: k + round: 2 + method: left + + # Sensor for Riemann sum of energy export (W -> Wh) + - platform: integration + source: sensor.power_export + name: energy_export_sum + unit_prefix: k + round: 2 + method: left + + # Sensor for Riemann sum of energy consumption (W -> Wh) + - platform: integration + source: sensor.power_consumption + name: energy_consumption_sum + unit_prefix: k + round: 2 + method: left diff --git a/template.yaml b/template.yaml new file mode 100644 index 0000000..7063ea7 --- /dev/null +++ b/template.yaml @@ -0,0 +1,71 @@ + - sensor: + - name: "power_other" + unit_of_measurement: "W" + icon: mdi:flash + state: > + {% set total = states('sensor.netzleistung') | float %} + {% set solar = states('sensor.balkonkraftwerk_power') | float %} + {% set raumduft = states('sensor.flur_raumduft_power') | float %} + {% set keller = states('sensor.keller_power') | float %} + {% set anrichte = states('sensor.kuche_anrichte_power') | float %} + {% set musik = states('sensor.kuche_musik_power') | float %} + {% set bett = states('sensor.schlafzimmer_bett_power') | float %} + {% set heimkino_sz = states('sensor.schlafzimmer_heimkino_power') | float %} + {% set deko = states('sensor.schreibtisch_deko_power') | float %} + {% set schreibtisch = states('sensor.schreibtisch_power') | float %} + {% set serverraum = states('sensor.serverraum_power') | float %} + {% set heimkino_wz = states('sensor.wohnzimmer_heimkino_power') | float %} + {% set spieleschrank = states('sensor.wohnzimmer_spieleschrank_power') | float %} + {{ (total + solar - raumduft - keller - musik - bett - heimkino_sz - deko - schreibtisch - serverraum - heimkino_wz - spieleschrank) | round(1) }} + device_class: power + state_class: measurement + attributes: + last_reset: '1970-01-01T00:00:00+00:00' + +# Shelly 3EM cumulative sensors (incl. PV) + - sensor: + # Template sensor for values of power import (active_power > 0) + - name: power_import + unit_of_measurement: 'W' + state: > + {% if (states('sensor.line_power_channel_a_power')|float + states('sensor.line_power_channel_b_power')|float + states('sensor.line_power_channel_c_power')|float) > 0 %} + {{ states('sensor.line_power_channel_a_power')|float + states('sensor.line_power_channel_b_power')|float + states('sensor.line_power_channel_c_power')|float }} + {% else %} + {{ 0 }} + {% endif %} + device_class: power + state_class: measurement + icon: mdi:transmission-tower-export + attributes: + last_reset: '1970-01-01T00:00:00+00:00' + + # Template sensor for values of power export (active_power < 0) + - name: power_export + unit_of_measurement: 'W' + state: > + {% if (states('sensor.line_power_channel_a_power')|float + states('sensor.line_power_channel_b_power')|float + states('sensor.line_power_channel_c_power')|float) < 0 %} + {{ (states('sensor.line_power_channel_a_power')|float + states('sensor.line_power_channel_b_power')|float + states('sensor.line_power_channel_c_power')|float) * -1 }} + {% else %} + {{ 0 }} + {% endif %} + device_class: power + state_class: measurement + icon: mdi:transmission-tower-import + attributes: + last_reset: '1970-01-01T00:00:00+00:00' + + # Template sensor for values of power consumption + - name: power_consumption + unit_of_measurement: 'W' + state: > + {% if (states('sensor.power_export')|float(0)) > 0 and (states('sensor.balkonkraftwerk_power')|float(0) - states('sensor.power_export')|float(0)) < 0 %} + {% elif (states('sensor.power_export')|float(0)) > 0 and (states('sensor.balkonkraftwerk_power')|float(0) - states('sensor.power_export')|float(0)) > 0 %} + {{ (states('sensor.balkonkraftwerk_power')|float(0)) - states('sensor.power_export')|float(0) }} + {% else %} + {{ states('sensor.power_import')|float(0) + states('sensor.balkonkraftwerk_power')|float(0) }} + {% endif %} + device_class: power + state_class: measurement + icon: mdi:home-lightning-bolt + attributes: + last_reset: '1970-01-01T00:00:00+00:00' diff --git a/utility_meters.yaml b/utility_meters.yaml index 70b2fc2..ec5f011 100644 --- a/utility_meters.yaml +++ b/utility_meters.yaml @@ -1,3 +1,4 @@ +# Internet traffic internet_usage_in_monthly: source: sensor.snmp_wan_in name: Monthly internet traffic in @@ -22,3 +23,29 @@ source: sensor.snmp_wan_out name: Hourly internet traffic out cycle: hourly + +# Energy + energy_import_daily: + source: sensor.energy_import_sum + name: Energy Import Daily + cycle: daily + energy_import_monthly: + source: sensor.energy_import_sum + name: Energy Import Monthly + cycle: monthly + energy_export_daily: + source: sensor.energy_export_sum + name: Energy Export Daily + cycle: daily + energy_export_monthly: + source: sensor.energy_export_sum + name: Energy Export Monthly + cycle: monthly + energy_consumption_daily: + source: sensor.energy_consumption_sum + name: Energy Consumption Daily + cycle: daily + energy_consumption_monthly: + source: sensor.energy_consumption_sum + name: Energy Consumption Monthly + cycle: monthly