Add a mqtt entity to energy dashboard

Hi!
My heat pump (brand IVT), is connected to HA with mqtt (autodiscovery). I would want to have some values added in the energy dashboard. Especially the heat energy comsumption and the warm water comsumption. I already use these values to track my daily consumption - that was easy with a helper.
But how can I make these accepted by the energy dashboard? I tried to create sensors and helpers that copied the values, but that didn’t help. I’m a newbie, so please explain as if I was a true beginner.
Thanks!

It must have the right device_class

EDIT: like this, in yaml

        device_class: energy
        state_class: measurement

and the correct state_class (total, total_increasing or measurement) …

1 Like

I use

- platform: template

and that don’t seem to support state_class.
I had already device_class: energy.
Is the platform (template) wrong way to go?
/Fanan

yes, that’s the “legacy” mode (old) and does not use all the new implementations.
I would recommend that you go with the newer templateing mode (below an example)

template:

  - sensor:
      - name: "Solaredge Calculated m1 Import"
        unique_id: "solaredge_calculated_m1_import"
        icon: mdi:transmission-tower-import
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        state: >
          {% set measured_import = states('sensor.solaredge_m1_imported_kwh') | float(0) %}
          {% set imported_before_meter_installation = 296.00 | float(0) %}
          {{ (measured_import + imported_before_meter_installation) | round(3, 0) }}
        availability: >
          {{ states('sensor.solaredge_m1_imported_kwh') not in ['unknown', 'unavailable', 'None'] }}

  - sensor:  
    - name: your_name
      unique_id: 'unique_id'
      unit_of_measurement: L
      device_class: volume
      state_class: measurement
      state: >
        {% set max_filllevel = 3000 | float(0) %}
        {% set current_filllevel = states('sensor.oilfox_filllevelquantity') | float(0) %}
        {% set fuelused = max__filllevel - current_filllevel | float(0) %}
        {{ '{:.2f}'.format(fuelused) }}
      availability: >
          {{ states('sensor.oilfox_filllevelquantity') not in ['unknown', 'unavailable', 'None'] }}
1 Like

Thanks! Now it’s working!
/Fanan

I was wrong. On the surface everything was ok. But the new entity don’t change - it’s still zero, which is far from the truth. What am I missing? This is my code (in my template.yaml):

- sensor:
    - name: "Bergvärmens energiåtgång"
      unique_id: "bergvarme_energiatgång"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: measurement
      state: >
        {% set measured_import = states('sensor.supp_energy_heating') | float(2) %}
      availability: >
        {{ states('sensor.supp_energy_heating') not in ['unknown', 'unavailable', 'None'] }}

This code worked (finally):

Template:
  - sensor:
    - name: "Bergvärmen i kWh"
      unique_id: "bergvarmen_i_kwh"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      state: "{{ states('sensor.compr_cons_heating')|float(0) }}"
      availability: "{{ states('sensor.compr_cons_heating')|is_number }}"