#What is the correct way to get “time until calendar event” in a template?
1 messages · Page 1 of 1 (latest)
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() }}
Thank you. Where is this documented?
Will this specifically get the start time of the event that triggered the template to run?
Ah, this is from an automation.
Perhaps more info about what you're actually trying to do would help folks help you
I want to speak a reminder aloud 30 minutes before each entry in my calendar.
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 🙂
There might be another event that starts in 15 minutes
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)) }}
Thank you