Calculate grid production to use in energy dashboard

I’ve just started to get familiar with HA and pull values of power consumption and production. I’d like to have a nice graph like the energy dashboard to show both.
At the electricity meter (Apator Norax 3D) I use an IR-reader with Tasmota to get the consumption values. Unfortunately there is the total for consumption only, not for return to grid. But I can read the current consumption with can be positiv (for consumption) or negative for feed).
Furthermore I run a mini PV system. Those values I pull via command line.
So, I have total consumption and total production. What’s missing for the dashboard is the value of return to grid.
Is there any way to calculate that?

Currently my configuration.yaml looks as follows:

default_config:

frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
command_line:
  - sensor:
      name: "power_balkon_pv_now"
      command: curl -s -u user:pass http://192.168.xx.xx/status.html | grep -E "\webdata_now_p(\s|$)" | cut -d'"' -f 2
      unit_of_measurement: 'W'
      scan_interval: 60
  - sensor:
      name: "power_balkon_pv_total"
      command: curl -s -u user:pass  http://192.168.xx.xx/status.html | grep -E "\webdata_total_e(\s|$)" | cut -d'"' -f 2
      unit_of_measurement: 'kWh'
      scan_interval: 120
template:
  - sensor:    
      - name: "Stromzähler Gesamt Verbrauch"
        unique_id: "StromVerbrauch"
        unit_of_measurement: 'kWh'
        device_class: "energy"
        state_class: "total_increasing"
        state: >-
            {{ float(states('sensor.tasmota_sml_total_in')) | round(3) }}
  - sensor:    
      - name: "Stromzähler Aktuell"
        unique_id: "StromAktuell"
        unit_of_measurement: 'W'
        device_class: "energy"
        state_class: "total"
        state: >-
            {{ states('sensor.tasmota_sml_power_cur') }}
- sensor:    
      - name: "Stromzähler Aktuell"
        unique_id: "StromAktuell"
        unit_of_measurement: 'W'
        device_class: "energy"
        state_class: "total"
        state: >-
            {{ states('sensor.tasmota_sml_power_cur') }}
  - sensor:    
      - name: "Stromzähler Aktuell Verbrauch"
        unique_id: "StromAktuellVerbrauch"
        unit_of_measurement: 'W'
        device_class: "energy"
        state_class: "total"
        state: >-
            {% set curr_power = states('sensor.tasmota_sml_power_curr') | float %}
            {% if curr_power > 0 %}
              {{ curr_power }}
            {% else %}
              {{ 0 }}
            {% endif %}
  - sensor:
      - name: "Stromzähler Aktuell Einspeisung"
        unique_id: "StromAktuellEinspeisung"
        unit_of_measurement: 'W'
        device_class: "energy"
        state_class: "total"
        state: >-
            {% set curr_power = states('sensor.tasmota_sml_power_curr') | float %}
            {% if curr_power < 0 %}
              {{ -curr_power }}
            {% else %}
              {{ 0 }}
            {% endif %}
  - sensor:
      - name: "Terasse Erzeugung Total"
        state: "{{ states('sensor.power_balkon_pv_total') if states('sensor.power_balkon_pv_total') | float > 0 }}"
        unit_of_measurement: 'kWh'
        device_class: "energy"
        state_class: "total_increasing"
        unique_id: "balkon_pv_energy"
  - sensor:
      - name: "Terasse Erzeugung Aktuell"
        state: "{{ states('sensor.power_balkon_pv_now') }}"
        unit_of_measurement: 'W'
        device_class: "energy"
        state_class: "measurement"
        unique_id: "balkon_pv_energy_now"

Thank you for any hints!

You can make two separate template power sensors from the original: one for when power is negative and one for when it’s positive (make both outputs positive though). You have the right idea, but you cannot take a power value, and just by splitting it, get to energy. See the next point.

Then use a Rieman integration with method left (might be the default now) to get energy. You can then use these two energy sensors in the energy dashboard.

If the power will be fluctuating quite a bit between positive and negative, this might not be very accurate. My inverter for example trickle charges at times.

That is it. Thank you a lot! I wasn’t aware of this integration.

1 Like