Trigger on time input with offset

I have several automations with triggers or conditions as times clustering around my getting up time in the morning. I wanted to make them more flexible and found a solution in an earlier thread here. Only I can’t get it to work. In the following example the first trigger is my current one using a fixed time. The third works as intended and the second is the solution I found. I can’t get that to work. (Yes, I entered a time twenty minutes after I wanted the trigger to fire.) Any ideas why?

trigger:
  - platform: time
    at: "06:40:00"
  - platform: template
    value_template: >
      {{ now() >= today_at('input_datetime.aufstehen') - timedelta(minutes = 20)
      }}
  - platform: time
    at: input_datetime.aufstehen

It’s a shame the direct entry of time offsets is only defined for sun and not other time states.
Danke

Copy that into Developer Tools —> Template and you get a hint why this can’t work.

Thank you for pointing me to that tool. It’s great help and makes things much easier. I had tried out several things without it beforehand, though, all to no avail. And, as I said, that template was taken from a former solution here

Unfortunately even with the template tester I can’t find it. I get
“ValueError: could not convert str to datetime: ‘input_datetime.aufstehen’”
without quotes:
“‘input_datetime’ is undefined”
without the first part to the dot:
‘"aufstehen’ is undefined"
Sorry, can’t do it on my own.
Danke

reveil is my wake up time , it’s an input_datetime.
that’s the trigger that’s start heating 15 minutes before that wakeup

{{now()|as_timestamp|timestamp_custom('%H:%M:00') == (state_attr('input_datetime.reveil','timestamp')-(15*60)-3600)| timestamp_custom('%H:%M:00')}}

Sorry, all my mistake. The original solution, before I started tinkering with it, works

{{ now() >= today_at(states('input_datetime.aufstehen')) - timedelta(minutes = 20) }}

I believe I also found what it was. After the minute changes on my computer it takes a bit until the trigger kicks in. Either the Raspberry’s time is a bit off or more probably there is a slight delay. Seens I didn’t wait but went right back into the automation.
Thanks for your patience and help again.

1 Like

Thank you too for that alternative formulation. I’ll stick with the simpler one for the time being.


today_at('input_datetime.aufstehen')

You might as well write today_at('AxelBerger')

The string can’t be evaluated because it doesn’t contain a datetime object.

</smartass mode>

Why don’t you define a template helper which calculates eg 10 minutes before input_datetime.reveal as datetime? Then trigger on the time of that helper and you have a solution that is not evaluated every minute.

Just define a template helper

{{ as_timestamp (as_datetime(states(“input_datetime.reveal”))-timedelta(minutes=10))| timestamp_custom(‘%H:%M:%S’) }}

and take that as trigger time. Should work better, shouldn’t it?

Developer tools show only dependency on input_datetime.reveal for recalculation.

This would not be re-usable in the sense if I should want action A 10 mins before set time and action B 3 hours prior to set time. Having a helper for every action would also be impractical.