#What is the correct way to get “time until calendar event” in a template?

1 messages · Page 1 of 1 (latest)

brisk siren
#

I tried time.delta but it seems to return the time since the last time the event fired.

fast jetty
#

I don't know where time.delta came from, but something like this will tell you how long until the next scheduled event:
{{ state_attr('calendar.test', 'start_time')|as_datetime|as_local - now() }}

brisk siren
brisk siren
fast jetty
#

It's just a template that looks at the calendar entity

#

There's no triggering

brisk siren
#

Ah, this is from an automation.

fast jetty
#

Perhaps more info about what you're actually trying to do would help folks help you

brisk siren
#

I want to speak a reminder aloud 30 minutes before each entry in my calendar.

fast jetty
#

if you trigger on a state change to the calendar entity, then yes, it would trigger whenever the next event updates and you could get the time until that event from what I provided

#

ok, then maybe start with that 🙂

brisk siren
#

There might be another event that starts in 15 minutes

fast jetty
#

the most straightforward way to interact with the calendar is based on whatever the next event is

#

which is what I provided above

#

This, as a template trigger, should trigger whenever the next event is 30 mins from now:

{% set start_time = state_attr('calendar.test', 'start_time') %}
{{ start_time is not none and (start_time|as_datetime|as_local - now() < timedelta(minutes=30)) }}
brisk siren
#

Thank you