Selective Recorder Purging

Hi all,

I’m looking to confirm some information around purging of data.

I’ve got an external MySQL database that’s held data for my Home Assistant for a couple of years now and it’s been working great, no slowdowns, etc. However, just for the fact that I really don’t NEED a lot of the historical data in there, only a very select few, I was thinking it’d be nice to at least improve the performance even further (dunno if I need it now, but I’m sure I will need to later) by selective purging.

My thoughts are, I want to purge all data older than 30 days EXCEPT specific entities. Before I do this, I thought I’d post here and confirm… Let’s say my entity names are sensor.example1, sensor.example2, and sensor.third_ex_blah, and I want to KEEP long-term historical data on these… But I’m okay deleting data older than 30 days for all other entitites. Is this how my configuration.yaml would have to look?

recorder:
  purge_keep_days: 30
  commit_interval: 300
  db_url: mysql://[filtered]
  exclude:
    entity_globs:
      - sensor.example*
    entities:
      - sensor.third_ex_blah

Any confirmation would be greatly appreciated!

There is no provision for “per-entity” purge settings.

What you have above will exclude the recording of any state data for the specified entities.

ohhh, dang okay didn’t expect that…

I noticed two recorders may be possible. Would this mean the only way to really do what I’m looking for is to create a database for long-term data and one for short-term data? And then I guess if I wanted to ‘keep’ the data I have now, I’d have to do some manual purging of data for the entities I don’t care for. Or I guess optionally, I could do my own scripts that clean up the database but that seems a little riskier.

There are a number of ways to approach this but keep in mind that LTS (long term statistics) are never purged and setting the default recorder to retain for more than a month or so may lead to performance issues.

  1. Use InfluxDB for long term state data (years), graphed with Grafana. This is the way most people go.

  2. Use an automation and the recorder.purge_entities service to periodically prune only the entities you want to from the database. The rest are purged automatically at 30 days.

Personally If it is only 30 days I would not bother.

1 Like