Custom energy sensor doesn't showup in energy devices graph

I have made this sensor:

platform: template
sensors:
  current_electrical_consumption_dhw:
    friendly_name: current electrical consumption dhw
    device_class: power
    unit_of_measurement: W
    value_template: >-
      {% set ElectricPower = states('sensor.l1_power_heatpump') | float %}
      {% set epower = states('sensor.l2_power_heatpump') | float %}
      {% if is_state('binary_sensor.daalderop_daalderop_three_way_valve','off') and ElectricPower > 300 %}
        {{ (ElectricPower + epower) | round(2) }}
      {% else %}
        {{ 0 }}  
      {% endif %}

To convert it to a energy sensor I have used the sum riemann

platform: integration
name: electrical_consumption_dhw
unique_id: f4a58a66-8ef0-11ee-b9d1-0242ac120002
source: sensor.current_electrical_consumption_dhw
unit_prefix: k
round: 3
method: left

and also added state class in the customize.yaml

sensor.electrical_consumption_dhw: 
  friendly_name: electrical consumption dhw
  device_class: energy
  state_class: total_increasing

But it’s not showing up in the devices energy graph.


Look to me that all the attributes are there.
It is driving me nuts!

Your template sensor does not have a state class. Therefore the Riemann Sum sensor will not have a state class. Therefore it can not be used by the energy dashboard.

Legacy template sensors do not have support for state class and will not be getting new features.

You should use the new template sensor format for new sensors.

(configuration.yaml)

template:
  - sensor:
      - name: current electrical consumption dhw
        unique_id: current_electrical_consumption_dhw
        device_class: power
        state_class: measurement
        unit_of_measurement: W
        state: >
          {% set ElectricPower = states('sensor.l1_power_heatpump') | float %}
          {% set epower = states('sensor.l2_power_heatpump') | float %}
          {% if is_state('binary_sensor.daalderop_daalderop_three_way_valve','off') and ElectricPower > 300 %}
            {{ (ElectricPower + epower) | round(2) }}
          {% else %}
            {{ 0 }}  
          {% endif %}
        availability: >
          {{ has_value('sensor.l1_power_heatpump') and 
             has_value('sensor.l2_power_heatpump')  }}

You will need to restart home assistant if this is the first time you have used the new template integration. After that you can use the reload option instead.

I have changed the sensor as suggested
image
Although the (sum riemann) energy sensor increased it is still not showing in the
energy dashboard.
image
Could it be that the addition in the customize.yaml is not needed?
image

It should not be needed.

Delete it and restart.

Then check Developer Tools β†’ Statistics for FIX ISSUE buttons you can press.

1 Like

Ah, that fixed the issue.

Thanks

1 Like