I’m trying to trigger an automation with a calendar event.
Simple enough eh? But I want it to trigger 30 minutes before the event. Do I need to add the !!-30 and the hashtag to the title on my calendar in order for that to trigger early?
Example. Normally my work calendar says “Work” no it will have to say “#Work !!-30” I suppose if I have to do that I will but man is it ugly haha
I’m actually trying the exact same thing right now, but can’t get it working. As far as I understand the calendar will only swich to on when the event starts. However, it has this offset attribute that will switch to true, depending on the “!!-30” additions in the event title.
I could nog get an automation working using the offset attribute as a trigger. So I’m going to try a template sensor for the attribute.
Would love to hear from someone who can explain exactly how to configure the offset attribute as a automation trigger.
I haven’t worked with the built-in offset settings (!!), but I wanted to have an event that alerts me 15 min before an event ends (so that I’m reminded in time to pick up my son from school). I didn’t have any luck getting this to work as a template trigger, so I created a sensor (with the same template rules), then created an automation that watches the state of that sensor. I ended up creating several sensors that all worked about the same way (various weekly kid school-things), so I set up a sensor for each, then one automation to remind me.
The various Google calendar entities are searches on one calendar.
sensor(s) - repeated for each calendar entity. 900sec = 15min. Note that I have a sensor.date__time that keeps the current time. I use that in the sensor so that it updates the value whenever the time changes (every minute).
nate_tech_shop_end:
friendly_name: Tech Shop ends in 15 minutes
entity_id: sensor.date__time
value_template: >
{% if states.calendar.nathan_tech_shop %}
{% if is_state("calendar.nathan_tech_shop", "on") and as_timestamp(states.calendar.nathan_tech_shop.attributes.end_time) - as_timestamp(now()) < 900 %}on{% else %}off{% endif %}
{% else %}off{% endif %}
automation (I used meaningful names in the sensors so that I could just reuse them as part of the notification):
- alias: Time to pick up a kid notification
trigger:
- platform: state
entity_id:
- sensor.nate_tech_shop_end
- sensor.nora_mathcounts_end
- sensor.nora_chess_club_end
state: 'on'
action:
- service: shell_command.speak
data_template:
text: >
{%- for state in states.sensor -%}
{% if state.entity_id == trigger.entity_id -%}
{{ state.attributes.friendly_name | urlencode }}
{%- endif %}
{%- endfor -%}
- service: notify.scott_notifier
data_template:
title: "Time to go!"
message: >
{%- for state in states.sensor -%}
{% if state.entity_id == trigger.entity_id -%}
{{ state.attributes.friendly_name }}
{%- endif %}
{%- endfor -%}
I did find out how to use the offset_reached attribute without a separate template sensor. The key is the attribute state you are looking for is true. No quotes around it. Here is my automation: