Data Retention

Just a quick question: How long does HA save data for (without implementing a database solution)?

Cheers.

1 Like

10 days for history data by default but this is user selectable.
Infinite for long term statistics.

1 Like

Awesome thanks.

Is it a 0 for infinite?

Do not set it to any more than 30 days.

I need/want longer :pensive:.
I’ve seen some posts on implementing a separate database, I’ll try that.
Cheers. :+1:

1 Like

Actually, what would you recommend please?

For long term storage of stats - have a look at the InfluxDB add-on and integration.

1 Like

Yep. That’s the go for long term data. Here’s a tutorial (includes Grafana):

1 Like

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 - most of the threads I find have few if any people answering, so I’m now scattergunning in threads that do have answers…

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 (it says required in the docs but it’s clearly not…?)
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 would also like to keep longer data more broadly (30days) - I do not see any ui selection for this? Why do you say not to set it more than 30 days

9 Likes

I agree. Now that I upgraded my RPi with a large SSD, I’m not so worried about storage running out or too many writes to an SD card. I’ve already spent time figuring out mini-graph and history explorer, and like to have everything in my Dashboard cards - a single interface.

All I really want is the simplest way to keep data for at least a couple of years and be able to portray it nicely so I can compare January now with a year ago, maybe get some interesting aggregates like Max and Min etc. If it is really necessary to install another database engine and charting software to do this, I would like to better understand why that is the case - and why isn’t that already part of HA.

2 Likes

It is part of Default Config. You have that instead.

There is no way to do this. There is one retention setting for everything.

Hmm… okay.
So, to edit Recorder for everything do I need to remove default config or can I just add

recorder:
    purge_keep_days: 366

to my config and it will overwrite?

I’ve picked 366 as I’d like to keep a year ideally for everything - you say don’t set it longer than 30 tho… why?

Is there no way to use an exclude on the purge?

Something like (psudo):

recorder:
    purge_keep_days: 366
       exclude:
          entities:
                - inputboolean.mysensor

No there isn’t. Just follow the recorder documentation. There are no hidden features.

Yes. Though I would not recommend retaining that much. Your database will likely start to become very sluggish.

On my setup I have a SSD with a Raspi4. I want to keep 30 days of history. So if I understood correctly, I just add in the configuration.yaml the following.

recorder:
  purge_keep_days: 30

Or do I have to add this under the default_config: like this:

default_config:
  
  recorder:
    purge_keep_days: 30

The first one.

1 Like

Not really. It does in fact work with the builtin db, it’s just really badly documented. Basically HA uses two different history engines, both built in: the ‘normal’ history and the long term statistics. Combining both, you’re able to achieve what you need without using additional external DBs.

The history is more precise and will use more memory and bandwidth. The DB engine itself (sqlite) is actually pretty good and can handle larger databases rather well. The problem is that the recorder implementation in HA is very inefficient. So keep the purge_keep_days at a reasonable number. 30 days seems reasonable, if your DB is stored on a reliable high bandwidth storage medium (not an SD card !). Some people have reported using it up to 90 days without issues. YMMV.

Next, the long term statistics. They go back indefinitely, but they only work for certain type of entities: entities with measurement or total_increasing state class. They’re less precise than history, but enough to do long term comparison on mean, min/max, etc. They’re more optimized too. Unfortunately they’re really badly documented. Here’s some info about them, but it’s pretty technical.

8 Likes

Thank you.
One question more: For the statistics card I see data for more than 30 days, even if I did not change the purge_keep_days.
For example I can see the daily mean for a battery of a sensor for 170 days. But the sensor-data for the sensor is just visible for 10 days. (see pictures below).

How long are the values for the statistic saved, and where do I change it?

They’re kept forever. You cannot change it. It’s independent of purge_keep_days. It’s an entirely separate history.

2 Likes

Ah, thats good to know! Thank you for that info.
For my temperature statistics the daily min, max and mean is enough for me. I don’t need more.
The hourly seems to be saved also forever. But the 5-min-values not. Correct?

Yes, correct.

1 Like