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 }}
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;
And here is the history for 120v charger and level 2 charger;
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?
@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.