Enabling long term statistics

I previously had a very long data retention time and this resulted in a huge database (100GB+)

Since then I have reduced that down as I should be making use of long term statistics. I had some SQL sensors that lost data due to the wrong sensor state class. These things happen, I have the data stored elsewhere so it’s not the end of the world.

I’ve since changed all these to have a state class of “Measurement” - assuming this would result in the long term stats to start being recorded - but that’s not the case.

All the data still cuts off before the recorder retention limit.

Is there a way to enable/turn on long term stats where they’ve previously not been recorded?

Are you sire LTS are not recorded? You’d have to wait a while before you have recorded enough for it to be obvious. You should be able to see it in the statistics tab in developer tools.

As well as a valid state class it needs a unit_of_measurement.

And the statistics are not retroactively calculated. Only from the time the sensor received these attributes.

Unit of measurement is not a requirement, still records fine without it.

Weird. That’s how HA knows to treat the value as a number (for graphs). How the heck does it know to treat it as a number for statistics if it does not have a unit?

Anything with a state_class is assumed to be numeric.

I think the “unit_of_measurement means numeric” logic came from back before we had statistics/state_class. Now numeric is defined as having a unit_of_measurement or a state_class, or a numeric unitless device_class (e.g. AQI or PH)

2 Likes

I think this is the issue.
I’ve got recorder purge set at 60 days and likely changed the settings less than 60 days ago (can’t remember specifically).
Will have to keep checking to see if they appear.

Currently the data is cutting off at 60 days.
The chart appearance has changed to show smoothed out averages which it didn’t prior to the change so state class is clearly working.