Combine multiple total_daily_energy and energy sensors for Energy Dashboard

I am using multiple ESPHome plugs which provide total_daily_energy measurements, which reset daily, and energy sensors from shellies, which reset at reboot, and some energy sensors which never reset (GitHub - bramstroker/homeassistant-powercalc: Custom component to calculate estimated power consumption of lights and other appliances).

I want to sum up all these sensors to be able to use the Energy Dashboard, as I don’t have a way of reading out my power meter.

I’ve tried it with this, but unfortunately the data lead to a reset at 00:00 and the dashboard reporting me feeding energy into the grid, which of course did not happen:

- sensor:
    - name: "Strom"
      unit_of_measurement: "kWh"
      device_class: "energy"
      state_class: "total_increasing"
      state: >
        {% set ns = namespace(states=[]) %}
        {% for s in states.sensor %}
          {% if s.object_id.endswith('_energy') or s.object_id.endswith('_tagesverbrauch') or s.object_id.endswith('_tagesverbrauch_2') or s.object_id.endswith('_tagesverbrauch_3') %}
            {% set ns.states = ns.states + [ s.state | float(default=0) ] %}
          {% endif %}
        {% endfor %}
        {{ ns.states | sum }}
1 Like

Go to the History tab and add all the entities you’re summing. You’ll probably see the problem. If not, post a screenshot of that history graph.

Getting templates to work with the HA energy features is an exercise in choosing the right mix of state_classes and utility helpers. Read up on total vs total_increasing state classes. That’s probably where I’d start making changes.

I am having exactly this same problem. My smartplug entities have a total_daily_energy attribute that resets at midnight every night. However, my Riemann Integration entities and template energy total entities do not reset at midnight. For example;

  - platform: integration
    source: sensor.furnace 
    name: Furnace kWh
    unit_prefix: k
    unique_id: furnacekwhintegration

image

and for templates;

template:
  - sensor:
      - name: "Transportation"
        unique_id: transportationconsumptionauto
        state_class: total
        device_class: energy
        unit_of_measurement: "Wh"
        state: >
          {% set clarity= states('sensor.120v_charger_energy') | float %}
          {% set soul = states('sensor.level_2_charger_energy') | float %}
          {{ ((clarity + soul) | float(0.0) | round (2)) }}

image

And here is the history for 120v charger and level 2 charger;

image

image

So none of my Riemann integration entities and Template total entities are resetting at midnight. How can we get them to do so, so that we can use them in daily energy calculations?

Use a utility meter?

utility_meter:
  solar_panel_production_daily:
    source: sensor.solar_panel_production_kwh
    name: Solar Panel Production Daily
    cycle: daily

@SgtBatten that gives me only one overall entity that resets. I can reset at various intervals (month, week, day, etc) though does not do so for all energy entities.

Reading your post I assumed you were looking for how to reset an entity daily.