MQTT sensors in energy dashboard through autodiscovery

Hi

I’m trying to add some energy measurements done by an ESP32 and sent over MQTT to the HA energy dashboard, using MQTT autodiscovery for creating the sensors. Somehow I managed to get this working on 2021.6, but when I revisited this project on 2021.11 I could not get it working any more.

I create the sensor by sending {"name": "house total energy", "device_class": "energy", "state_class":"measurement", "unit_of_measurement":"kWh", "state_topic": "homeassistant/sensor/house_total_energy/state"} to homeassistant/sensor/house_total_energy/config.

This succesfully creates the sensor and it displays the state updates on the states page. On the energy dashboard however, it’s not available for selection.

I’ve tried adding "last_reset": "1970-01-01T00:00:00+00:00", "last_reset_topic": "homeassistant/sensor/house_total_energy" and "unique_id":"house_energy" to the payload, and changing "state_class" to "total_increasing", but to no avail.

I can’t see anywhere in the docs what I could be doing wrong. Is perhaps something missing in the MQTT autodiscovery?

Hi!
Did you solve this? I have the same problem.

To be available as an input to the energy dashboard, the sensor needs to be tracked by the recorder/history component. I only tracked sensors I included manually in my configuration.yaml. Adding it to history made the sensor available in the energy dashboard.

Also, I think my example message needs a unique_id field as well.