ESPHome & MQTT: No Long term statistics

Hello together,
i have many ESPHome Devices in Home Assistant for Temp and Humi measurement.
These devices are available in the long-term statistics.

Some devices are located at a distance and send the data via MQTT.
These devices are not available in the long-term statistics.

I tried this in the ESPHome YAML, but it does not work.

sensor:
  - platform: ina226
    address: 0x40
    shunt_resistance: 0.002 ohm
    current:
      icon: mdi:flash-auto
      name: "${sensorname1} Strom"
      filters:
        - lambda: |-
            float MIN_VALUE = 0;
            float MAX_VALUE = 30.0;
            if (MIN_VALUE <= x && x <= MAX_VALUE) return x;
            else return {0};
    power:
      icon: mdi:solar-panel-large
      name: "${sensorname1} Leistung"
       device_class: "energy"
      state_class: "measurement"
    bus_voltage:
      icon: mdi:flash
      name: "${sensorname1} Bus Spannung"
       device_class: "voltage"
      state_class: "measurement"
    shunt_voltage:
      icon: mdi:flash
      name: "${sensorname1} Shunt Spannung"
       device_class: "voltage"
       state_class: "measurement"
    max_current: 20.0A
    update_interval: 10s

Under Developer Tools the attribute state_class is not shown:

image

I made this change for all temperature and humidity sensors that send their data via MQTT:

  customize_glob:
     sensor.temperatur_*:
       last_reset: '1970-01-01T00:00:00+00:00'
       device_class: temperature
       state_class: measurement
     sensor.luftfeuchtigkeit_*:
       last_reset: '1970-01-01T00:00:00+00:00'
       device_class: humidity
       state_class: measurement

It is now possible to display the devices in the long-term statistics. But is that the right way?

1 Like

Good question. I hope we get an answer

1 Like

It’s easier than relying on customize for each sensor, so: yes,

ezgif.com-gif-maker

I did see a way to add this to mqtt discovery by publishing a retained topic but that would depend on your sensors being discovered and not defined in yaml.

Thanks for the information. I am of the opinion that this should be transmitted via MQTT in the same way as with the native API.

@OttoWinter Is this issue with the MQTT component being looked in to?

This should’ve been resolved in ESPHome 2021.8.

1 Like

Please don’t demand people answer you. See point 16 here.

I’m sorry. It wasn’t meant as a demand. Different communities, different rules I suppose.

1 Like