How can I merge the values of 2 meters into 1 and use them in the energy dashboard?


I need a bit help… My heat pump has two energy meters, one for the indoor unit and 1 for the outdoor unit. At the moment I’ve added these separate to the energy dashboard but I like to have 1 which merge these values.

I started with this code:

  - platform: template
        unique_id: 094412db-6903-4897-911f-b40e0e41ea28
        friendly_name: "Energieverbruik warmtepomp"
        device_class: energy
        unit_of_measurement: kWh
        value_template: "{{ states('sensor.extra_total') | float + states('sensor.extra_total_2') | float }}"

The new sensor adds the values together but I cannot add the sensor in the energy dashbord as individual device.

So I added state_class: total_increasing but that doesn’t do the trick. When I check my configuation it states:

Configuration warnings
Invalid config for ‘template’ from integration ‘sensor’ at configuration.yaml, line 20: ‘state_class’ is an invalid option for ‘sensor.template’, check: sensors->energieverbruik_warmtepomp->state_class

I cannot figure out what I’m doing wrong. Can anyone help or point me into the right direction?

Thanks! :pray:

Edit: I’ve already found the solution, add a utility meter with the combined entity ID :slight_smile:

That is another way to solve it.The problem with your template was that it is and old style template sensor definition. New style you should define the sensor under the top level template: and not sensor:

You are setting yourself up for failure. This sensor will create havoc with the energy dashboard unless both sensors are always reporting valid values.

If one of your sensors becomes unavailable the total will drop. When the sensor returns the total will increase. This increase will be logged incorrectly as energy use.

To combat this issue you must use an availability template.

  - sensor:
      - name: "Energieverbruik warmtepomp"
        unique_id: 094412db-6903-4897-911f-b40e0e41ea28
        device_class: energy
        state_class: total_increasing
        unit_of_measurement: kWh
        state: "{{ states('sensor.extra_total') | float + states('sensor.extra_total_2') | float }}"
        availability: "{{ has_value('sensor.extra_total') and has_value('sensor.extra_total_2') }}"

This will mark the total sensor as unavailable if one or both the source sensors are not reporting numbers. This will prevent the issue as changing from unavailable to some value will not cause an energy reading to be logged.


Thank you very much Tom, you’re the best!!