How to sum many total_increasing sensors as a total_increasing sensor?

Hi,
I have a lot of devices which report kWh energy consumption which act as proper “total_increasing” sensor: They reset to 0 at regular ticks and continue counting. I’d like to calculate the sum of these to use in the energy panel as a proxy for a full house energy meter. I’ve used How to sum energy and power sensors? - #6 by chemelli to create a sum of these like this:

template:
  - trigger:
    - platform: time_pattern
      minutes: "*"
    sensor:
      - name: "Energy cumulative"
        unique_id: all_energy_kWh
        unit_of_measurement: 'kWh'
        device_class: energy
        state_class: total_increasing
        state: >-
            {%set ns = namespace(values=[]) %}
            {%set ss = states.sensor|rejectattr('entity_id', 'eq', 'sensor.energy_cumulative')|selectattr('attributes.unit_of_measurement', 'eq', 'kWh')|list%}
            {%for s in ss%}
                {%set ns.values = ns.values + [ s.state|float ]%}
            {%endfor%}
            {{ns.values|sum}}

… but when any one of these input sensors reset to zero, of course the sum doesn’t reset to zero, and the total_increasing calculation makes it look like there was a ton of consumption all at once.

Is there a nice way of getting this to work where you sum up a bunch of total_increasing sensors and either reset the sum to zero (by storing some offset somewhere maybe?) or just getting a real total out of it instead of using total_increasing for the end sum?

Thanks for any help, including links to obvious places I should have searched. :slight_smile:

2 Likes

Had any response? I was hoping this was already done, but it otherwise will have to be done as an automation when one of the sensors resets…

Hi Alge,
How did you go, I am trying the same, want a sensor for each room measuring the energy (total)

same problem here. Maybe solution is to create an intermediate or proxy total_increasing sensor for every original sensor and sum those proxies.

Example:
two measurements of kWh. M1 and M2.
two proxies: m1 and m2
total: T

Initial situation:
M1: 500
M2: 900
m1: 500
m2 900
T: 1400

M1 resets and counts to 100, M2 counts to 1100
M1: 100
M2: 1100
m1: 600
m2 1100
T: 1700

Think should do the trick. Will test and report back

1 Like

Tested. Ussing intermediate total_increasing sensors does not help It produces the same result that the total sum.

But using utility meter helpers as proxies does it. Create an utility meter for each source and sum the utility meters. The fact is that the best solutions and the one that makes more sense is a modification of the utility meter helper that could use multiple sensors as source.

Sorry, I ended up getting a full house energy meter sensor. (: