State_class: measurement not working for temperature on specific device

Hi there I have a small question about temperature chart
I have few sensor but statistic collected only for 2 of then I check mqtt configuration and all looks fine

// my own device based on esp32 and have a temperature and humidity sensor 
// for this sensor statistic not collected 
unique_id: magic_light_deI9eURO_p3
state_topic: magic_light/deI9eURO/water_temp/value
value_template: '{{ value }}'
unit_of_measurement: °C
device_class: temperature
state_class: measurement
name: Boiler
platform: mqtt

// for this sensor statistic collected and showed on card
unique_id: magic_light_deI9eURO_p2
state_topic: magic_light/deI9eURO/room_hum/value
value_template: '{{ value }}'
unit_of_measurement: '%'
device_class: humidity
state_class: measurement
name: Boilerroom
platform: mqtt

// another sensor from different device and statistic collected as well
unique_id: ebusd_bai_StorageTemp_temp
value_template: '{{value_json["temp"].value}}'
state_topic: ebusd/bai/StorageTemp
unit_of_measurement: °C
state_class: measurement
device_class: temperature
name: StorageTemp temp
platform: mqtt

thanks for any advice

even more I check discovery data and it’s look identical

"discovery_data": {
            "topic": "homeassistant/sensor/ebusd_bai_StorageTemp_temp/config",
            "payload": {
              "unique_id": "ebusd_bai_StorageTemp_temp",
              "value_template": "{{value_json[\"temp\"].value}}",
              "state_topic": "ebusd/bai/StorageTemp",
              "unit_of_measurement": "\u00b0C",
              "state_class": "measurement",
              "device_class": "temperature",
              "name": "StorageTemp temp",
              "platform": "mqtt"
            }
          }
          
"discovery_data": {
            "topic": "homeassistant/sensor/magic_light_deI9eURO_s3/config",
            "payload": {
              "unique_id": "magic_light_deI9eURO_p3",
              "state_topic": "magic_light/deI9eURO/water_temp/value",
              "value_template": "{{ value }}",
              "unit_of_measurement": "\u00b0C",
              "device_class": "temperature",
              "state_class": "measurement",
              "name": "Boiler",
              "platform": "mqtt"
            }
          }

Are you using YAML or MQTT Discovery to configure your MQTT Sensors?

The reason why I ask is because the YAML format shown in your first post was deprecated several versions ago. The new YAML format is shown in the documentation.

The main difference is that MQTT Sensors are now defined under the mqtt: key and not the sensor: key. Each sensor configuration no longer refers to platform: mqtt.

Example

mqtt:
  sensor:
    - name: Boiler
      state_topic: magic_light/deI9eURO/water_temp/value
      unit_of_measurement: '°C'
      device_class: temperature
      state_class: measurement
      unique_id: magic_light_deI9eURO_p3

    - name: Boilerroom
      unique_id: magic_light_deI9eURO_p2
      state_topic: magic_light/deI9eURO/room_hum/value
      unit_of_measurement: '%'
      device_class: humidity
      state_class: measurement

    - name: StorageTemp temp
      state_topic: ebusd/bai/StorageTemp
      value_template: "{{ value_json.temp.value }}"
      unit_of_measurement: '°C'
      state_class: measurement
      device_class: temperature
      unique_id: ebusd_bai_StorageTemp_temp

yep I am using mqtt discovery
and I just copy/paste json from ebusd topic
maybe it should not be retained ?

Are there any errors in the Log related to the sensor?

Is the sensor listed in Developer Tools → Statistics? Is there a note next to it reporting a problem?

oh thanks
it’s show that previous unit of measurement was ‘’ and new is ‘°C’
so I choose “convert” and looks like it work now
but data not showed yet but maybe need some time

A sensor entity needs these options, with proper values, to be included in order for its data to be recorded in long-term statistics:

  • unit_of_measurement
  • device_class
  • state_class

If the value of unit_of_measurement was an empty string then that will definitely prevent the sensor’s data from being recorded in long-term statistics.

1 Like

yes you are right
but problem was that HA not recognize that unit_of_measurement was changed to new value and do not fix is but himself
but all work now
“Developer tools - statistic” really great hit!
thank you

1 Like