How to use Google Calendars' event notification as a trigger and then reference the event in your Actions like you would if you directly referenced it?

I tried a few things, and the closest thing I could get using that sensor is:

alias: Mobile - Calendar Notifications
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.YOURDEVICE_active_notification_count
    not_to:
      - unknown
      - unavailable
    not_from:
      - unknown
      - unavailable
condition:
  - condition: template
    value_template: "{{ trigger.to_state.state|int > trigger.from_state.state|int }}"
  - condition: template
    value_template: |
      {{ trigger.to_state.attributes|select('match','android.title_com.google.android.calendar_')|list|count > 0}}
action:
  - repeat:
      for_each: |
        {%- set ns = namespace(messages=[]) %} 
        {% for y in trigger.to_state.attributes |
        select('match','android.title_com.google.android.calendar_') %}
          {% set ns.messages = ns.messages + [(trigger.to_state.attributes).get(y)] %}
        {% endfor %}
        {{ ns.messages }}
      sequence:
        - service: notify.NOTIFIER
          metadata: {}
          data:
            message: "{{ repeat.item }}"   
mode: queued

FWIW, I found this method to be pretty unreliable in terms of timing. If you don’t have fast updates turned on, it seems almost random. However, I don’t use Google Calendar notifications the way you have described in previous post, so I may have been doing something incorrectly.

I also found that if you have two event notifications at the same time there doesn’t seem to be an easy way to get a notification for each one received… which is why I ended up splitting them and running them through a repeat in the automation above.

Thanks a lot for your effort.

Any idea why I get the error Automation is unavailable Actions: invalid template (TemplateSyntaxError: unexpected '}') for dictionary value @ data[0]['repeat']['for_each'] at the top of the automation’s page? I just copy-pasted your code with the name of my sensor in the trigger.

There was a typo at the end of the set statement… it should end with the %} delimiter not }}.
I have fixed it in the post above.

1 Like

I have fast updates enabled and get the notifications instantaneously, so far, but I’ve gotten 4 notifications for the same calendar event, minutes apart. This occured after 1 day of usage.

Look at the automation Traces and see if there’s anything you can use to discriminate between a desired notification and an undesired notification. Keep in mind that there may not be anything that will work, you may have reached the limits of what is possible while relying on the notifications.