DK1MI.radio

HA: Reading the energy fed into the grid from the meter

For some modern electricity meters there is the possibility to read the current electricity consumption and the meter reading via an optical sensor. Ready-to-buy sensors are available for this purpose, which can be attached directly on the meter’s sensor using the built-in magnet.

DK1MI.radio

This sensor is connected to an ESP8266 board, which then collects and processes the information and makes it available via Wi-Fi. This board has Tasmota installed as firmware in my case.

DK1MI.radio

Home Assistant users who have a photovoltaic system but no two-way electricity meter can often unfortunately only read out the current electricity consumption, but not the energy fed into the grid. In the case of my meter, however, this value is positive when energy is taken from the grid and negative when energy is fed into the grid.

In this case, by defining two new sensors within Home Assistant, it is possible to split the determined value and thus create one sensor each for the energy drawn and for the energy fed into the grid.

These two pseudo sensors can be created by editing the file ~/config/configuration.yaml and add the following code block:

template:
  - sensor:
      - name: "Entnahme aus dem Netz"
        unit_of_measurement: "W"
        state_class: measurement
        device_class: energy
        unique_id: gridin
        state: >
          {% if states('sensor.stromzaehler_aktuelle_wirkleistung') | float(0) > 0 %}
            {% set gridin = states('sensor.stromzaehler_aktuelle_wirkleistung') | float(0) %}
          {% else %}
            {% set gridin = 0 %}
          {% endif %}
          {{ gridin }}          
        attributes:
          last_reset: '1970-01-01T00:00:00+00:00'

      - name: "Einspeisung ins Netz"
        unit_of_measurement: "W"
        state_class: measurement
        device_class: energy
        unique_id: gridout
        state: >
          {% if states('sensor.stromzaehler_aktuelle_wirkleistung') | float(0) < 0 %}
            {% set gridout = (states('sensor.stromzaehler_aktuelle_wirkleistung') | float | abs) %}
          {% else %}
            {% set gridout = 0 %}
          {% endif %}
          {{ gridout }}          
        attributes:
          last_reset: '1970-01-01T00:00:00+00:00'

The above code is heavily inspired by the following thread: (solved) Help getting a value from negative to positive in template (*-1)

You might want or need to adapt the following parameters:

The following is a screenshot from my dashboard showing from top to down:

DK1MI.radio

Thank you for reading! If you have any comments or questions, please send me an e-mail.

#Home Assistant