How to add mqtt sensor to energy dashboard?

I have a Sonoff S31 smart plug running Tasmota which is integrated into HA via the MQTT integration. It was auto-discovered, I did not configure it in YAML. (Note: it’s using the MQTT integration, not the Tasmota integration. I’d prefer not to change that if possible.)

Two of the sensors on the entity return power in kWh - Total energy and Daily energy. However, they do not show up in the drop-down list on the energy configuration screen, so I can’t add them to the energy dashboard.

I think this is because their device_class isn’t set to ‘energy’, but I can’t find a way to set it. Is there a solution for this?

Note: I’ve also tried to use the Riemann sum integral sensor to integrate the plug’s Power senor, which is in W, but that doesn’t seem to work either. It seems to correctly report kWh, but I can’t add it to the dashboard either.

Hey :slight_smile:
I have my grid consumption coming from MQTT, to integrate it, here is what I had to add in customize.yaml

sensor.index_wh:
  state_class: total_increasing
  device_class: energy

Where sensor.index_wh is my consumption in Wh. Will work with your sensor in kWh :slight_smile:

Oh, apply this to the sensor wich is the Total energy, not the daily.

Does this still work after core 2022.2.0 update?

On my setup this still works fine !


image
image

Edit :
Wow my bad I changed from MQTT to influxDB sensor ! So for MQTT sensors you should add this to the MQTT sensor configuration :

When i add this, my configuration check lasts to infinity…