After the latest updates to Home Assistant, the ability to add labels to entities was introduced. It turned out to be a quite convenient way to manage database cleanup using automation. Labels allow for easy browsing, filtering, and grouping of entities in different views. By leveraging them in automation, you can conveniently adjust its scope without directly editing the automation.
alias: Purge frigate data from db
description: ""
trigger:
- platform: time
at: "03:00:00"
condition: []
action:
- service: recorder.purge_entities
target:
entity_id: |
{{ label_entities('one_week_purge') }}
data:
keep_days: 7
mode: single
The provided example runs daily at 3:00 AM and triggers the recorder.purge_entities
service.
Entities are substituted using the {{ label_entities('one_week_purge') }}
template,
which retrieves all entities tagged with the one_week_purge
label.
Of course, you can copy the -service ...
section and add further calls with different labels
and keep_days
.