Sensor template values and energy dashboard do not match

I track the energy consumption of the whole house from my electricity meter.
Also I track a few specific devices.

I tried to create a miscellaneous sensor which should display the power consumption of all other non tracked devices.
Whole energy consumption - all tracked devices = all non tracked devices

template:
  - sensor:
      - name: "Stromverbrauch Sonstiges (Licht, Steckdosen, etc.)"
        device_class: 'energy'
        state_class: 'total_increasing'
        unit_of_measurement: "kWh"
        state: >
          {% set state1 = states('sensor.stromzahler_gesamtverbrauch_volkszahler_daily')|float(0) %}
          {% set state2 = states('sensor.stromverbrauch_backofen_daily')|float(0) %}
          {% set state3 = states('sensor.stromverbrauch_bad_e_heizkorper_daily')|float(0) %}
          {% set state4 = states('sensor.stromverbrauch_buro_daily')|float(0) %}
          {% set state5 = states('sensor.stromverbrauch_geschirrspuler_daily')|float(0) %}
          {% set state6 = states('sensor.stromverbrauch_hebeanlage_daily')|float(0) %}
          {% set state7 = states('sensor.stromverbrauch_heizung_daily')|float(0) %}
          {% set state8 = states('sensor.stromverbrauch_kuhlschrank_daily')|float(0) %}
          {% set state9 = states('sensor.stromverbrauch_netzwerkschrank_daily')|float(0) %}
          {% set state10 = states('sensor.stromverbrauch_steckdose_eg_wohnen_tv_daily')|float(0) %}
          {% set state11 = states('sensor.stromverbrauch_trockner_daily')|float(0) %}
          {% set state12 = states('sensor.stromverbrauch_waschmaschine_daily')|float(0) %}
          {{ (( state1 * 1000 - ( state2 + state3 + state4 + state5 + state6 + state7 + state8 + state9 + state10 + state11 + state12)) / 1000) | round(2) }}
        availability: >
          {{ states('sensor.stromzahler_gesamtverbrauch_volkszahler_daily')|is_number and
             states('sensor.stromverbrauch_backofen_daily')|is_number and
             states('sensor.stromverbrauch_bad_e_heizkorper_daily')|is_number and
             states('sensor.stromverbrauch_buro_daily')|is_number and
             states('sensor.stromverbrauch_geschirrspuler_daily')|is_number and
             states('sensor.stromverbrauch_hebeanlage_daily')|is_number and
             states('sensor.stromverbrauch_heizung_daily')|is_number and
             states('sensor.stromverbrauch_kuhlschrank_daily')|is_number and
             states('sensor.stromverbrauch_netzwerkschrank_daily')|is_number and
             states('sensor.stromverbrauch_steckdose_eg_wohnen_tv_daily')|is_number and
             states('sensor.stromverbrauch_trockner_daily')|is_number and
             states('sensor.stromverbrauch_waschmaschine_daily')|is_number }}

My problem is that the overview of the miscellaneous devices in energy dashboard does not display the correct value.


I also tried to create a template sensor with state_class: ‘total’ but it’s a similar behaviour. The values are different but not diplayed correctly in energy dashboard.

Do you have an idea what could be the cause and how to solve this?

I have a similar setup and result, albeit with a lot less sensors.
In past releases there were issues with the statistics but I have not yet investigated if these still exist. As this is not urgent for me, did not spend time on it in favor of other things :slight_smile:

I finally fixed this.

Everything I need to do was removing the helper entities. I created them to have the daily consumption of the unique sensors but this was not necessary. With the total values it’s working fine :slight_smile:

template:
  - sensor:
      - name: "Stromverbrauch Sonstiges"
        device_class: 'energy'
        state_class: 'total_increasing'
        unit_of_measurement: "kWh"
        state: >
          {% set sta1 = states('sensor.stromzaehler_gesamtverbrauch_volkszaehler')|float(0) %}
          {% set sta2 = states('sensor.stromverbrauch_backofen')|float(0) %}
          {% set sta3 = states('sensor.stromverbrauch_bad_e_heizkorper')|float(0) %}
          {% set sta4 = states('sensor.stromverbrauch_buro')|float(0) %}
          {% set sta5 = states('sensor.stromverbrauch_geschirrspuler')|float(0) %}
          {% set sta6 = states('sensor.stromverbrauch_gefrierschrank')|float(0) %}
          {% set sta7 = states('sensor.stromverbrauch_heizung')|float(0) %}
          {% set sta8 = states('sensor.stromverbrauch_kuhlschrank')|float(0) %}
          {% set sta9 = states('sensor.stromverbrauch_netzwerkschrank')|float(0) %}
          {% set sta10 = states('sensor.stromverbrauch_steckdose_eg_wohnen_tv')|float(0) %}
          {% set sta11 = states('sensor.stromverbrauch_trockner')|float(0) %}
          {% set sta12 = states('sensor.stromverbrauch_waschmaschine')|float(0) %}
          {{ (( sta1 * 1000 - ( sta2 + sta3 + sta4 + sta5 + sta6 + sta7 + sta8 + sta9 + sta10 + sta11 + sta12)) / 1000) | round(2) }}
        availability: >
          {{ states('sensor.stromzaehler_gesamtverbrauch_volkszaehler')|is_number and
             states('sensor.stromverbrauch_backofen')|is_number and
             states('sensor.stromverbrauch_bad_e_heizkorper')|is_number and
             states('sensor.stromverbrauch_buro')|is_number and
             states('sensor.stromverbrauch_geschirrspuler')|is_number and
             states('sensor.stromverbrauch_gefrierschrank')|is_number and
             states('sensor.stromverbrauch_heizung')|is_number and
             states('sensor.stromverbrauch_kuhlschrank')|is_number and
             states('sensor.stromverbrauch_netzwerkschrank')|is_number and
             states('sensor.stromverbrauch_steckdose_eg_wohnen_tv')|is_number and
             states('sensor.stromverbrauch_trockner')|is_number and
             states('sensor.stromverbrauch_waschmaschine')|is_number }}