The tester does not work with Template conditions… especially in this case since there is no trigger event to populate the trigger variable used by this template.
You will have to go to the Developer Tools > States tool and check the attributes of the last notification sensor immediately after a calendar notification is received.
@Didgeridrew your code seems to run without any issue for some weeks.
I was wondering if there’s a way to extend the functionality even further to make it act like an actual calendar notification, meaning that when it’s tapped it opens the event from that notification in the calendar app
I don’t use Pushover, so you’ll need to do a bit of experimenting…
For the HA companion app and Android devices, I would add a click action with an Android intent, but Pushover only seems to allow opening a url. The intent url may work if all your target devices are Android. Try the following:
hm upon changing the action to the version you presented the Pushover notifications for this Automation don’t fire anymore at all
And I’m pretty sure I added the code correctly this time
Considering one of my devices has iOS I tried just adding the URL in this simpified action:
action:
- service: notify.pushover
data:
message: |-
test
url: 'https://calendar.google.com/calendar/u/0?cid=YXJzNGw0bjEyM0BnbWFpbC5jb20'
but even that threw an error:
“Error running action
Error rendering data template: Result is not a Dictionary”
I also tried the variant that was in the Pushover documentation:
action:
- service: notify.pushover
data:
message: test
data:
url: https://calendar.google.com/calendar/u/0?cid=YXJzNGw0bjEyM0BnbWFpbC5jb20
which on iOS upon tapping the notification only causes the pushbullet app to open with the link there for me to tap again to open google calendar. I was hoping for the page to pop up from just tapping the notification though, just like how the actual calendar app would behave. Additionally, it opens the Google Calendar Website thereby clogging my tabs, not the Google Calendar App.
I didn’t find comprehensive documentation, nor actual package names, just some vague userposts so I also tried google calendar://calendar.google.com/calendar/u/0?cid=YXJzNGw0bjEyM0BnbWFpbC5jb20 and google_calendar://calendar.google.com/calendar/u/0?cid=YXJzNGw0bjEyM0BnbWFpbC5jb20 for the last line with no success
iOS stuff is outside my wheelhouse… have you looked into setting up a Siri Shortcut to launch the Calendar. You can fire Shortcuts via HA service call with additional data, so that might be an avenue to explore.
@Didgeridrew
I’ve been noticing a issue recently which I can’t exactly pinpoint because it doesn’t occur consistently
I think it’s probably something in my Galaxy S6s’ tasker configuration (because upon disabling all Profiles the issue disappeared) but everything is set up correctly so it must be a bug
The issue is that sometimes the Pushover notification just gets immediately canceled
Do you have any suggestions or know a way to set this calendar up which is less prone to bugs?
Update: I just quit using the Galaxy S6 and used a Pixel 3 + Galaxy S7 and iPhone 12 mini instead and the issue went away.
I noticed a new issue with @Didgeridrew 's automation: When I set two Calendar notifications at the same time only one of them triggers the automation. So, the other one isn’t mirrored.
It’s not even in Home Assistant’s History page.
that didn’t do anything and I would’ve been surprised if it did since it’s not the automation not firing but actually the value not being reported by the HA Companion App.
He suggests to use the Active Notification Count sensor as a workaround as that contains the notification title as an attribute.
So, I tried redoing the automation with that sensor, but I got stuck because for this sensor the attributes are different in that each notification has an individual number on the left side of the colon
and I don’t know how to make templates for that. Would you help me out with that?
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?