So, I’m guessing you’re using the Google Calendar Event component. Yes?
If so, I’m not familiar with it, nor ever used it, but from what I read in the docs, wouldn’t it be better to use an offset string in the title to get a pre-trigger? Something like !!-540 to get a pre-trigger 540 minutes (or 9 hours) before the start time? If it works the way I think it does, then you could use this for your trigger:
As an alternative approach, I think you can use the offset: parameter to create a trigger before the actual event - although you need to change the event title.
I have only used it with the caldav component, so I don’t know if it works with the google calendar component.
I cannot enter an offset as its a calendar not made by me, only imported, with my daily work schedule
To get the offset, without the ‘offset’ title thingie
- condition: template
value_template:'{% set diff = as_timestamp(states.calendar.treinbestuurder_be.attributes.start_time) -as_timestamp(now()) %}# create a timestamp of the calendar time attr and substract current time
{{ diff<32400 and diff > 18000 }}' # compare difference in seconds, will match condition when true
Other solution is creating a sensor to use as trigger like Robdyi did in his post:
Hey @Wim_L
Can you help me with this? Im trying to create an automation that will trigger when an event is 3o minutes away. I also cant edit my work calendar.
How would I go about using this as a trigger, rather then a condition? Or am I misunderstanding something
Not sure if this helps but I use this sensor to tell me the time to the next event. I use it to get alexa to announce when we should be leaving the house.
- platform: template
sensors:
timetoleavealexamin:
friendly_name: Time to go Alexa min
entity_id: sensor.time
value_template: >-
{% if states.calendar.calendar.attributes.start_time %}
{{((as_timestamp(states.calendar.xxxxxgmailcom.attributes.start_time) - as_timestamp(now())) / 60) | default(99) | int }}
{%- else -%}
0
{%- endif %}
Wondering if I screwed something up. I assume the state is the minutes until the next event? It doesnt seem to be updating and just showing 4 even though the event is in 1 minute.
- platform: template
sensors:
upcoming_event:
friendly_name: Time Until Next Event
entity_id: sensor.time
value_template: >-
{% if states.calendar.work.attributes.start_time %}
{{((as_timestamp(states.calendar.work.attributes.start_time) - as_timestamp(now())) / 60) | default(99) | int }}
{%- else -%}
0
{%- endif %}
Hello, I am trying to do a automated heating for the office. It schuld trigger 2h before the Google Calendar event starts. It would be very helpful to see a full automation (trigger, condition, action). I would highly appreciate if @halpplz or @RobDYI could help me out here and share the complete working code. Furthermore I am not sure how to create the sensor timetoleavealexamin / upcoming_event. Thanks in advance and have a nice day!
sensor:
- platform: time_date
display_options:
- 'time'
- platform: template
sensors:
timetoleavealexamin:
friendly_name: Time to go Alexa min
entity_id: sensor.time
value_template: >-
{% if states.calendar.calendar.attributes.start_time %}
{{((as_timestamp(states.calendar.work.attributes.start_time) - as_timestamp(now())) / 60) | default(99) | int }}
{%- else -%}
0
{%- endif %}
automation event_in_120min:
alias: Event in 120 minutes for Google Calendar
trigger:
platform: state
entity_id: sensor.timetoleavealexamin
to: '120'
action:
Thank you so much. Now I have it also working!
And I also find it very genius using the tts to announce events - Thanks for the inspiration as well as the help @RobDYI
I was having a little trouble understanding this for a while, but I get it now…This is for anyone else who is a little dense with this stuff.
The template sensor that RobDYI suggests creates a sensor that gives the number of minutes until the next calendar event in the calendar feed you provide. Then you create an automation (through lovelace, yaml, or node red) and specify how many minutes before the event you want to trigger your automation.
This works perfect.
I just removed the “entity_id: sensor.time” line completely, since it’s deprecated in HA now and not needed anymore.
Mine takes about 15 minuttes or so from then I add a new event in the calendar/change an event to the sensor “timetoleavealexamin” updates, is this normal?