Clear history depending on elapsed time

I’d like to clear the history of some of my sensors depending on how much time has passed.

For example:

  • from the past two weeks keep all recorded sensor values,
  • from 2 weeks ago till 6 months ago, keep 1 sensor value per day
  • from 6 months ago or longer, keep 1 sensor value per week

This could help keep my database clean and HomeAssistant responding quickly while allowing a general overview of sensor values in the past (i.e. helpfull for smart meters for energy and gas consumption).

How could I achieve something like this? The History and/or Recorder components don’t allow for such configuration. Any help is appreciated!

Still looking for a solution on this. Does anyone have any pointers or tips to help me out? Thanks!

You could set up mariaDB then use any SQL tool to run scripts to clean up the data. I am not sure if you can do it directly from HA. I believe there are also add-ons to export data to things like Google docs spreadsheets.

Setting up an entire mariaDB instance just for this task sounds a bit cumbersome. Do you know if there are methods to clean up the data directly in HA’s own database?

@joostthehost You opened this threat a long time ago but only the MariaDB option was offered. Did you, or anyone else for that matter have any other ideas how to do this or is this indeed the proper way to go?

I wish I could say I have, but unfortunately I don’t. I’m still interested in a solution without external scripting/tooling.