Skip to content
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

Camera traffic, when app in background. #979

Open
nick2525 opened this issue Sep 25, 2020 · 73 comments · Fixed by #1194
Open

Camera traffic, when app in background. #979

nick2525 opened this issue Sep 25, 2020 · 73 comments · Fixed by #1194
Labels
bug Something isn't working webview

Comments

@nick2525
Copy link
Contributor

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.

@nick2525 nick2525 added the bug Something isn't working label Sep 25, 2020
@dshokouhi
Copy link
Member

You need to check that "automatically close connections" in your HA user profile is enabled. The frontend actually handles this part as we are just a webview so they look to see if you have gone idle.

You should also check that you are not going to the home screen when you have the more info panel open, another offender in this case is if you use the live view card on lovelace which plays video on the homescreen directly.

@nick2525
Copy link
Contributor Author

  1. I checked "automatically close connections" - "Should we close the connection to the server after being hidden for 5 minutes?" - was on, but it seems 5 minutes too much for mobile.
  2. I use card on lovelace which plays video on the homescreen directly - as it is nice feature.
  3. Yes, HA is Webview, but HA is not website, here you can control server or frontend, and forward iOS /Android lifecycle to frontend, maybe even to backend, to lower the number of frames in the video, or use still image when APP is onStop() or onPause()

@barrymossel
Copy link

This started for me too after (one of the) latest update(s). Just spend 2,5 GB in 10 minutes. Never experienced this before.

@JBassett
Copy link
Collaborator

@nick2525 and @barrymossel can you please include your yaml camera config and frontend config so we can attempt to recreate. I have tried with my personal setup and I am unable to get the app to stream in the background.

@nick2525
Copy link
Contributor Author

camera:

  • platform: mjpeg
    name: children_camera
    username: *****
    password: *****
    mjpeg_url: http://.../live/0/mjpeg.jpg

camera 3:

  • platform: mjpeg
    name: kitchen_camera
    mjpeg_url: http://...:56000/mjpeg

camera 4:

  • platform: mjpeg
    name: slipping_camera
    username: admin
    password: admin
    mjpeg_url: http://.../live/0/mjpeg.jpg

camera 5:

  • platform: generic
    name: slipping_room_camera
    framerate: 2
    still_image_url: http://.../webcapture.jpg?command=snap&channel=1

camera 6:

  • platform: generic
    name: child_room_camera
    framerate: 2
    still_image_url: http://.../webcapture.jpg?command=snap&channel=1

@nick2525
Copy link
Contributor Author

nick2525 commented Sep 28, 2020

{ "background": "radial-gradient(crimson, skyblue)", "cards": [ { "camera_view": "live", "entity": "camera.children_camera", "title": "\u041a\u043e\u0440\u0438\u0434\u043e\u0440", "type": "picture-entity" }, { "camera_view": "live", "entity": "camera.child_room_camera", "title": "\u0441\u043f\u0430\u043b\u044c\u043d\u044f", "type": "picture-entity" }, { "camera_view": "live", "entity": "camera.kitchen_camera", "title": "\u043a\u0443\u0445\u043d\u044f", "type": "picture-entity" }, { "camera_view": "live", "entity": "camera.slipping_camera", "title": "\u043b\u0435\u0441\u0442\u043d\u0438\u0446\u0430", "type": "picture-entity" }, { "camera_view": "live", "entity": "camera.slipping_room_camera", "title": "\u0441\u043f\u0430\u043b\u044c\u043d\u044f", "type": "picture-entity" } ], "id": "cameras", "theme": "dark-mode", "title": "\u043a\u0430\u043c\u0435\u0440\u044b" }

@barrymossel
Copy link

barrymossel commented Sep 29, 2020

camera:
  # - platform: foscam
    # ip: !secret ip_camera_kleren
    # name: Klerenkamer
    # username: !secret camera_kleren_username
    # password: !secret camera_kleren_password
  # - platform: ffmpeg
    # name: Lise
    # input: !secret url_camera_lise
  - platform: mjpeg
    name: Sophie
    mjpeg_url: http://192.168.1.43:8081/
  - platform: mjpeg
    name: Lise
    mjpeg_url: http://192.168.1.43:8082/
  - platform: mjpeg
    name: Hal
    mjpeg_url: http://192.168.1.43:8083/

The ones that were commented out are my old camera's which didn't have this problem. When I "updated" those the traffic started getting out of hand. Did some more investigation: I use MotionEye as when I load the rtsp feeds directly into HA I get a lag ranging from 4 to 60 sec. When I load the rtsp feed into MotionEye and let that process and stream it, there is virtually no lag (max 1 sec). But apparently the feeds use way too much bandwidth. When I load the stream url into a browser it uses lot's of data as well. So that's one of the issues for me. But now I turned the quality of the feeds to 25% and it still uses 100's of MB's per couple of minutes. Way more than the original feed passing through the Ewelink app (camera's are Sonoffs).
But still, I believe the old camera's didn't do any of this anyway. Never noticed something weird on the data usage side of the HA app... So, could be two things I guess: very small feeds with low data usage, or no streaming in background.

And btw, if I force the app to close it doesn't stream and use data. If I just go back to Android home screen it does use bandwidth.

@barrymossel
Copy link

Lovelace:

          - type: picture-glance
            title: Sophie
            camera_image: camera.sophie
            camera_view: live
            aspect_ratio: 16:9
            entities:
              - binary_sensor.deursensor_sophie_contact      
              - light.sophie       
          - type: picture-glance
            title: Lise  
            camera_image: camera.lise
            camera_view: live
            aspect_ratio: 16:9
            entities: 
              - binary_sensor.deursensor_lise_contact
              - light.lise

@bram2202
Copy link

bram2202 commented Oct 8, 2020

I got the same issue (#1017)
I also happen to have a Xiaomi mi 9(T pro)

HA config:

- platform: generic
  name: Hallway
  still_image_url: !secret camera_hallway_snap_url
  verify_ssl: false

- platform: generic
  name: Street
  still_image_url: !secret camera_street_snap_url
  verify_ssl: false

- platform: generic
  name: Livingroom
  still_image_url: !secret camera_livingroom_snap_url
  verify_ssl: false

Lovelace:

    cards:
      - aspect_ratio: 0%
        camera_image: camera.hallway
        camera_view: live
        entity: camera.hallway
        show_name: false
        show_state: false
        type: picture-entity
      - aspect_ratio: 0%
        camera_image: camera.livingroom
        camera_view: live
        entity: camera.livingroom
        show_name: false
        show_state: false
        type: picture-entity
      - aspect_ratio: 0%
        camera_image: camera.street
        camera_view: live
        entity: camera.street
        show_name: false
        show_state: false
        type: picture-entity

@nick2525
Copy link
Contributor Author

nick2525 commented Oct 9, 2020

My wife has Xiaomi mi 9T, the bug is also reproduced.

@ericlathrop
Copy link

I just got burned by this, wasted almost 1GB of my data plan. Using the Zoneminder integration, and Picture Glance Cards.

zoneminder:
  - host: zoneminder.mydomain.com
    ssl: true
    username: x
    password: x

sensor:
  - platform: zoneminder
    include_archived: false

camera:
  - platform: zoneminder

@bramkragten
Copy link
Member

Fix: home-assistant/frontend#7362

@nick2525
Copy link
Contributor Author

Was it fixed in 0.117.0b1? Because the bug is still being reproduced(

@dshokouhi
Copy link
Member

@nick2525 can you verify the frontend version you are on please?

@nick2525
Copy link
Contributor Author

Frontend version: 20201021.1 - latest

@nick2525
Copy link
Contributor Author

Screenshot_2020-10-22-20-13-52-062_com miui securitycenter

@dshokouhi
Copy link
Member

@nick2525 thanks, and you waited 5 minutes for the connection to close right?

@dshokouhi
Copy link
Member

BTW it looks like the linked issue was actually not the fix for this. That was the reasoning for the bug closing and being re-opened.

@nick2525
Copy link
Contributor Author

Some cameras disconnected after 5 minutes, but live view is not restored on those cameras. But if I pres on camera, stream works. But live view is not restored on app onResume()

@dshokouhi
Copy link
Member

live view being restored is unrelated to this issue....this issue is purely about making sure the data flow stops when the app is in the background after 5 minutes.

@nick2525
Copy link
Contributor Author

Screenshot_2020-10-22-20-44-29-006_com miui securitycenter
It seems, that some camera didn't stop after ten minutes, because It too much data for sensors, but it 8 times less traffic when after one minute in background

@dshokouhi
Copy link
Member

what are the results if you disable all your picture entity cards? does it 0 out then after 5 minutes?

@nick2525
Copy link
Contributor Author

Screenshot_2020-10-22-21-06-34-703_com miui securitycenter

@nick2525
Copy link
Contributor Author

nick2525 commented Oct 22, 2020

It almost no traffic when I disabled camera view live, and 0.00kb after 7 minutes with disabled camera view live

@bramkragten
Copy link
Member

This might (probably?) be fixed in 2021.9

@abmantis
Copy link

abmantis commented Sep 2, 2021

This might (probably?) be fixed in 2021.9

Great! Any pointer to the fix commit?

@R5fan
Copy link

R5fan commented Sep 13, 2021

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
Copy link
Member

All known workarounds are mentioned in this issue

@R5fan
Copy link

R5fan commented Sep 14, 2021

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
Copy link

TRusselo commented Sep 14, 2021

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
Copy link

R5fan commented Sep 15, 2021

  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
Copy link

R5fan commented Sep 18, 2021

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
Copy link

stale bot commented Jan 8, 2022

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.

@stale stale bot added the stale label Jan 8, 2022
@nick2525
Copy link
Contributor Author

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

@stale stale bot removed the stale label Jan 16, 2022
@dshokouhi
Copy link
Member

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
Copy link

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

@TRusselo
Copy link

TRusselo commented Feb 8, 2022

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

@zSprawl
Copy link

zSprawl commented Jan 27, 2023

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
Copy link
Member

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
Copy link

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
Copy link

Still an issue as of May 2024

Screenshot_20240529_190840_Settings.jpg

@rosicenko
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working webview
Projects
None yet
Development

Successfully merging a pull request may close this issue.