Long-term statistics: What is the retention policy and how can it be changed?

I’d like to understand the new long-term statistics better:

  • How long into the past will the statistics be available?
  • Is it possible to change the retention policy?

Default is 10 days.
Have a look at the documentation of the recorder : Recorder - Home Assistant

I don’t think that applies to long term statistics, or the energy panel would not be able to display monthly or yearly stats. Though I don’t know the answer to the question.


And all questions I’ve seen on this forum about this have been (AFAIK) strangely unanswered.
I’m surprised it’s not (again AFAIK) documented anywhere.

1 Like

I hope for an answer. Thats an important information, what is missing

I was having the same questions and found useful information here: Long- and short-term statistics | Home Assistant Data Science Portal

The website data.home-assistant.io was mentioned in the release party for 2021.8


Long-term statistics are different than the other objects in the database, which are stored exactly as they happened and are automatically purged after a period (default is 10 days). Statistics are never purged. Because they are summarized every hour, they only create 24 entries per day.

Which is the developer documentation. It is not yet featured in the documentation on the general website I guess.


I wonder if it is possible somehow to exclude sensors from this stats database. OK, 24 records a day for every sensor isn’t much, but still, why record data like for example link quality of Zigbee sensors?


Did you try the exclude option of the recorder integration? I am not sure if it will apply too on the long term statistics.

I’m gonna respawn this old thread since I had the same question and the documentation I’ve found wasn’t clear. I’ve found some answers and since google bring lot of people here I’ll share what I’ve found.

First of all: recorder save all the data from any sensor and any change is recorded. Recorder will purge old data after some days (default to 10) and you can include or exclude some sensor from recording to help reduce the size, that can become huge. Recorder data can be seen in history graphs and this are NOT statistics.

Only sensors that complies with long-term statistic are also packed by a totally different module. These data are NOT viewable from the history graphs, but from statistics graphs. When recoreder purges data, statistics are not affected. Statistics are like diamonds, they’re forever.
After all, only sensors configured to comply with statistics are tracked, and sensor tracked will just add a few bytes every day (24 hourly measures with max, min, mean value). Hence nothing to be worried about in decades.


So, where are precisely stored these permanently statistics?
Which entries of the database? Which folders, eventually, also could contain their data?

The Statistics idea is great and it is definitely solve 98% of data retention-based problems.

However there are 2% left for situations where statistics approach with min-max-mean is not sufficient. For example, a car integration may record all tracks with average fuel consumption. It is not data-greedy because such sensor us updated only few times a day, but it may be important to hold all values for further analyse.
Similarly, it may be a door sensor which also provides only few events per day, but for security reasons this information may be valuable for a few months, not just last 10 days.

So actual request for different retention policies which may be applied for different entities/domains still exists.


I must say, the documentation around this is pretty rubbish… I’ve posted new threads, looked at old threads and just keep going around in circles.

I don’t see Recorder in the settings search, and given that HA is supposed to be moving most things into UI this would seem like a first point of call. At the very least the overall retention policy should be settable within the UI, but even better granular control at the entity level…
I do not, and really should not need to, start looking at external solutions like MariaDB or Grafana or whatever just to track entity data longer than 10 days

Recorder isn’t even in my configuration.yaml - at the very least shouldn’t this be pre-populated at setup?

My question…
I have a self created Input Number (input_number.daughters_achievement_points) helper which gets updated at maximum once per day, typically once per week. I want to set the policy to keep this data indefinitely…

How on earth do I do this?


I’m also looking for this. I want to track temperature sensors for longer than 10 days, energy consumption definitely for years. How can I do that?

Looking to do the same. From the documentation it sounds like we need to create a statistic sensor for each sensor we wish to be tracked but unless I’m mistaken there isn’t an easy to follow example of how/where to do that.

Sensor Entity | Home Assistant Developer Docs (home-assistant.io)

For long term statistics to be generated for a sensor (which as explained above, will be kept forever) all it needs is a valid device_class a state_class of measurement and a unit_of_measurement.

If the integrations you are using to add these sensors do not support these options/attributes they can be added using customize.

Thanks for the reply. I have a few Switchbot Meters.

state_class: measurement
unit_of_measurement: °C
device_class: temperature

I would like to track the min max values for each day.

Great. LTS are being saved for your sensors.

All you have to do is add a statistics graph card to your dashboard to track the min amd max of each sensor. You can set a time to show as long as you want.

1 Like

Thank you.
I see I can also use a Statistic card to show a single value for a time period.
Is it possible to access such stats similar to how you can access secondary attributes of an entity?

I was thinking I could use something like the Multiple Entity Row card (HACS) to display the min, mean and max for various meters for various periods, in a grid style layout.
Today: Bedroom Min: 10 Mean: 15 Max: 20 Kitchen Min: 9 Mean: 14 Max: 19
Yesterday: Bedroom Min…
This Week: …

Unfortunately no.

LTS are not directly accessible except via the statistics graph.

For that you would have to create statistics sensors. Or SQL sensors that access the LTS data in the database, which depending on your skill set may be much more difficult.

Thank you.
I will have a play with card_mod, etc.
Or spend some time learning how to author my own card. :crossed_fingers: