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.
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.
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.
Look at the automation Traces and see if there’s anything you can use to discriminate between a desired notification and an undesired notification
I wasn’t able to discriminate between those things, but I noticed that whenever the recurring Tasker “Running Tasks” notification appears the automation fires unintendedly.
Any idea how to prevent that?
In the Active Notification Count State Attributes it’s listed as eg.: android.title_net.dinglisch.android.taskerm_2087247171: Running Tasks
By the way, I noticed another issue when using this automation: I sometimes get random double/triple notifications for events that have their notification set to one day prior.
For example, I got a notification for the 6 AM event 24h prior, as expected and then, out of the blue: another one at 00:02 AM and another one at 01:53 AM.
No idea how to troubleshoot this. Here are the Changed Variables of the triggers for the unexpected notifications though, in case that helps:
Are you clearing notifications in a timely manner? If the notifications aren’t cleared they will still be available to be sent again when you get a new notification of any kind. That is one of the reasons I said that I found the method unreliable… you can try filtering out attributes that were part of the previous state object:
Filtered Attributes Example
alias: Mobile - Calendar Notifications
description: ""
trigger:
- platform: state
entity_id:
- sensor.YOUR_DEVICE_active_notification_count
from: null
variables:
new_attr_list: >
{% set from_attr = trigger.from_state.attributes %} {% set from_keys =
from_attr.keys() | list %} {% set ns = namespace( attr=[]) %} {%- for
k,v in (trigger.to_state.attributes).items() if k not in from_keys and
k is match('android.*.google.android.calendar_') %}
{% set ns.attr = ns.attr + [(k,v)] %}
{%- endfor %}{{ (ns.attr) }}
new_attr: "{{ dict.from_keys(new_attr_list) if new_attr_list != [] else none }}"
condition:
- alias: Reject if new state is less than old
condition: template
value_template: "{{ trigger.to_state.state|int > trigger.from_state.state|int }}"
- alias: Allow only if New is from Calendar
condition: template
value_template: "{{ false if new_attr is none else new_attr.keys()|count > 0 }}"
action:
- repeat:
for_each: >
{%- set ns = namespace(messages=[]) %} {%- for y in new_attr |
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.pushover
metadata: {}
data:
message: "{{ repeat.item }}"
- delay: 1
mode: queued
But there are still a number of ways that this method could produce false-positive notifications or fail to send true notifications. Surely there is a less convoluted, less error prone, or more controllable method than going from Google Calendar push notifications > your phone > Home Assistant > Pushover.
Google Calendar can send email notifications just as easily as it can send push notifications. Pushover seems to have a method to accept email messages and distribute them. Or if you really want HA to be part of it… have you tried using email notifications and an IMAP sensor like I asked about 9 months ago?