Help me wrap my head around Google Calendar

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.

Here’s my code:

calendar:

- cal_id: [email protected]
  entities:
  - device_id: nathan_tech_shop
    name: Nathan Tech Shop
    search: Nate to tech shop
    track: true
  - device_id: nora_mathcounts
    name: Nora MathCounts
    search: Nora MathCounts
    track: true
  - device_id: nora_chessclub
    name: Nora Chess Club
    search: Nora chess club
    track: true

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 -%}
4 Likes

The template sensor worked.

Sensor:

- platform: template
  sensors:
    work_alarm:
      value_template: '{{ states.calendar.work.attributes.offset_reached }}'
      friendly_name: 'Work Alarm'

Automation:

- alias: Work
  hide_entity: False
  trigger:
    platform: state
    entity_id: sensor.work_alarm
    to: 'True'
  action:
    service: notify.pushbullet
    data:
      message: Test bericht
      title: Gcal

No hashtag needed it seems. I did use the !!-30 in the event title.

@Jer78 has allready done a lot of work on this topic, read this:
https://community.home-assistant.io/t/text-to-speech-notification-to-leave-for-appointment/8689

1 Like

Wow, thanks for thoroughly laying this out - explains a lot to me that I didn’t quite get. Congrats on having such smart kids too. :wink:

Wow there’s a lot to learn in this link as well! Thanks a lot. Never knew you could do Street Views with the generic camera.

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:

- alias: Test Event Notification
    trigger:
      - platform: template
        value_template: "{{ is_state_attr('calendar.home_assistant', 'offset_reached', true) }}"
    condition:
      - condition: template
        value_template: "{{ states.calendar.home_assistant.attributes.message == 'Test Event' }}"
    action:
      - service: persistent_notification.create
        data:
          title: "Test Event"
          message: "Test Event Notification Triggered"
      - service: notify.html5
        data:
          message: "Test Event Notification Triggered"

apparantly !! wont work over 99minutes

I have something wrong somewhere
is it my time_date sensor entity

#calender offset
  - platform: time_date
    display_options:
      - 'date_time'
    
#more calendar offset time in seconds
  - platform: template
    sensors:
      my_event_offset:
        friendly_name: "My Event 120 sec offset"
        entity_id: sensor.date_time
        value_template: >
          {% if states.calendar.my_calendar %}
          {% if is_state("calendar.my_calendar", "on") and as_timestamp(states.calendar.my_calendar.attributes.end_time) - as_timestamp(now()) < 120  %}on{% else %}off{% endif %}
          {% else %}off{% endif %}