MQTT sensor does not allow state_class

I am trying to add the “state_class” property to an existing MQTT sensor but got the message “Property state_class is not allowed”.
However from the documentation an several examples this should be possible. Does anyone know what I am doing wrong?

The original sensor configuration looks as follows:

- platform: mqtt
  name: Soladin Total_Power
  unit_of_measurement: "kWh"
  state_topic: "sensors/pv/soladin/stats/Total_Power"
  value_template: "{{ value|int / 100 }}"
  device_class: "energy"

When I add the “state_class” property as follows :

- platform: mqtt
  name: Soladin Total_Power
  unit_of_measurement: "kWh"
  state_topic: "sensors/pv/soladin/stats/Total_Power"
  value_template: "{{ value|int / 100 }}"
  device_class: "energy"
  state_class: 'measurement'

The message : “Property state_class is not allowed” is shown.
Anyone an idea?

Are you using an older version of Home Assistant? Because it works for me using 2021.9.7.

Screenshot from 2021-09-25 11-13-16

it works for me, and you should use

    state_class: total_increasing

Hi,

Thanks for your reply,

I am also running Home Assistant 2021.9.7 in a virtual machine (HASSOS) on my Synology.

Perhaps it has something to do with the fact that I started to use Home Assistant several years ago in a Synology Package, then merged to run in a docker and finally moved to HASSOS in a Virtual Machine.

As soon as I type “state_class” this error pops up.

Regards, Will

What do you mean by “as soon as I type”? Are you using Visual Studio Code with the Home Assistant Config Helper and that message appears in VS Code when you enter state_class?

Because if that’s what you mean then that message has nothing to do with Home Assistant. That’s reported by the Config Helper (and it’s out of date).

Thanks Taras!

That was indeed the case. I just ignored the error message and the state was added to the entity:

Regard, Will

1 Like

Glad to hear it resolved the mystery of the error message’s source.

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.