Condition: Get age of File

Hi! Im a core user and want to crate Backups every night at 3am, but only if

automations.yaml
configuration.yaml
etc. has changed in the last 6 hours / change date < 6 h

I could make a shell script, which can check the last edit and fire a backup through the api
or
create shell sensor which can check the last edit and a automation to trigger a backup

is it possible to do that more elegant with a condition? how can I make a condition to get last edit time/date of a file?

Your suggestions are what I would do to but… I seem to read that you donot want unnecessary backups. I use Duplicati which does incremental ones…just another idea :slight_smile:

another solution would be rsync, which is already running. but it is nice to have small packages to fall back on. more control over system states that were error free :stuck_out_tongue:

ok. create a shell command inside your config

shell_command:
  backup_ha: 'find /home/homeassistant/.homeassistant -maxdepth 1 -name "*.yaml" -mmin -1439 >/dev/null && curl -s -kX POST -H "Authorization: Bearer YOURTOKEN" -H "Content-Type: application/json" http://10.30.50.2:8123/api/services/backup/create'

and a suitable automation:

alias: _Cron Backup
description: ""
trigger:
  - platform: time
    at: "03:30:00"
action:
  - service: shell_command.backup_ha
    data: {}
mode: single

done

I have decided to monitor only the yaml files, because adding new devices will inevitably lead to changes of e.g. automations.

btw: -mmin 1440 = changes within the last 24h00m