Hi all,
Every now and then, I find that a notification to be sent to my phone (iOS) fails to send (out of phone range, phone is off at night, etc). I’d like to be able to send an email in the case of a failed delivery as a fall-back option.
At present, I can capture the moment when a notification fails, and send an email using the following code chunk:
# NOTIFY APP/EMAIL WHEN A SERVICE ERROR OCCURS IN THE HOMEASSISTANT LOGS (to alert of a failure that I may not want to have missed!)
# requires the following in configuration.yaml:
# system_log:
# fire_event: true
- alias: "Create notifications for errors"
initial_state: 'on'
mode: single
max_exceeded: silent
trigger:
platform: event
event_type: system_log_event
condition:
condition: template
value_template: '{{ "Error sending notification" in trigger.event.data.message[0] }}'
action:
# HA notification center
- service: persistent_notification.create
data_template:
title: A Service has errored and generated a log message
message: "{{ trigger.event.data.message[0] }}"
# email notification
- service: notify.notify_email
data_template:
title: "Alert: A Service has errored and generated a log message"
message: "{{ trigger.event.data.message[0] }}"
However, this doesn’t inform me as to WHAT the original notification actually was! (title and content). Is it possible to capture this information and send as an email, in a similar fashion to above?
Thanks in advance!
Note, the current implementation as above generates a message like this:
Error sending notification to https://mobile-apps.home-assistant.io/api/sendPushNotification: ContentTypeError(RequestInfo(url=URL('https://mobile-apps.home-assistant.io/api/sendPushNotification'), method='POST', headers=<CIMultiDictProxy('Host': 'mobile-apps.home-assistant.io', 'User-Agent': 'HomeAssistant/2021.9.7 aiohttp/3.7.4.post0 Python/3.8', 'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Content-Length': '363', 'Content-Type': 'application/json')>, real_url=URL('https://mobile-apps.home-assistant.io/api/sendPushNotification'))... etc, etc, etc