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: ""
  - platform: state
      - sensor.YOURDEVICE_active_notification_count
      - unknown
      - unavailable
      - unknown
      - unavailable
  - condition: template
    value_template: "{{ trigger.to_state.state|int > trigger.from_state.state|int }}"
  - condition: template
    value_template: |
      {{ trigger.to_state.attributes|select('match','')|list|count > 0}}
  - repeat:
      for_each: |
        {%- set ns = namespace(messages=[]) %} 
        {% for y in trigger.to_state.attributes |
        select('match','') %}
          {% set ns.messages = ns.messages + [(trigger.to_state.attributes).get(y)] %}
        {% endfor %}
        {{ ns.messages }}
        - service: notify.NOTIFIER
          metadata: {}
            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.