jcwillox / hass-auto-backup

🗃️ Improved Backup Service for Home Assistant that can Automatically Remove Backups and Supports Generational Backup Schemes.
https://jcwillox.github.io/hass-auto-backup
MIT License
338 stars 23 forks source link

[FR]: Allow Jinja template for keep_days #132

Open jf-64 opened 3 months ago

jf-64 commented 3 months ago

Is your feature request related to a problem? Please describe.

Currently the value of keep_days has to be given explicitly by numbers. Using template calculation results currently in "[object Object]": null, thus if you want to have a backup with dynamic* value for keep_days, you have to create a new automation for for different keep_day values:

*: e.g.: set it every Monday to 21, but every 1st Monday of the month to 28, but every 1st Monday of the quarter to 84, otherwise to 14

Of course it can be done also by separated automations, but why not KISS?

Describe the solution you'd like

Accept Jinja template for keep_days, see above.

Describe alternatives you've considered

No response

Additional context

No response

jcwillox commented 3 months ago

Home Assistant services should already let you template the keep days field, or do you want AB to evaluate a template when it's checking if a backup should be deleted?

jf-64 commented 3 months ago

2 weeks ago (at the time I wrote this message) it wasn't possible to template it. Do you meant it was changed since then?

jcwillox commented 3 months ago

I thought you could always do it, like in this example

script:
  msg_who_is_home:
    sequence:
      - service: notify.notify
        data:
          message: >
            {% if is_state('device_tracker.paulus', 'home') %}
              Ha, Paulus is home!
            {% else %}
              Paulus is at {{ states('device_tracker.paulus') }}.
            {% endif %}

I also found an example in my config, where I have a variable keep_days that I generate dynamically, and then use in the service call.

      - service: auto_backup.backup
        data:
          name: '{{ name }}'
          password: '{{ password }}'
          keep_days: '{{ keep_days }}'