How to supplement MQTT discovery to add state_class

I have a tasmota device that is setting up a discovery topic as below - note how it does not have a “state_class: measurement” field, and so the entity is not usable as a statistic.


I don’t have control of the discovery setup (it uses blerry). Is there a way that I can “add” the state_class?

Aside: I thought I could try to create a new sensor as follows, but I still cannot see the entity as a statistic.

  - sensor:
    - name: "Temperature"
      state_topic: "tele/tasmota_blerry/govee_sensor"
      state_class: measurement
      device_class: temperature
      json_attributes_topic: tele/tasmota_blerry/govee_sensor
      unique_id: govee_sensor_Temperature
      value_template: '{{ value_json.Temperature }}'

Thanks for any tips.

Yes, you can customise entities.

Customizing entities - Home Assistant

EDIT: Pasted the wrong link.

Pieter, I am wanting to add “state_class: measurement” to a sensor that is defined via MQTT discovery and lacking this setting.

Your answer doesn’t seem relevant - it permits the name, ID, etc., of an entity to be updated - am I missing your point?

      state_class: measurement

You should already have


in your configuration.yaml, so just add the remaining

Seems that page has changed, and the text about customize: is no longer there.

It sure is. See @francisp’s example. You can attribute any entity with anything you want, no matter where it comes from.

EDIT: Apologies, I didn’t realise I posted the wrong link.

I see this:

That is on

Gotcha. Copy and paste error on my end. That was the link I intended to post.

@parautenbach and @francisp thankyou so much for this tip - after defining the customization as you noted, the entity was immediately available as a statistic in the developer page and also the statistics card, etc.

Your tip was a gem - this config override feature is not obvious to newcomers!

1 Like

Indeed, it’s not obvious. What I learned myself only last year was that you can actually define any custom attributes (not just the known HA ones, like state class, friendly name, etc.). I mark e.g. some entities with monitor: true for custom battery monitoring with my own templates and automations. It’s a powerful mechanism.