android icon indicating copy to clipboard operation
android copied to clipboard

Android Widgets Disconnecting Regularly

Open mark007 opened this issue 2 years ago • 20 comments

Home Assistant Android app version(s):

Android version(s): Android 13 September 2023 update.

Device model(s): OnePlus 9 Pro

Home Assistant version: Core version 2023.11.0

Last working Home Assistant release (if known): Has been happening for many recent versions.

Description of problem, include YAML if issue is related to notifications: When myself and others in the household on various OnePlus Phones and Android Tablets, we see that when we add various HA widgets like temperature sensors, or any widget for that matter, they show as having a red disconnected icon soon after the device sleeps. After we wake the device and see the red icon, the widgets seem to have no concept of trying to reconnect automatically. When they are touched, they do reconnect fine but not automatically which I am logging this issue for.

I feel that whenever the widgets have some reason to show the red icon indicating they have disconnected, they should make regular attempts to reconnect which should fix t;he issue, especially for those of us whose devices deep sleep, disconnecting all connections.

Companion App Logs:


Screenshot or video of problem:

Additional information:

mark007 avatar Nov 04 '23 02:11 mark007

Please get us the companion app logs from when the issue occurs. Without logs we will not be able to help. I personally cannot reproduce this as my widgets don't have connection issues.

dshokouhi avatar Nov 04 '23 02:11 dshokouhi

@dshokouhi whats the best way to get those, is it in the app itself.

mark007 avatar Nov 04 '23 02:11 mark007

Attaching logs from the app.

mark007 avatar Nov 04 '23 02:11 mark007

@dshokouhi whats the best way to get those, is it in the app itself.

Yes the steps are mentioned in the issue template.

Settings > Companion app > troubleshooting > show and share logs

Make sure to reproduce the issue before grabbing the logs otherwise we won't see the error

dshokouhi avatar Nov 04 '23 02:11 dshokouhi

No problem, during the log above I saw my few widgets show red icons. I can reproduce quite easily where they show and stay red until touched. I can readd logs whenever required.

mark007 avatar Nov 04 '23 02:11 mark007

In the attached log, i woke up my phone at 3:01. I left it open until 3:04 on screen doing nothing from my side, just watching the homescreen with widgets, and in all of that time, the widget i have called sensor.average_room_temperature showed as red/disconnected. It made no attempt to reconnect at all from what i can see from the attached logs. Are custom sensors not updated correctly like normal sensors like normal entities that are not custom defined like mine which is defined in my automatins.yaml?

mark007 avatar Nov 04 '23 03:11 mark007

ok I dont see any errors in the logs here I do see the websocket connection working when the screen turns on which is expected

11-04 02:49:35.786 15127 15127 D WebSocketRepository: Sending message 528: {type=config/entity_registry/get, entity_id=sensor.average_room_temperature, id=528}
11-04 02:49:35.786 15127 15127 D WebSocketRepository: Message number 528 sent
11-04 02:49:35.792 15127  4719 D WebSocketRepository: Websocket: onMessage (text)
11-04 02:49:35.793 15127 15211 D WebSocketRepository: Message number 528 received

BTW teh 2 logs are identical that you had posted, I think the second log may not be the right one?

The way widget updates work is based on the screen turning on and off, there is no reconnection attempt made as that will be battery intensive and also why tapping the widget will force it to update. The red icon is associated with an error so lets see the error first to see what can be done.

dshokouhi avatar Nov 04 '23 03:11 dshokouhi

Are custom sensors not updated correctly like normal sensors like normal entities that are not custom defined like mine which is defined in my automatins.yaml?

All entities update via the websocket and teh connection logic is mentioned above. Not sure what you mean by custom sensor but any sensor even template sensors or ones added by custom components are in the states tab and those will all auto update when the screen comes on, unless there was a connection issue.

dshokouhi avatar Nov 04 '23 03:11 dshokouhi

OK, what logs can I attach or am I misunderstanding the correct behavior. When i mentioned a few mins ago, that sensor I have called average_room_temperature, it was marked as red and is now red as i look at it on my phone. attaching screenshot. But now as i touch it, the red icon disappears. All around the 3:19/3:20 mark. Will attach logs now.

mark007 avatar Nov 04 '23 03:11 mark007

Strange I still don't see any errors and the websocket is successful

11-04 03:22:03.650 15127 15127 D WebSocketRepository: Sending message 567: {type=config/entity_registry/get, entity_id=sensor.average_room_temperature, id=567}
11-04 03:22:03.651 15127 15127 D WebSocketRepository: Message number 567 sent
11-04 03:22:03.660 15127  4719 D WebSocketRepository: Websocket: onMessage (text)
11-04 03:22:03.661 15127 15211 D WebSocketRepository: Message number 567 received

when you open the app again after this occurs is the app still open in the last place you left it or is it restarted?

dshokouhi avatar Nov 04 '23 03:11 dshokouhi

I'm not sure exactly what your asking. I can definitely try any order of events you suggest. My usual order events is to simply unlock my phone and as you can see now, the red icon shows on the home assistant entity. It will stay like that forever until i touch it.

mark007 avatar Nov 04 '23 03:11 mark007

The red icon on the 22.0 temperature value.

mark007 avatar Nov 04 '23 03:11 mark007

Sorry I meant just now when you were reproducing the issue and then going into the app to grab the logs. I am trying to see if maybe the reason why the logs look fine is because the app crashed previously when the issue first occurred.

Basically the red icon only shows up when there is a failure and the logs should show the failure but right now they do not.

dshokouhi avatar Nov 04 '23 03:11 dshokouhi

Yeah could it be the case that the logs do not have enough fine grained logs to see it. For me its not such a fine grained thing as it can last as long as I leave the screen on. If you could reproduce yourself it'd be the ideal scenario.

mark007 avatar Nov 04 '23 03:11 mark007

I can definitely reproduce it anyways over the coming days with any required logs. Its very reproducible.

mark007 avatar Nov 04 '23 03:11 mark007

Yeah could it be the case that the logs do not have enough fine grained logs to see it. For me its not such a fine grained thing as it can last as long as I leave the screen on.

Sorry this still doesn't answer my question of if the app is crashing or not, the app itself should not crash so if you can reproduce the issue please let us know if the app is crashing or not. If it is crashing then the app would not have the logs and the only way to get the logs is using Android Studio or ADB logcat, whichever you'd be comfortable with. Thats only needed if the app crashes while you reproduce the issue.

If you could reproduce yourself it'd be the ideal scenario.

I can't reproduce it my device still stays connected to the network even in deep sleep so i never see the issue.

dshokouhi avatar Nov 04 '23 03:11 dshokouhi

yeah whatever is best for you i can do. Just let me know.

mark007 avatar Nov 04 '23 04:11 mark007

OK I found a way to make it happen without having the phone sleep. If I purposely turn off WiFi/mobile data, touch one of the widgets to force it to go red. Turn back on WiFi/mobile data. I counted to 70 seconds and the widget hadn't reconnected. If I touch it it immediately comes back.

Could this be the cause of the issue, it doesn't seem to reconnect as soon as a data connection is restored.

mark007 avatar Nov 04 '23 16:11 mark007

yeah whatever is best for you i can do. Just let me know.

I did several times but you still have yet to tell me if the app is crashing and i dont know how many other ways I can ask. I have even mentioned if the app is crashing how to get the logs from other sources but I still get generic responses like this.

Could this be the cause of the issue, it doesn't seem to reconnect as soon as a data connection is restored.

as mentioned earlier in this ticket there is no reconnecting happening as that will result in battery drain, if the app does not connect when the screen turns on then its on the user to tap the notification and reconnect. Keep in mind this is not an issue for majority of users.

I am going to step away from this issue and see if someone else can help out.

dshokouhi avatar Nov 06 '23 15:11 dshokouhi

Apologies for late logcats. Some issues on my end. logcat attached from 18:51-18:53 this evening when I did the following.

logcat.zip

18:51 killed/started HA app clean. Touched the widget to get it to reconnect, waited for a minute. All was in a good state. 18:52 disabled wifi / mobile data, touched the widget to forcibly get it to get into a red/failed state, immediately turned back on wifi / mobile data About 30 seconds later: I stopped logcat, the widget was still red, there seemed to be no listening for wifi changing state events from what I can see.

It doesn't seem like the app itself is crashing from my lay mans review of the logcat. When I return to the app it also doesn't take any time to launch, which to me looks like its not after crashing, its immediately there when I return to it.

From what you are saying in your responses to me it looks like the following?

  1. It is by design only trying to connect on certain events like when the screen turns on. There's no concept of retrying to connect in the case of any other negative scenarios / losing data connection etc.
  2. Fixing or changing this is not being done because its a battery usage concern.
  3. This is not an issue for majority of users.

I guess my response to 1, 2 and 3 above would be the following.

  1. I have installed some other widgets from kasa / weather widgets / lifx. They are all 'resilient' to negative events like the network dropping for a second or two. I can't imagine in this day and age its acceptable for any modern software to not be resilient to this. Even some of the most basic and honestly not very well designed widgets from kasa will at least 'reconnect' when my phone turns on / data comes back.

  2. How can it be the case that these other widgets can do this efficiently. Even the likes of YouTube or any other data syncing app like a google photos background backup process etc will have this concept of being resilient to network outages which being honest, will happen millions of times per day for nearly every user on the planet. I think there must be some misunderstanding here thinking home assistant is in some way special or going to drain any more batter than these other apps and widgets. I just think its false to say this.

  3. What is this based on? Is it based on the fact that nobody has written this ticket before me or is it based on a hunch. If its because others have not logged the ticket my response would be that I also noticed this issue many months ago and temporarily 'gave up' on using HA widgets or at least relying on them for anything important. It is only out of my interest in homeassistant and seeing it truly be the best home automation platform that I am logging this. My assumption would be that others are not either heavily using widgets at all, or if they are and are seeing this issue, they just don't care so strongly to log the github ticket itself.

Anyways many thanks, hopefully someone is interested to fix this as to me, seeing all of my other widgets be resilient (even the 'bad' ones) and the homeassistant one not adds a slight sadness to my heart, and I don't believe for a second there isn't a developer out there that wouldn't agree with me and look to push a patch to add this resiliency in an upcoming companion app version.

mark007 avatar Nov 06 '23 19:11 mark007