Recorder purge and repack

In my configuration.yaml file I have added:

recorder:
   purge_interval: 1
   purge_keep_days: 7
   repack: true

When I now restart HA, I get an error stating that the configuration for is wrong:


Removing the repack: true line and the config is okay.

What would be the right syntax to automatically repack the database?

Remove the options for purging from your config and create an automation for it.

  - alias: Purge Database
    initial_state: True
    trigger:
      platform: time
      at: '02:22:22'
    action:
      service: recorder.purge
      data:
        keep_days: 7
        repack: true

EDIT: You have to set purge_interval: 0 to disable HA’s default daily purge.

2 Likes

Thanks for that. Changed my setup…
Will report in a week, if the automation works :stuck_out_tongue_winking_eye:

If you set the logging for recorder to debug,

logger:
  default: warn
  logs:
    homeassistant.components.recorder: debug

you will see what the purge does.

2019-04-10 16:22:22 DEBUG (Recorder) [homeassistant.components.recorder.purge] Purging events before 2019-04-02 14:22:22.370017+00:00
2019-04-10 16:22:24 DEBUG (Recorder) [homeassistant.components.recorder.purge] Deleted 5147 states
2019-04-10 16:22:30 DEBUG (Recorder) [homeassistant.components.recorder.purge] Deleted 5520 events
5 Likes

Thank you!
You helped me a lot

*old but useful!

Hi, in /config/automations.yaml I I entered your code

 - alias: Purge Database
    initial_state: True
    trigger:
      platform: time
      at: '02:22:22'
    action:
      service: recorder.purge
      data:
        keep_days: 7
        repack: true

but when I save the file, this error comes out:

bad indentation of a mapping entry at line 2, column 18:
        initial_state: True
                     ^

That line and all below it need bringing back one space. The first letter of the keys should be lined up with each other, so the i of initial would be under the a of alias.

Now it work @anon43302295, thanks.

@VDRainer Does this automation reduce the size of the db file in Kb?
Would it be possible to have on the lovelace an indicator of the last repack, the size of the db file and a button to perform the repack manually? Thanks

1 Like

The repack option should do this.

Take a look at the filesize sensor

Create a script with the action from the automation and execute it from an entities-card or with a button

1 Like