hass-auto-backup icon indicating copy to clipboard operation
hass-auto-backup copied to clipboard

[FR]: Allow Jinja template for keep_days

Open jf-64 opened this issue 9 months ago • 3 comments

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

jf-64 avatar May 10 '24 11:05 jf-64

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?

jcwillox avatar May 27 '24 04:05 jcwillox

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?

jf-64 avatar May 27 '24 06:05 jf-64

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 }}'

jcwillox avatar May 27 '24 14:05 jcwillox