New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML5 push notifications - not received while phone is unused #22249
Comments
Same issue here. OnePlus 6 (Android 9) with turned off all possible battery optimisation services. HA 0.89/0.90, Linux, venv, Python 3.7.2. |
@andriej I'm not gonna be able to help out with this as I only use Chrome for HTML5 Push Notifications. |
yes , happens to me also occasionally, also oneplus 6T user here |
I think sometimes it may not be that your phone dozes but that googles servers are delayed. If it does have to do with doze I would be curious to see if the FCM push notification works while HTML5 does not. Personally I have seen myself and others at the same time see the same delays so it leads to me think it was a server issue, I had to stop using HTML5 as a result of that. The notifications would be delayed by like 5 minutes or more and that was not suitable for an alarm. |
Doze means the phone will only wake up periodically to download batches of notifications. However if the developers set the urgency of the message then it will normally be delivered immediately to the device causing the device to wake up. As seen here - https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message a webpush would have the priority defined in the header of the push, and I don't see anything setting the priority in the notify/html5.py code. |
Seems like lack of priority may be the issue! |
@andriej Can you submit a PR to update docs to note that? |
Isn't it lack of priority declaration in the code that @asjmcguire meant? |
Misread, sorry @andriej, yep you are correct. Mind submitting a PR to add priority to the code? |
That's the moment I can't help - I don't know python. ;-) |
@robbiet480 - what one of guys from polish HomeAssistant group described as resolution is working payload. Maybe someone (@bieniu ? :-)) could test it to be added too. |
I tested it. I added these lines to the component
and unfortunately this didn't help. |
@bieniu so now go to Advanced settings->Battery manager->protected aps or in Sony case Battery -> Excludes from Power Saving and tick Chrome. |
That's not possible on a OnePlus, some apps you can indeed exclude from battery saving, but not chrome |
@pergolafabio don't worry. It doesn't help. After 40 minutes phone is not getting notification at all... Might be related: https://bugs.chromium.org/p/chromium/issues/detail?id=935931 |
If y'all come up with a new fix I can submit a PR with it if no one else is willing to. |
I changed code to something like this:
Now I receive message when I wake up device, but still no wake... |
@pszafer I tested your fix and the effect is the same. The notification comes after phone wake. This isn't ideal but it's a huge improvement. |
I found this about high priority notifications: "High priority messages generally should result in user interaction with your app or its notifications. If FCM detects a pattern in which they don't, your messages may be de-prioritized. Android P introduced app standby buckets which limit the number of FCM high priority messages you can send to your app that don't result in the user using your app or viewing a notification. If, in response to a high priority message, a notification is displayed in a way that is visible to the user, then your app standby bucket quota will not be consumed by that message." |
@bieniu let's try to narrow down issue. I think that we need ttl in webpush method and in webpush headers... It's hard to investigate on one phone. About second. I always click on notification and get back click event. |
@pszafer On this version also, I receive notification after phone wake up. If I send two notifications when the phone is sleep then I receive only the first ones after wake up. |
Yikes.. I have both this problem but also that notifications aren't sent at all after "a while" because "UnauthorizedRegistration". That started after switching from GCM to VAPID. |
I'd be inclined to agree that is the problem, having read the entire bug post - it's clear that expecting this to be fixed anytime soon is a lost cause. It can't hurt Home Assistant to ensure the priority metadata is set - but it looks like setting Chrome to be excluded from battery optimising techniques is the only solution for the moment. |
@asjmcguire It's not always possible to exclude Chrome from battery optimization. On OnePlus phones Chrome is a system application and You can't exclude system applications. You can exclude Chrome Beta but it doesn't help. I checked this today. With Beta notification when the phone sleeps isn't delivered. The next problem is that if several notification are sent when the phone sleeps, only the first ones will be delivered after phone awake. The rest of the notifications will be lost. |
@bieniu about several notification you have to modify tag to not replace previous notification. Isn't it working for you? |
I commented out TTL shouldn't be necessary as critical notifications should have TTL 0 (phone call) but for chrome it doesn't always work... |
In my opinion, |
In my opinion |
I rather agree with @bieniu, ttl=0 is not only an issue for Doze. There's also spotty mobile coverage, airplane mode and rumor has it that some people even turn their phone off occasionally, or forget to charge it ;) Therefore I think making ttl configurable per notification might be the best solution, since not all notifications stay relevant equally long. |
To rule out Chrome issues, I have tried testing HTML5 push notifications in Firefox for Android. Without the TTL being set neither push notifications in Chrome, nor in Firefox work when the phone (Moto 5G plus) is in doze. I can confirm that push notifications don't work when the phone is in doze with Brave either (but its chromium based). It doesn't matter if the priority flag is set is to high. With the TTL value set to a different value (I used 36000) Firefox will display the push notification when the phone wakes from doze, but Chrome has still dropped the push notification. So I think there are two separate bugs causing the problem.... One in Chrome which we can't fix. The other is in home assistant, with the TTL being set to zero, which is expiring the notification when the phone is in doze. |
If it helps: I have used patched my instance with a ttl of 3600s and the priorities mentioned above. With these settings my html5 notifications work fine |
On OnePlus phones, we can't exclude chrome from battery optimalization |
@pergolafabio You can exclude Chrome Canary from battery optimization but can't stable build. |
Aha, didn't know what canary was , thnx for info |
Extended testing has revealed that eventually the firefox browser started dropping and completely ignoring push notifications while the phone is in doze. It doesn't matter if battery optomization for firefox is disabled. So I suspect there there is indeed an algorithm at work within android deciding that the behavior of home assistant's push notifications is too spammy, too potentially battery wasting, and not meeting their user interaction metrics and thus the expected behavior is being silently modified in the name of optimizing my android user experience. |
Just tested the fix in #22988. I created an html5 custom component containing changes of the PR I tested like this:
Also tested with my wife's phone (samsung A5 2017, android 8) which was already working, everything works fine too. Thanks for the fix ! |
@thomasgermain so it's far better working for you than for me :) |
@pszafer sorry for being too optimistic :( I forgot to mention that the webapk is not battery optimized, but I guess is something you already tried. |
edit Test environment is a MotoG5 Plus (Android 8.1.0) and Chrome Canary, with home assistant as a webapk with battery optomization disabled. After patching the correct file FCM push notifications now are received reliability upon waking at the very least. |
Again relevant to this conversation is the previously mentioned website https://dontkillmyapp.com/. You should check the site for details about what extra measures, if any, your manufacturer takes to conserve battery. |
For those who have time to inspect deeper what's going on, BatteryHistorian is pretty useful : https://developer.android.com/studio/profile/battery-historian |
#22988 Did the trick! Thanks! I just copied @pszafer' s files from here and put them in I did do a code edit to make all html5 messages 'high priority'. This way there is no delay in the message. Most of my messages are from my alarm, so I need them to come in as soon as possible. Line 84: It looks like this might be able to be configured from config.yaml or even for each automation, but I didn't want to take the time to find out. This way I know they are all set to high priority. I am on a Pixel 2 XL running Android 9 with battery optimization off on Chrome and the webapk. I tried Chrome Canary at the same time and there was no difference in responsiveness, but I do really like the app-like feel that canary offers with the webapk. I'm going to keep that :-) |
I did the same thing and it prevented HA lovelace from being accessible. I could get to the samba shares so it appeared that HA was loading and running. But until I removed the HTML5 folder from custom_components folder it was not letting the UI come up. Did I miss a step? |
Looks like it is all related; #23613 |
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. |
hi, whats the actual status on this? is it possible now to have the messages instantly ? |
Hi, you will have to set See https://www.home-assistant.io/integrations/html5/#ttl-and-priority |
yeah, i know, setup like this now, but not reliable
|
I'm hoping this will all be resolved the when the Android app is released?
…On Tue, 8 Oct 2019, 14:03 pergolafabio, ***@***.***> wrote:
yeah, i know, setup like this now, but not reliable
- service: notify.html5
data_template:
message: "Er staat iemand aan de deur!"
title: "Deurbel"
data:
tag: alert
image: !secret snapshot_buiten_deurbel
vibrate:
- 300
- 100
- 400
renotify: 1
ttl: 86400
priority: high
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#22249>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHRBATYTQ7YPXWX3ZP2RP7LQNSALNANCNFSM4HAFW4KA>
.
|
Hopefully. Right now most of the messages arrive to the phone, except they are not waking it up. |
yeah, same behaviour here, when i wake up the phone, i receive the message i started today with the "pushover" integration, seems the work verry good and verry easy |
Home Assistant release with the issue: 0.90
Last working Home Assistant release (if known): hard to say
Operating environment (Hass.io/Docker/Windows/etc.): Linux / venv / Python 3.7.2
Component/platform: html5 notify
Description of problem:
Since few versions (but it was hard to notice) HTML5 push notifications are not received by android phones while the phones are laying unused.
Push notifications work properly when testing with active screen or few minutes after it. If the screen is off (idle) for longer period, the notification never reaches the phone - not even when the phone is unlocked/active again.
On one of the groups we've managed to confirm problem on different phone brands, all with latest android 9 system. Also all of us run python 3.7.2.
Someone has also noticed that it may be because of some undocumented (in FCM Firebase) priority type, which defined, may change the behaviour and 'force' phone to show notification even when phone is not in use.
There's no issue with other notifications in meanwhile (communicators like whatsapp/messenger etc.)
Could person responsible for the html5 (@robbiet480 ?) could take a closer ook at this issue?
Problem-relevant
configuration.yaml
entries and (fill out even if it seems unimportant): not relevantTraceback (if applicable): no error messages
Additional information:
What's worth nothing it's not the matter of phone power-save features - we've tried different settings including turning them off.
The text was updated successfully, but these errors were encountered: