home-assistant / android

:iphone: Home Assistant Companion for Android
https://companion.home-assistant.io/
Apache License 2.0
2.32k stars 643 forks source link

Camera traffic, when app in background. #979

Open nick2525 opened 4 years ago

nick2525 commented 4 years ago

Home Assistant Android version: 2.4.1-full

Android version: 10 Phone model: Xiaomi mi 9 Home Assistant version: 0.115.3 Last working Home Assistant release (if known): no Description of problem:

When app in background, video streams from cameras does not stop stream. Almost all apps stops video stream at onPause() Android lifecycle, but HA does not. Now the problem is even more serious, because from the activities of the sensors, the system almost never kills the application. I have a lot of cameras and I wasted 70 gigabytes in a month because of this bug. Plus the battery runs out quickly. Traceback (if applicable):

Screenshot of problem: Screenshot_2020-09-25-18-25-18-432_com miui securitycenter

Additional information: Solution: You should stop stream, when device goes onStop(), maybe communicate with HA server, and show video placeholder.

barrymossel commented 3 years ago

But could it help to have a different setting in frontend for mobile apps/browsers?

Thats unrelated to the android app but I am sure you can start a discussion about it in the frontend repo because that is where the update will come from.

Done that: https://github.com/home-assistant/frontend/discussions/8831

Last month I had almost 20GB of background data (luckily through wifi due to corona), which could be dramatically lower if the connection closes after 10 seconds.

You can just remove cameras from the home page and keep them on a tab that isn't normally visible and it will greatly reduce the camera stream issue. The issue here is that the camera is the last thing being observed so its kept open. By ensuring the video doesnt even start on the tab it removes the issue. Also as noted in this thread the connection closing didn't solve the issue so we are not sure where it is coming from.

My cameras aren't on the homepage. Actually when I open a tab with cameras traffic goes up significantly, then switch to one without and close the app, traffic keeps on that level. Closing the app eliminates the traffic.

Wouldn't this whole issue be frontend related? When a stream is out of view (either because the tab/view has changed to another, or the browser/app closed), it should not use traffic.

barrymossel commented 3 years ago

Ah, I am not alone: https://github.com/home-assistant/frontend/issues/8630 & https://github.com/home-assistant/frontend/issues/5437

barrymossel commented 3 years ago

Also as noted in this thread the connection closing didn't solve the issue so we are not sure where it is coming from.

Btw, traffic does stop for me after XX (probably 5) minutes.

barrymossel commented 3 years ago

For MotionEye users:

Don't use the streaming url and camera entity, but embed url with iframe card. When the camera is out of view (either closing the app or changing tab/view) stops camera traffic. Unfortunately not possible with picture_glance to show certain entity states, but I will think of something else for that...

TRusselo commented 3 years ago

still happening

bramkragten commented 3 years ago

This might (probably?) be fixed in 2021.9

abmantis commented 3 years ago

This might (probably?) be fixed in 2021.9

Great! Any pointer to the fix commit?

R5fan commented 3 years ago

Im not sure yet if this is indeed fixed in 2021.9, Im only upgrading now, but I need an emergency workaround in case this isnt fixed or happens again in the future; today I blew through my monthly datacap and incurred a 50 euro data charge in an hour, and I hadnt even turned on my phone's screen. I need something to restrict companion's data usage. I disabled "background data" but that doesnt seem to help.

I can presumably totally block it with an android firewall, but then I might as well just uninstall it.

Im trying to make a node red flow that monitors the app_rx_gb sensor and correlates it with being on mobile data, but somewhat ironically, that sensor doesnt seem to update in the background, unless something else changes (like my location or alarm clock?) And even if it did, Im not sure what I can do to stop the data, other then send myself a notification. Which Ill probably read too late.

dshokouhi commented 3 years ago

All known workarounds are mentioned in this issue

R5fan commented 3 years ago

2019.9 doesnt fix it for me. Checked HA on my phone this morning for 5 seconds, closed the app and phone and and 30 minutes later it has used 1.5GB and keeps going up.

When I said workaround, I mean some emergency / brute force "solution", something that works independently of the companion app. An android app or setting of some kind to limit the impact this issue can have or just deny it access to mobile data at all. In android settings I disabled mobile background data usage: image

but it seems to think HA doesnt run in the background? In the app it says it has background access: image

How do I revoke that?

I need something other than uninstalling HA companion (a ton of automations depend on its sensors), and right now all I have is turning off mobile data on my phone whenever I leave the house.

TRusselo commented 3 years ago

2019.9 doesnt fix it for me. Checked HA on my phone this morning for 5 seconds, closed the app and phone and and 30 minutes later it has used 1.5GB and keeps going up.

When I said workaround, I mean some emergency / brute force "solution", something that works independently of the companion app. An android app or setting of some kind to limit the impact this issue can have or just deny it access to mobile data at all. In android settings I disabled mobile background data usage:

but it seems to think HA doesnt run in the background? In the app it says it has background access:

How do I revoke that?

I need something other than uninstalling HA companion (a ton of automations depend on its sensors), and right now all I have is turning off mobile data on my phone whenever I leave the house.

Well... couple things.... Android Settings > apps > home assistant > Battery > Allow background Activity Android Settings > apps > home assistant > Battery > Optimize battery usage BUT... disabling these options will mess with the sensors you NEED working. IF you want to reset all permissions,... you could always delete/re-install app... not sure if it would create duplicate phone/sensors in HA... have not tried. but AGAIN.... these background permissions are needed for your phone sensors...

Im in the same boat. So i removed the camera page from home assistant. I use blue iris to check them instead.

But here are a couple things that were helping me before i removed them. it fixed the problem for me, but others in my home could not follow these 2 simple rules..... so i eventually removed the page for those users..

1 never close HA app by pressing the HOME button on your phone. The home button does not close ANY app. just pushes it to the background. in Android there are 2 ways to close apps. 1. press BACK BACK BACK BACK BACK ect.... until you see the home screen. or 2. press RECENT APPS button and swipe the app away. (depending on your phone you might have a recent apps button, or you have to long press/ double press home/back to display recent apps menu)

2 Another work-around i was having success with for a while, in HA put all cameras on a single page. when checking the cameras go to that page, then when done, change to a different page before closing app. **see above about closing apps.

image

i really dont understand why fixing this is so hard.... if app not in foreground, then close video streams

R5fan commented 3 years ago
  1. press BACK BACK BACK BACK BACK ect.... until you see the home screen. or 2. press RECENT APPS button and swipe the app away

This doesnt help. I force closed HA and it would still gobble up bandwidth "in the background". Im no developer, but I dont understand the problem either. The companion app should be 2 parts; one for the front end (basically a browser), one for the sensors/communication. Only the latter should be allowed to run in the background. I wouldnt even mind if companion only did the latter; provide sensor data, something for instructions (and via MQTT please!), while we use a browser for the dashboard. A browser we can actually close :).

Regarding Blue Iris, I did the same, relying mostly on BI web interface, and now I managed to actually integrate individual BI UI3 web streams and its web GUI in to HA. I wrote a little piece on it here: https://www.reddit.com/r/homeassistant/comments/po34pg/finally_low_latency_low_bandwidth_high_quality/

This also completely solves this particular issue, as blue iris will stop streaming when the camera frame has no focus, and/or after a configurable time. Completely independently of HA.

This isnt a good or universal solution (especially for those not using BI), but its a great workaround for me, or anyone in the same boat; and even if this bug finally gets fixed, it will be some time before I trust HA cameras with my bandwidth. 50 euro is bad enough, but if this had happened while I was traveling abroad, it could have been a very expensive lesson.

R5fan commented 3 years ago

Using iframes for camera streams to work around this bug has at least problem I wasnt aware off; it stops android from entering sleep mode, which is particularly annoying on wall mounted tablets.

I worked around that, and that solution may also work -or at least help- for this bug, if you use regular picture entity cards for camera's: whenever I want the tablet to sleep, I redirect companion to a dedicated view that has no iframes (or camera's). I dont know for sure if this will stop regular camera entities from streaming in the background, but it may help and it certainly stops UI3 streams which only stream when they are in the foreground.

This behavior has an unexpected benefit for wallpanels too; instead of having to keep sending notifications (which require the cloud!) just to keep my tablets awake while im in the room or the lights are on, the iframe does that for me now. So I can pretty much turn the screen on or off with one command. Full node red flow here: https://www.reddit.com/r/homeassistant/comments/ppwln7/node_red_flow_to_allow_ha_tablets_to_enter_sleep/

stale[bot] commented 2 years ago

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. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

nick2525 commented 2 years ago

now the camera stream picture dies if HA is open for a very long time. For example, I have a tablet hanging on the wall. I would like the stream to automatically restart

dshokouhi commented 2 years ago

now the camera stream picture dies if HA is open for a very long time. For example, I have a tablet hanging on the wall. I would like the stream to automatically restart

Does that happen in chrome for android? I think there was some frontend websocket issues in HA core 2021.12 that were fixed in the latest point release.

lsdlsd88 commented 2 years ago

this is still an issue. App on Android even in background pulling video stream all the time

TRusselo commented 2 years ago

yeah this did not happen to me in chrome. HASS companion app

zSprawl commented 1 year ago

I’m also having the issue anytime a camera entity is on the dashboard, it will eventually crash the app. The more camera entities, the fast it manifests.

dshokouhi commented 1 year ago

I’m also having the issue anytime a camera entity is on the dashboard, it will eventually crash the app. The more camera entities, the fast it manifests.

That is actually not the same issue as this one, as far as I know the app is not crashing here because there is background data occurring and if the app crashes after a short while I dont think anyone will see GB of data like above. Once an app crashes it is no longer connected to webview. If you are seeing crashes please open a new issue and fill out the template provided with the crash log. In your case check to see if there is a Recent Crash tab when you pull hte app logs for the template. If it is there that is the log we will need.

radhoo2k10 commented 1 year ago

Screenshot_20230321_182315_com huawei systemmanager Screenshot_20230321_182321_com huawei systemmanager Still an issue as of 21th of March. Huawei android phone. Latest companion app and latest HA on server. 2 camera streams on page 1.

JeanneD4RK commented 5 months ago

Still an issue as of May 2024

Screenshot_20240529_190840_Settings.jpg

rosicenko commented 2 months ago

Same issue happening to HA app running on my NSPanel Pro and absolutely trashing its RAM.