Hi and thanks for sharing the solution. I’ve used it to create a command_line switch so it can be used by the backup-Automation:
- platform: command_line
switches:
purge_backups:
friendly_name: Purge HA-config Backups
unique_id: switch.purge_backups
icon_template: mdi:trash-can
# go to backup direcotory, list files by date, filter result list to hide the first 7 results (show from nr.8) and remove remaining
command_on: cd /config/backups/ && ls -A1t | tail -n +8 | xargs rm -v
The switch will stay turned on if you use it in lovelace, but that isn’t my scope. I just use it in the automation to trigger it and then turn it of again:
alias: Backup, daily HA-config backup
description: ""
trigger:
- platform: time
at: "00:10:00"
condition: []
action:
- service: backup.create
data: {}
- service: switch.turn_on
data: {}
target:
entity_id: switch.purge_backups
- service: switch.turn_off
data: {}
target:
entity_id: switch.purge_backups
mode: single
maybe there is a solution that will also turn off the switch automatically after the command has been executed, but i’m happy with this solution