How to define the device_class: energy for a riemann integration sensor?

Hello

For the new energy integration available in 2021.08, i need to define an energy sensor.

I use an OWL cm180i meter with 3 clamps.
Each clamp gives me a ‘Power’ information. I use the Riemann integration to transform Power in Energy.

The question is 'how to set the device_class: energy to the energy sensor provided by the Riemann integration

a) device_class: energy in the Riemann integration sensor is not allowed
b) use of customize_glob is not working

sensor.*_kWh_*:
  last_reset: "1970-01-01T00:00:00+00:00"
  device_class: energy
  state_class: measurement
#

and the status
Screenshot 2021-08-06 15.37.36

is this a feature request ?
or any other idea ?

Thanks for your suggestion

here what I did

added

  device_class: energy
  state_class: measurement
  unit_of_measurement: "kWh"

to the MQTT Platform

then in the customize.yaml added

sensor.washing_energy_today:
      last_reset: "2021-07-30T00:00:00+00:00"

for all the

  state_class:

note it error in VSC think that update is coming

but did the config check

and restart

and I see them in the list now

From the source code, if the source entity has a “power” device_class, the integrated entity will automatically have the “energy” device_class.

3 Likes

Here the source entity status: (device_class: power)
Screenshot 2021-08-06 17.58.24

the riemann integration

platform: integration
source: sensor.chauffage_en_watt
name: Compteur Chauffage kWh
unit_prefix: k
method: left
round: 2
unit: kWh
#device_class: energy
#state_class: measurement 

and the status of the integrated entity
Screenshot 2021-08-06 18.00.53

Obviously the integrated entity does not have the energy device_class.
Do you think it’s a bug ?
Thanks

  1. The code has been added recently. It’s there in 2021.8.1, but not sure it’s in .0
  2. There is a semi-bug in that the device_class is only added after the source has updated at least once.

I’m running core-2021.8.1
I will wait tll tomorrow and see
What do you call a cycle ? Is it related to statistics ?

The “unit_time” of integration, which is “h” by default.

I’ve just checked and good news !
I have 3 different sensors with the same structure :
2 are activated and have the device_class; energy
1 (the one I was looking for) is dormant with no measure (chauffage means heater) with no device_class:energy

This solve the issue
Thanks

Cool. I’ve updated my previous post. The code indeed only adds the device_class after the source entity state has been updated at least once.