Detect when notification not received by smartphone?

TLDR: Is it possible to get an acknowledgement in Home Assistant that the Home Assistant Companion App received a notification and if not to resend it?

I love the Home Assistant Companion app and use it for countless things. Often it involves automations that send notifications to my smartphone.

While most of the time this works fine, occasionally the notifications are not received by my smartphone.
This is most noticeable with this automation I created which sends notifications to my smartphone and then sometimes sends messages later on to clear those notifications.
Sometimes the clearing notifications are not received and thus remain on my phone.
To figure out where the problem is I have added logging for all the important steps of the automation and therefore Iā€™m certain that it did actually send the clear_notification. If I manually force it to send the clear_notification again with the same tag it does get removed from my smartphone.

Now my question is how I can get some kind of confirmation in Home Assistant that my smartphone has received the message? So something similar to the checkmarks in whatsapp/signal etc that show the message was received.
I would in that case want to resend the message. Ideally the Companion app would support some kind of parameter where it can read whether it is a ā€˜retryā€™ and thus ignore the double if in the end it does receive the original message.

Did you look in the docs?

2 Likes

Not well enough it seems, thank you and my apologies!

This is the information I have available about the message Iā€™m sending:

{
   "_msgid":"3ec8afd93eeb4b24",
   "topic":"",
   "outputtext":{
      "domain":"notify",
      "service":"mobile_app_mobile_quizzical",
      "data":{
         "title":"Persoon bij voordeur",
         "message":" ",
         "data":{
            "ttl":0,
            "importance":"high",
            "priority":"high",
            "vibrationPattern":"100, 1000, 100, 1000, 100",
            "image":"/api/camera_proxy/camera.reolink_video_doorbell_poe_sub",
            "timeout":"",
            "persistent":"",
            "tag":"testtest",
            "sticky":"",
            "confirmation":"true",
            "clickAction":"app://com.mcu.reolink",
            "actions":[
               {
                  "action":"",
                  "title":""
               },
               {
                  "action":"",
                  "title":""
               },
               {
                  "action":"",
                  "title":""
               }
            ]
         }
      }
   }
}

And this is the confirmation event that the Home Assistant Companion App sends back:

{
   "payload":{
      "event_type":"mobile_app_notification_received",
      "event":{
         "tag":"testtest",
         "image":"/api/camera_proxy/camera.reolink_video_doorbell_poe_sub",
         "title":"Persoon bij voordeur",
         "webhook_id":"16cf9a0f54fdf5264b29bd87fb053b898a365e7a29a08230580403a70c74044e",
         "clickAction":"app://com.mcu.reolink",
         "vibrationPattern":"100, 1000, 100, 1000, 100",
         "confirmation":"true",
         "importance":"high",
         "device_id":"7d52bce08e67953a"
      },
      "origin":"REMOTE",
      "time_fired":"2023-02-11T22:22:34.787085+00:00",
      "context":{
         "id":"01GS195BS2XYJA78Y2NPGXD8BV",
         "parent_id":null,
         "user_id":"a3056b7b373946478f6ab9dca598f953"
      }
   },
   "topic":"mobile_app_notification_received",
   "event_type":"mobile_app_notification_received",
   "_msgid":"3f47e1a7ab7b9d10"
}

I donā€™t see any identifier that links the sent message to the confirmation event. Am I missing something?
This would be essential to be able to determine whether the sent message was received or not (and if not resend the notification). The best I can think of is to add some unique identifier myself, but it is not obvious where to add it:

  • if I add it to the title of message then the identified will appear in the notification on, my phone.
  • I can add it to the ā€˜tagā€™ but then itā€™s more complex to manage sticky notifications etc.
    Once Iā€™ve made a choice where to add it, in combination with the user_id I can resend the message to the correct user.

Many thanks

Isnā€™t the title enough as it is?
In the automation that sends the notification the title is hardcoded I guess?
Then you go to a wait for trigger and use the same hardcoded title.

Only if the automation is triggered several times before the messages arrive is there an issue, right?

the app sends back the entire notification data that it received, you should have something there that you can link back like tag or any other field.

As I believed the problem was with my phone not always receiving the messages I created a whole set of automations to monitor the sent messages and resend them if they are not received but turns out this effort was a but of a waste of time:


The reason is that I see now from the logs that I am creating that the clear_notification messages sent to my mobile phones are being received by the smartphones, but for some reason it doesnā€™t end up actually clearing the notification from my phone. Here are two examples cases where ā€œjohn mobile_appā€ received a clearing notification but did not actually clear the notification:

16:41:23 person detected
16:41:23 20230221164123 notify Person detected front door
16:41:30 front door opened
16:41:30 20230221164123 clear_notification send
16:41:31 20230221164123 clear_notification sent to mobile_app_mobile_john
16:41:32 20230221164123 clear_notification sent to mobile_app_mobile_jane
16:41:32 20230221164123 jane mobile_app_notification_received
16:41:34 20230221164123 john mobile_app_notification_received
16:41:34 []
17:57:53 person detected
17:57:53 20230221175753 notify Person detected front door
17:57:57 front door opened
17:57:57 20230221175753 clear_notification send
17:57:59 20230221175753 clear_notification sent to mobile_app_mobile_john
17:57:59 20230221175753 john mobile_app_notification_received
17:57:59 20230221175753 clear_notification sent to mobile_app_mobile_jane
17:57:59 20230221175753 jane mobile_app_notification_received

If I manually send those clear notifications again (so with tag_id ā€˜20230221164123ā€™ and ā€˜20230221175753ā€™) the notifications do get cleared.
So why did they not get cleared the first time it received the command to do so?
Any clue?

where are these logs from HA? Try checking the logs from the app itself. There is no guarantee as to what order FCM messages arrive in on the device.

Those are my own created logs that Iā€™ve embedded in my automations in order to try and figure out whatā€™s going on.
Thanks for the tip on checking the logs from the HA Companion App itself. Unfortunately it only stores about 3 minutes of logs and so far I have always been too late in spotting that a notification was not cleared, so that the relevant logs were already goneā€¦
I can however see the last 25 received notifications and there I can see the notification was received:

And then a few seconds later the command to clear the notification:

And clearly the clearing doesnā€™t succeed because the notification is still on my phoneā€¦
But if I then later on retry to send the clearing notification it does work:


To my eyes it looks exactly the same as the previous clearing notification.

I guess Iā€™ll have to try and keep an eye on it and hope to see it within the first 3 minutes. Most of the time it does workā€¦

I use a timeout parameter in my notifiy command to accomplish same thing.

Thanks @cyn, the thing is that Iā€™d like to see notifications if people passed by the house. So I only remove notifications that are no longer relevant (e.g. because I opened the door).

I managed to catch it in the logs in the Home Assistant Companion app and I have the impression it supports your theory:

02-23 15:32:59.110 20192 19059 W FirebaseMessaging: Unable to log event: analytics library is missing
02-23 15:32:59.112 20192 19059 D FCMService: From: 331041709873
02-23 15:32:59.128 20192 20192 D MessagingService: Creating notification with following data: {tag=20230223153257, image=/api/camera_proxy/camera.reolink_video_doorbell_poe_sub, title=Persoon bij voordeur, webhook_id=REDACTED, channel=silent, clickAction=app://com.mcu.reolink, importance=high}
02-23 15:32:59.143 20192 20192 D UrlRepository: localUrl is: true, usesInternalSsid is: true, usesWifi is: true
02-23 15:32:59.144 20192 20192 D UrlRepository: Using internal URL
02-23 15:32:59.152 20192 20253 D UrlRepository: localUrl is: true, usesInternalSsid is: true, usesWifi is: true
02-23 15:32:59.152 20192 20253 D UrlRepository: Using internal URL
02-23 15:32:59.160 20192 19060 D TrafficStats: tagSocket(207) with statsTag=0xffffffff, statsUid=-1
02-23 15:32:59.196 20192 20253 D TrafficStats: tagSocket(213) with statsTag=0xffffffff, statsUid=-1
02-23 15:33:03.136 20192 19067 W FirebaseMessaging: Unable to log event: analytics library is missing
02-23 15:33:03.136 20192 19067 D FCMService: From: 331041709873
02-23 15:33:03.145 20192 19067 D MessagingService: Processing device command
02-23 15:33:03.165 20192 19067 W FirebaseMessaging: Unable to log event: analytics library is missing
02-23 15:33:03.166 20192 19067 D FCMService: From: 331041709873
02-23 15:33:03.171 20192 19067 D MessagingService: Clearing notification with tag: 20230223153257
02-23 15:33:03.171 20192 19067 D NotifManagerCompat: Cancel notification with tag "20230223153257" and id "-306168537"
02-23 15:33:03.172 20192 19067 D NotifManagerCompat: Check if the notification is in a group...
02-23 15:33:03.172 20192 19067 D NotifManagerCompat: Notification is not in a group. Cancel notification...
02-23 15:33:03.174 20192 20192 D UrlRepository: localUrl is: true, usesInternalSsid is: true, usesWifi is: true
02-23 15:33:03.179 20192 18957 D TrafficStats: tagSocket(98) with statsTag=0xffffffff, statsUid=-1
02-23 15:33:03.234 20192 20192 D MessagingService: Show notification with tag "20230223153257" and id "-306168537"

The logs are a bit Chinese to me, but my reading of it is that it starts creating the notification, then receives the clearing notification, and then shows the notification on the screen. So the clearing notification comes a bit too early.

So except if you plan to add some check before the ā€˜show notification stepā€™ that the notification should have been cleared already, I guess my best approach is to add some check to make sure a clearing notification is sent at least 10 seconds after the original notification?