Persistent Connection And Notifications

The way I understand it is that the Always Persistent Connection setting is supposed to bypass google’s notification service and send the notifications directly/locally to the app.
But my phone is somehow able to receive notifications even when my phone is not connected to the server.

  • I have Persistent Connections set to Always
  • Nabu casa is logged out (I don’t use it)
  • The internal and external addresses for my HA server in the app are both set to my local 192.168.1.XXX address
  • my phone’s Wifi is off.
  • VPN on my phone to my server is disconnected.
  • So phone is on LTE only with no connection to my server.

I send a test notification using the developer tools services (Notifications: Send a notification via mobile_app_phone) and the notification comes through still.

Am i missing something? Is the notification still going through the google cloud? This was not the behavior on my previous phone. I recently got a new phone (pixel 8) and configured the app the same as the old phone (pixel 4a). I can’t imagine this is the cause, but thats the only thing thats changed (other than a few HA updates).

Looking at the notification history in the app, all the test notifcations say FCM (Firebase Cloud Messaging??) regardless if the notifications came in while the phone was using Wifi, or while using the scenario i described above.

I’m on version 2023.10.5 on the server and 2023.10.4-full for the app version.

Unless you use the minimal version of the app firebase will be used as the fall back.

Thanks for the quick reply.
Wouldn’t the fallback to firebase contradict the ‘always’ setting/definition then?
My interpretation of always means to never use firebase.
Is this a recent change? Becasuse i’m 100% sure it did not function this way (e.g. last month or so)

Let me explain why i say so:
I have an automation that sends a notification (android auto notification also) when I leave my house zone. I used this notification as verification that my phone has successfully connected to my VPN (automatically in the background via Tasker).

If i don’t get the notification i know my phone didn’t connect to VPN (sometimes Tasker fails when in the background). And this would happen with regular frequency where I wouldn’t get the notification after driving away from my house. And I would have to unlock the phone and reconnect to the VPN manually.
But now the notification comes through 100% of the time even when my phone is not connected.

Testing this on my new and old phone seems to shows different behaviour.

  • both old and new phone connected to Wifi
  • both have persistent setting set to always
  • send notifications (developer tools > services) to both phones separately
    • old phone is on version 2023.10.2-full
      • notifications listed as coming via Web Socket
    • new phone is on version 2023.10.4-full
      • notification listed as coming via FCM

So there seems to be some difference between the app versions.

No because your installation has a fallback. If you don’t want the fallback then you’ll want to install the minimal version.

No this was there since the feature was first introduced.

Have you tried checking the companion app logs to see if there is an error?

I’m not sure if there are any errors logged. I only see one ‘w’ (warning?) in the logs. This is the log i see when i send a notification on my new phone where it uses Firebase. I deleted some of the webhook values and GPS positions just in case.

10-30 10:26:34.052 17591 18450 D LogcatReader: Done reading logcat for pid 17591
10-30 10:26:50.304 17591 25945 W FirebaseMessaging: Unable to log event: analytics library is missing
10-30 10:26:50.305 17591 25945 D FCMService: From: 331041709873
10-30 10:26:50.310 17591 17591 D MessagingService: Creating notification with following data: {title=Pixel 8, webhook_id=xxx-deleted, message=Pixe 8, server_id=1}
10-30 10:26:50.316 17591 17591 D MessagingService: Show notification with tag "null" and id "-2131038910"
10-30 10:26:50.387 17591 18450 D ServerConnectionInfo: localUrl is: true, usesInternalSsid is: true, usesWifi is: true
10-30 10:26:50.397 17591 18450 D ServerConnectionInfo: localUrl is: true, usesInternalSsid is: true, usesWifi is: true
10-30 10:26:50.407 17591 18450 D ServerConnectionInfo: localUrl is: true, usesInternalSsid is: true, usesWifi is: true
10-30 10:26:50.418 17591 18450 D ServerConnectionInfo: localUrl is: true, usesInternalSsid is: true, usesWifi is: true
10-30 10:26:50.419 17591 18450 D WebSocketRepository: Sending message 1492: {type=ping, id=1492}
10-30 10:26:50.420 17591 18450 D WebSocketRepository: Message number 1492 sent
10-30 10:26:50.431 17591 18134 D WebSocketRepository: Websocket: onMessage (text)
10-30 10:26:50.432 17591 18450 D WebSocketRepository: Message number 1492 received
10-30 10:26:55.933 17591 17591 I ImeTracker: io.homeassistant.companion.android:cf3665c1: onRequestHide at ORIGIN_CLIENT_HIDE_SOFT_INPUT reason HIDE_SOFT_INPUT
10-30 10:26:58.233 17591 18154 D LogcatReader: Read logcat for pid 17591

And this is the log I see on my old phone that sends it over a websocket connection.

10-30 10:32:10.539  7901  8229 D LogcatReader: Read logcat for pid 7901
10-30 10:32:10.563  7901  8229 D LogcatReader: Done reading logcat for pid 7901
10-30 10:32:17.897  7901  8124 D ServerConnectionInfo: localUrl is: true, usesInternalSsid is: true, usesWifi is: true
10-30 10:32:17.912  7901  8124 D ServerConnectionInfo: localUrl is: true, usesInternalSsid is: true, usesWifi is: true
10-30 10:32:17.924  7901  8124 D ServerConnectionInfo: localUrl is: true, usesInternalSsid is: true, usesWifi is: true
10-30 10:32:17.936  7901  8124 D ServerConnectionInfo: localUrl is: true, usesInternalSsid is: true, usesWifi is: true
10-30 10:32:17.938  7901  8124 D WebSocketRepository: Sending message 297: {type=ping, id=297}
10-30 10:32:17.939  7901  8124 D WebSocketRepository: Message number 297 sent
10-30 10:32:17.962  7901  8133 D WebSocketRepository: Websocket: onMessage (text)
10-30 10:32:17.965  7901  8124 D WebSocketRepository: Message number 297 received
10-30 10:32:26.667  7901  8133 D WebSocketRepository: Websocket: onMessage (text)
10-30 10:32:26.670  7901  8124 D WebSocketRepository: Message number 143 received
10-30 10:32:26.674  7901  8227 D WebSocketRepository: Sending message 298: {type=mobile_app/push_notification_confirm, webhook_id=xxx-deleted, confirm_id=64524a831a22e94552b4cff802a14da1, id=298}
10-30 10:32:26.676  7901  8227 D WebSocketRepository: Message number 298 sent
10-30 10:32:26.684  7901  8133 D WebSocketRepository: Websocket: onMessage (text)
10-30 10:32:26.686  7901  8227 D WebSocketRepository: Message number 298 received
10-30 10:32:26.694  7901  7901 D MessagingService: Creating notification with following data: {message=Pixel 4a, title=Pixel 4A, webhook_id=xxx-deleted, server_id=1}
10-30 10:32:26.701  7901  7901 D MessagingService: Show notification with tag "null" and id "-2130702529"
10-30 10:32:27.725  7901  7901 D LocBroadcastReceiver: Received location update.
10-30 10:32:27.728  7901  7901 D ForegrndServiceLauncher: Check if service HighAccuracyLocationService is running. Service running = false
10-30 10:32:27.729  7901  8229 D LocBroadcastReceiver: Last Location: 
10-30 10:32:27.729  7901  8229 D LocBroadcastReceiver: Coords:(40.xxxxx, -82.xxxxx)
10-30 10:32:27.729  7901  8229 D LocBroadcastReceiver: Accuracy: 100.0
10-30 10:32:27.729  7901  8229 D LocBroadcastReceiver: Bearing: 0.0
10-30 10:32:27.732  7901  8229 D LocBroadcastReceiver: Begin evaluating if location update should be skipped
10-30 10:32:27.732  7901  8229 D LocBroadcastReceiver: Received location that is 38 milliseconds old, 1698676347694 compared to 1698676347732 with source fused
10-30 10:32:27.732  7901  8229 D LocBroadcastReceiver: Duplicate location received, not sending to HA
10-30 10:32:31.299  7901  8227 D LogcatReader: Read logcat for pid 7901

In the old phone logs there is this bit which is not in the new phone logs.
type=mobile_app/push_notification_confirm, webhook_id=xxx-deleted

can you try checking errors from HA core at the same time please? HA core is actually the one that will push to firebase based on the app being connected or not.

Edit: an error like this: https://github.com/home-assistant/core/blob/7b6910882e39cf5e0afeb91d04c66b58b0d7a235/homeassistant/components/mobile_app/notify.py#L142

I don’t see anything in the Core logs (detailed version). Doing a CTRL+F search of “not connected” or “firebase” comes up with 0 hits.

yea I just realized that error will show up if you have the minimal version of the app, full version has always defaulted to firebase so that behavior is not new you are just now noticing. There is nothing in the beta versions that would cause this behavior change.

try enabling debug logging for the mobile app integration and look at the debug entries to see if anything jumps out. I also wouldnt filter the logs the way you are, you should look at all mobile app log entries when investigating issues from HA core.

In this case HA core is responsible for sending the notification where it needs to go.

try enabling debug logging for the mobile app integration and look at the debug entries to see if anything jumps out. I also wouldnt filter the logs the way you are, you should look at all mobile app log entries when investigating issues from HA core.

I will do this and look into it, thanks.

full version has always defaulted to firebase so that behavior is not new you are just now noticing. There is nothing in the beta versions that would cause this behavior change.

Something must have changed either on my setup or on HA side. Just need to track down what it was. I can say this confidently because for about a year I used the lack of notification as a confirmation that my VPN didn’t auto-connect to my server. And this happened quite frequently. Therefore I had to manually connect the VPN. Once that happend, the notifications would come through the phone.

And the fact that two phones show different results (Firebase vs web socket) when sending the same test notifications to them is some indication that something is different between the 2023.10.2 and 2023.10.4 versions.

Trying to debug this made me think of another, maybe more fundemental question. When I get the notification on my phone via firebase that is triggered by my phone leaving the home zone, how is my phone’s location data getting back to the server if my phone has no connectivity to my server?

Thanks again for all of the help.

if thats the only case you get the notification then its quite possible the app was just trying to reconnect while the phone was switching networks and when you sent the notification it just wasnt connected. Might be a case you never encountered until recently and a coincidence upon the update.

Your server sends the notification either through websocket or firebase depending upon what is connected. If sent to firebase then your device does not need to be connected to the server to get the notification it comes from firebase servers. Your phone still wont be able to send location data if it has no connectivity to the server.

Have you already tried rebooting both device and HA and HA host to rule out a cached issue?

Also are you certain you were using the full version before and not the minimal version that has no fallback?

So I wanted to hopefully conclude this thread and give some of my findings so far, even though some might be theoretical and/or inconclusive.

Something was definitely wrong with my setup because every notification was coming via firebase regardless if my phone was connected to my wifi, through VPN or not connected to my network at all. I was not using nabu casa either.

So I deleted the beta version and went back to the normal version of the app… I’m not sure if this was/is the culprit or if the phone/app had gotten into a weird state which was causing the issue, but I’m not seeing the issue now with the non-beta version. Now the notifications are coming through appropriate channel (mainly websocket).

Regarding the issue of my phone seemingly sending data to my server without an active connection, I think there was a ‘race condition’ of sorts happening; what you hinted to above.

As I drove away from the house, the new phone kept connection with the wifi just a bit longer than the previous phone. Long enough to just hit the threshold of the home zone. So as I exited the zone, the wifi would disconnect and I would get the notification on my phone through firebase (since VPN sometimes doesn’t connect automatically). So this would make it seem like the data was reaching my server without a connection. I suspect my older phone disconnected from WiFi sooner, so I never encountered that scenario.

So you are correct that notifications fallback to firebase, but I still think that the persistent setting of “always” should imply that it will never use firebase and therefore it shouldn’t fallback to it.

Yes certain. I didn’t even know there was a minimal version until you mentioned it. I’ve only ever used the app from the offical google play store.

Thanks for the info and help.