No long term statistics for entity with state_class: measurement

Hello,

I have several sensors integrated by modbus in configuration.yaml. Here is one example:

sensors:
    - name: "Lueftung_Istwert_Zuluft"
      unique_id: "Lueftung_Istwert_Zuluft"
      input_type: input
      scale: 1
      offset: 0
      unit_of_measurement: m^3/h
      address: 4032
      slave: 20
      scan_interval: 15
      device_class: volume_flow_rate
      state_class: measurement

The data of the sensor is only stored for 10 days, long term statistics are not saved.

When setting up this sensor in the first place I did not define the state_class. I understood this might be the rootcause for not having LTS, therefore I added state_class: measurement later. But it did not solve the problem.

What else could be the rootcause for not having LTS saved?
Might there be a problem with defining the state_class after setting up the sensor?

Many thanks in advance!

Read this,

You could try to delete sensor and restart then create it again, “correct”
You can not just add a unit_of_measurement If it’s not a statistical sensor

The unit must match the device class. See: https://www.home-assistant.io/integrations/sensor#device-class

Change your unit to m³/h.

Restart HA.

Then go to Settings → Developer Tools → Statistics. If there is a Fix Issue button to the right of your entity then press it and fix the issue.

Thank you, I updated the unit and restarted, but did not get any fix-issue button in the statistics area. I will check tomorrow if data remains longer than 10 days.

Here is an additional example for a sensor without LTS:

  • name: “Lueftung_Temperatur_Zuluft”
    unique_id: “Lueftung_Temperatur_Zuluft”
    input_type: input
    scale: 0.1
    offset: 0
    unit_of_measurement: °C
    address: 4036
    slave: 20
    scan_interval: 15
    device_class: temperature
    precision: 1
    state_class: measurement

In this case the unit is correctly specified in my understanding, but there is no LTS either. So the unit might not be the (only) root cause.

Nope. You will have to check in 10 days. The current data will have the incorrect unit.