Automation needs to trigger 30min before input_datetime

Hi,
I created a time-only input-datetime helper.

I want to create an automation that is triggered 30 minutes before the time specified in the input-datetime helper.

This is what I have:

alias: Sauna inschakelen 30min voor gewenste tijd
description: ""
triggers:
  - value_template: >-
      {{ now().strftime('%H:%M') == (states('input_datetime.sauna_klaar') |
      as_datetime - timedelta(minutes=30)).strftime('%H:%M') }}
    trigger: template

I must have done something wrong, since it doesn’t trigger.

What have I done wrong?

You didn’t try the template, or the separate bits of it, in the Template Editor. You can’t run the as_datetime on a time-only state (docs).

Try:

triggers:
  - trigger: template
    value_template: "{{ (today_at(states('input_datetime.sauna_klaar')) - now()).total_seconds() < 1800 }}"

That was indeed my mistake. I should have checked with the template editor.

Your solution works, thanks a lot!

1 Like