android icon indicating copy to clipboard operation
android copied to clipboard

Unable to connect to Home Assistant error when playing video opened from notification

Open Rogue136198 opened this issue 3 years ago • 12 comments

Home Assistant Android version: beta-2484-0e0994de-full

Android version: Android 12 Android 13 (Beta)

Phone model: Pixel 4a (5G) Pixel 5 (in a VM)

Home Assistant version: 2022.7.5

Last working Home Assistant release (if known): N/A

Description of problem: When playing a video clip opened from a notification I receive the error "Unable to connect to Home Assistant" The video continues to play behind the error message

The issue is present on my primary Pixel 4a (5G) running Android 13 Beta 4 and the beta release of HA. This issue was present when I was running Android 12

The issue is also present on a Pixel 5 VM running Android 12 stable

To further clarify, the issue happens when accessing a video from /api. The URL format is as follows /api/frigate/notifications/{{id}}/{{camera}}/clip.mp4

Traceback (if applicable, to get the logs you may refer to: https://companion.home-assistant.io/docs/troubleshooting/faqs/#android-crash-logs):

Debug Log from Android Studio VM android_studio_log.txt

Debug Log from In App homeassistant_companion_log_6-16-2022_12-9-36.txt

Screenshot of problem: image

Additional information:

  • I have reviewed Issue #2325 but I was still unable to solve the issue by restarting Mosquitto. To further clarify, I've rebooted everything.
  • I am running Home Assistant behind nginx using the SWAG docker container. I have confirmed this issue is present when connecting directly to the HA docker IP.
  • I am using the new mTLS option but the issue was present before implementing this. Also the issue is present when accessing the docker IP directly thus bypassing the mTLS auth.
  • I have not ruled out that this could be an issue with the Frigate Integration

Rogue136198 avatar Jul 16 '22 16:07 Rogue136198

Duplicate of https://github.com/home-assistant/android/issues/1672

dshokouhi avatar Jul 16 '22 17:07 dshokouhi

Duplicate of #1672

Can you please explain how this is duplicated? This issue is regarding opening /api in app not /media

When I open /api/frigate/notifications/{{id}}/{{camera}}/clip.mp4 I am not receiving a 401 error, the content successfully loads in the app and continues to load even after the error message appears. I can even download the clip after opening it.

This issues is not about the content not loading, its about an error message appearing over the content even though there is no error preventing the content from loading.

Rogue136198 avatar Jul 16 '22 18:07 Rogue136198

I have now confirmed that /api/frigate/notifications/{{id}}/{{camera}}/clip.mp4 does not require authentication by capturing a URL generated by the application and opening it in Chrome while incognito. The ONLY required authentication is what is added by my reverse proxy, in my case, mTLS.

This further confirms that this issue is not a duplicate as /media requires authentication while /api/frigate does not

Rogue136198 avatar Jul 16 '22 21:07 Rogue136198

Ok before I reopen can you try using a standard HA API instead of one built by a custom component? Try camera proxy please.

dshokouhi avatar Jul 16 '22 22:07 dshokouhi

Gave it a go, was about to figure out why I was receiving a 401 error for the camera proxy when the following showed up several seconds after the 401.

image

In this case my URL is /api/camera_proxy_stream/camera.camera_proxy_camera_front_door

I then figured out how to auth the camera proxy (stole an API key from the UI) URL is as follows: /api/camera_proxy_stream/camera.camera_proxy_camera_front_door?token=APIKEY

The result is it loads then you get this lovely error.

image

Rogue136198 avatar Jul 16 '22 23:07 Rogue136198

Looks like you used the incorrect format for the API, see the docs for proper format

https://companion.home-assistant.io/docs/notifications/notification-attachments#automatic-snapshots

There is no need to add auth here as the app already does that part.

How long does it take for the pop-up to show up? 10 seconds after loading?

dshokouhi avatar Jul 16 '22 23:07 dshokouhi

Looks like you used the incorrect format for the API, see the docs for proper format

https://companion.home-assistant.io/docs/notifications/notification-attachments#automatic-snapshots

There is no need to add auth here as the app already does that part.

Gave it a go, I now get a 404 error, I tried with multiple cameras and tried the direct IP instead of my reverse proxy. All the same

How long does it take for the pop-up to show up? 10 seconds after loading?

Yes, I just timed it and it looks to be about 10 seconds. Worth noting that every once in awhile its almost instantaneous.

Rogue136198 avatar Jul 17 '22 00:07 Rogue136198

The reason why the pop-up here shows up is because the app is dependent upon the HA frontend notifying the app that it is connected via the external bus. When the API is used we may not get that message but that also means if a user had an invalid API call we may miss not showing them that we can't connect.

I do not think its the correct approach to avoid showing this pop-up if a user is on an API page. I wonder if we detect an API call if we should just load it up in the browser instead of the apps own webview activity to avoid this.

The code for showing this pop-up is here: https://github.com/home-assistant/android/blob/f4eea70b2cd00cf334da9b1974a5409fdaab17db/app/src/main/java/io/homeassistant/companion/android/webview/WebViewActivity.kt#L1316-L1325

dshokouhi avatar Jul 22 '22 15:07 dshokouhi

I wonder if we detect an API call if we should just load it up in the browser instead of the apps own webview activity to avoid this.

I do not think this is a good approach. You can already do this by specifying the absolute path with the FQDN to open in the browser. It only opens in app when using the relative path.

Having the ability to open a video in app adds to the app UX making it feel more polished (save for the current error).

Rogue136198 avatar Jul 22 '22 17:07 Rogue136198

I do not think this is a good approach. You can already do this by specifying the absolute path with the FQDN to open in the browser. It only opens in app when using the relative path.

Its not the same though, relative path forces the app add authentication. Opening in the browser requires the user to do so, we would just be adding auth to the request and opening it that way. It makes sense for the app to open a relative lovelace path, but not an API path which has no frontend UI.

Having the ability to open a video in app adds to the app UX making it feel more polished (save for the current error).

There is no app UX though, our webview activity is plain without any UI added. Any UI you see is from the HA frontend. The benefit of a browser is that the user can close the tab, you can't do that in our app as there are no tabs.

dshokouhi avatar Jul 22 '22 17:07 dshokouhi

I'm having the exact same issue. Funny enough it only happens on one of my Android devices (my personal). Following this thread, it looks like there wasn't a consensus on whether viewing videos from the App UI vs Browser is the right approach.

I use Frigate on top of HAOS. The combo is great, but this annoying banner is really taking away from the experience.

Any update on this would be awesome!

jhemmond avatar Aug 17 '22 02:08 jhemmond

I'm having the exact same issue. Funny enough it only happens on one of my Android devices (my personal). Following this thread, it looks like there wasn't a consensus on whether viewing videos from the App UI vs Browser is the right approach.

I use Frigate on top of HAOS. The combo is great, but this annoying banner is really taking away from the experience.

Any update on this would be awesome!

I think @dshokouhi is right, I don't like having the video open in the browser but I think that the best option (unless Frigate provides an integrated UI as part of their HACS add-on).

I've been meaning to look into how to make it so it opens in the browser but I have not had the time.

Rogue136198 avatar Aug 21 '22 15:08 Rogue136198

sorry to poke the bear, but any news on this? i have the same issue, and just stated to look around for info and solutions. i came across this thread and it is one of the only ones that actually addresses this head-on. so... any new pointers, or just "live with it" for the time being? cheers

tennbaum avatar Nov 02 '22 10:11 tennbaum

I moved to iOS and the issue is not there because Frigate elects to open video links in Safari, which does not have the issue. Wonder if Android can just have the option to open in browser, so we don't get these pesky and annoying error messages.

jhemmond avatar Nov 03 '22 18:11 jhemmond

I still intend to work on this at some point especially now that I have Frigate running in production. I just have not had the time to sit down and take a look at it.

Rogue136198 avatar Nov 03 '22 18:11 Rogue136198

I'm having this exact same issue as well. No reverse proxy or anything like that, and I also get the error when viewing both recordings and snapshots. If anyone needs debug data or triaging, I'm happy to assist!

ThinkDualBrain avatar Dec 01 '22 16:12 ThinkDualBrain

Just plain ol 192.168.1.10/local/test.html having same issue too.

spacebares avatar Dec 20 '22 20:12 spacebares

Any update on this issue, I have exact same issue with Frigate notifications.

nithikalisamy avatar Dec 29 '22 01:12 nithikalisamy

Any update on this. Getting this on Android.

superdong69 avatar Jan 03 '23 23:01 superdong69

So I looked into trying to resolve this issue over my Christmas Holiday but unfortunately I could not figure out the logic needed. If someone with more experience wants to give it a go, all theirs. I can also help if wanted.

Rogue136198 avatar Jan 04 '23 21:01 Rogue136198

Hey everyone took an attempt to fix the issue. For anyone who wants to test the fix please download the artifact from https://github.com/home-assistant/android/actions/runs/3933174642 and extract and install the debug apk. You will need to enable the persistent connection to send a test message with the video or whatever else you sent when you got the error, firebase messaging does not work in debug builds. I also recommend giving a unique name during onboarding so you can easily tell which service call to use. The debug builds are designed to be installed side by the production one and are safe to remove after testing.

If you do still encounter an issue please share the YAML of the service call so we can see what the URL looks like

dshokouhi avatar Jan 16 '23 19:01 dshokouhi

Just tested this morning and it works well.

Rogue136198 avatar Jan 17 '23 13:01 Rogue136198