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

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

Closed
Rogue136198 opened this issue Jul 16, 2022 · 22 comments · Fixed by #3232
Closed
Labels
bug Something isn't working webview

Comments

@Rogue136198
Copy link
Contributor

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 Unable to connect to Home Assistant #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 Rogue136198 added the bug Something isn't working label Jul 16, 2022
@dshokouhi
Copy link
Member

Duplicate of #1672

@dshokouhi dshokouhi marked this as a duplicate of #1672 Jul 16, 2022
@dshokouhi dshokouhi closed this as not planned Won't fix, can't repro, duplicate, stale Jul 16, 2022
@Rogue136198
Copy link
Contributor Author

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

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

@dshokouhi
Copy link
Member

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

@Rogue136198
Copy link
Contributor Author

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

@dshokouhi
Copy link
Member

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 dshokouhi reopened this Jul 16, 2022
@Rogue136198
Copy link
Contributor Author

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.

@dshokouhi
Copy link
Member

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:

private fun waitForConnection() {
Handler(Looper.getMainLooper()).postDelayed(
{
if (!isConnected) {
showError()
}
},
CONNECTION_DELAY
)
}

@Rogue136198
Copy link
Contributor Author

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).

@dshokouhi
Copy link
Member

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.

@jhemmond
Copy link

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!

@Rogue136198
Copy link
Contributor Author

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.

@tennbaum
Copy link

tennbaum commented Nov 2, 2022

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

@jhemmond
Copy link

jhemmond commented Nov 3, 2022

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.

@Rogue136198
Copy link
Contributor Author

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.

@ThinkDualBrain
Copy link

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!

@spacebares
Copy link

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

@nithikalisamy
Copy link

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

@superdong69
Copy link

Any update on this. Getting this on Android.

@Rogue136198
Copy link
Contributor Author

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.

@dshokouhi
Copy link
Member

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

@Rogue136198
Copy link
Contributor Author

Just tested this morning and it works well.

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.

9 participants