home-assistant / iOS

:iphone: Home Assistant for Apple platforms
https://companion.home-assistant.io
Other
1.48k stars 283 forks source link

Local Push becomes disabled and cannot become re-enabled until iPhone is rebooted #2502

Open tholland15 opened 6 months ago

tholland15 commented 6 months ago

Model Name: iPhone 15 Pro Software Version: 17.1.2 App version: 2023.12.1

Home Assistant Core Version 2023.12.4

Describe the bug For the last 2 days, the Battery State Sensor no longer immediately updates when the phone is charging or taken off of a charger, while HA is in the background. The sensor updates immediately if HA is in the foreground. Before a recent HA iOS App update (before 2023.12.0 or before 2023.12.1, I'm not 100% sure) this sensor would update immediately even with HA in the background.

To Reproduce Put HA iOS app in the background, plug phone into charger, see that Battery State Sensor does DOES NOT update. Put HA iOS app in the foreground, plug phone into charger, see that Battery State Sensor DOES update.

Expected behavior Previously, the sensor state would update immediately when the phone was put on, or taken off of a charger, even if HA was in the background.

Additional context This bug is present on both iPhones in our household (same model and versions). I could work around this with a iOS shortcut, sending events when charging or not, but I'd rather not set that up if this is a simple regression that will quickly be fixed. If it WON'T be fixed soon, please just let me know so I can go the shortcuts route, and get my automations working again. Thanks!

bgoncal commented 6 months ago

As we have in the documentation: On iOS, sensors update in limited situations: when your location changes, periodically when the app is running in the foreground, when you pull-to-refresh the web view, in the background at a rate determined by iOS, and when performing an "Update Sensors" or via "Send Location" shortcut or push notification.

https://companion.home-assistant.io/docs/core/sensors/

I also just ran an older version of the app and at least to me it behaves the same. Let me know if you endup not having updates in background ever.

bgoncal commented 6 months ago

To achieve what you want we may need to implement https://developer.apple.com/documentation/BackgroundTasks which is currently not supported in the App.

tholland15 commented 6 months ago

Hi Bruno,

I'm going to have to disagree with you strongly here, as until 2 days before I opened this issue, I used this sensor extensively and it always updated instantly.

Since this was not an intentional change, unless this was caused by a change in iOS, this is definitely a regression.

For as long as I've used home assistant, I have had it set so that my wife and I both putting our phones on our nightstand chargers (when other conditions are met) puts our house into "Night Mode" which kicks off over 50 other tasks (turning off lights, changing thermostats, etc).

When we both remove our phones from the charger in the morning, it brings our house out of "Night Mode" which kicks off over 50 other tasks to get our home ready for the day.

We've been using this iOS sensor for this, twice a day, and it has always updated in less than a second, until 2 days before I filed this issue, which was also around the time the iOS app was updated.

Happy to help debug this further.

bgoncal commented 6 months ago

Hi Bruno,

I'm going to have to disagree with you strongly here, as until 2 days before I opened this issue, I used this sensor extensively and it always updated instantly.

Since this was not an intentional change, unless this was caused by a change in iOS, this is definitely a regression.

For as long as I've used home assistant, I have had it set so that my wife and I both putting our phones on our nightstand chargers (when other conditions are met) puts our house into "Night Mode" which kicks off over 50 other tasks (turning off lights, changing thermostats, etc).

When we both remove our phones from the charger in the morning, it brings our house out of "Night Mode" which kicks off over 50 other tasks to get our home ready for the day.

We've been using this iOS sensor for this, twice a day, and it has always updated in less than a second, until 2 days before I filed this issue, which was also around the time the iOS app was updated.

Happy to help debug this further.

No worries, let's try to find what changed; I know when local push is activated, it also updates sensors more often, but I don't see in the codebase any trigger based on battery/charge state; there is one, but it works only in the foreground. @zacwest Am I missing something here?

zacwest commented 6 months ago

Local Push is the only way this can update immediately. We observe and immediately update if we see changes but on iOS this means Local Push or something else.

Might be worth double checking the notification update isn't changing behavior or Local Push just isn't informed under Xcode 15. Linked-on-or-after checks are pervasive in SDK updates.

tholland15 commented 6 months ago

It would definitely be local push in my use case since my wife and I would be home and on our home WiFi.

Which made me go check and make sure local push was working as it should and I saw: Connected via: Internal URL Version: 2024.1.2 WebSocket: Connected Local Push: Disabled

Uh, that's odd. I check under Internal URL and make sure Local Push is enabled and the SSID is my home SSID and I am on WiFi. All is correct.

I kill and restart the Home Assistant app a few times, Local Push is still Disabled.

I reboot my phone, after making no changes, start the HA App and Local Push is now: Available (0)

I plug in my phone here at my desk and the HA sensor immediately updates 🎉

So it looks like the real bug here was that Local Push somehow got disabled when the app updated and it took a reboot to fix it? Why did this happen I wonder? Will this happen again? Do we need some recovery logic here?

I can check my wife's phone when she gets home, but since hers was behaving the exact same way, I expect her Local Push is also currently "Disabled" and she has not rebooted since this began happening.

tholland15 commented 6 months ago

I confirmed on my wife's phone that she also had Local Push: Disabled despite having all the correct settings. Just like with my phone, a reboot without changing any settings got Local Push activated again.

She has not rebooted her iPhone since before Christmas, and this issue started happening on both of our phones on the same day (likely after we received the latest app update, 1st or 2nd of Jan, not sure exactly which).

Was this a one time issue related to the latest update? Or is there a bug that will disable local push until the phone is rebooted under some unknown circumstance?

I propose changing the name of this issue to something like "Local Push becomes disabled and cannot become re-enabled until iPhone is rebooted"

bgoncal commented 6 months ago

I see the same behavior on my iPhone too, I will investigate

bgoncal commented 5 months ago

Not sure yet the reason for that but the Local Push becomes available again for me after sometime, did it happen to deactivate again to you? If it does please (if possible) don't manually force it to reactivate, wait a few hours or a day and let me know more less how long it took.

tholland15 commented 5 months ago

Not sure yet the reason for that but the Local Push becomes available again for me after sometime, did it happen to deactivate again to you? If it does please (if possible) don't manually force it to reactivate, wait a few hours or a day and let me know more less how long it took.

I just noticed it's disabled again while I'm at home, on WiFi. I'll try to keep an eye on it and let you know approximately when it becomes enabled.

No info yet on what is causing it to get disabled?

tholland15 commented 5 months ago

Also, I use HA push notifications fairly extensively. Would local push being disabled also cause notifications to be sent via Apple's servers, using up my daily quota and causing a noticeable (few second) delay?

WizBangCrash commented 4 months ago

I'm having the same issue and an iPhone reboot does not fix it. Local push has been disabled for days now, but is enabled on my wife's iPhone with the same app configuration as me. I am running app version 2024.2.1 and I've only noticed it since upgrading. iPhone is a 12 Pro and running 17.2.1. Wife's is an iPhone XR also on 17.2.1 I tried deleting the server in the app, killing off the app and then rebooting, but my app is always showing as disabled for local push. Tomorrow I am going to rey deleting the app from my phone and then reinstall it. I'll let you know if that has any effect. Let me know if there is any debug information I can provide to help diagnose.

WizBangCrash commented 4 months ago

I deleted the app from my iPhone this evening. Rebooted my phone, then re-added the app. Local Push is now working for me 👍 Hopefully this won’t happen on the next update.

bgoncal commented 2 months ago

Can someone check if the issue is resolved on 2024.4? I wasn't able to reproduce it anymore

ckglobalroaming commented 2 months ago

2024.4.4 same issue. No local push. Reboot phone and it comes back. IOS 17.4.1. Thanks.

ErikvO commented 6 days ago

I have the same issue: every once in a while my iPhone continues charging to 100% instead of the 85% I set up in an automation. Every time it is due to local push showing disabled, despite being connected to the internal URL with web sockets connected. I can only fix it by restarting the phone. I’ve been having this issue for more than a year now.

It happened again this morning (which is the reason for me trying to find a solution again).

I’m on version 2024.6.4. I just noticed the app updated today. Might this be the cause?