Unable to select entities when editing a quick settings tile

Hi,

when I tap on the button to select an entity in the view to edit a quick settings tile nothing happens (except that the button flashes, so the tap is getting registered).
Any idea how to fix this?

Regards
Tobi

Any errors in the companion app logs?

None that I could find :confused:
Any tips what I should be looking for?
There’s a lot of Android UI specific stuff being logged.

if you dont see any entities loading when you select the button you should see an error in the logs (unless you don’t have a supported entity domain), feel free to reproduce the issue and share the logs and a screenshot so we can see whats going on.

Here is a list of supported domains at the bottom of this page: Android Quick Settings | Home Assistant Companion Docs

I’ve done a bit more digging, turns out I’m getting these errors regularly:

07-10 10:48:05.316 17896 18085 D UrlRepository: Using external URL
07-10 10:48:05.318 17896 18079 E WebSocketRepository: Websocket: onFailure
07-10 10:48:05.318 17896 18079 E WebSocketRepository: java.net.ProtocolException: Expected HTTP 101 response but was '403 Forbidden'
07-10 10:48:05.318 17896 18079 E WebSocketRepository: 	at okhttp3.internal.ws.RealWebSocket.checkUpgradeSuccess$okhttp(RealWebSocket.kt:224)
07-10 10:48:05.318 17896 18079 E WebSocketRepository: 	at okhttp3.internal.ws.RealWebSocket$connect$1.onResponse(RealWebSocket.kt:170)
07-10 10:48:05.318 17896 18079 E WebSocketRepository: 	at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
07-10 10:48:05.318 17896 18079 E WebSocketRepository: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
07-10 10:48:05.318 17896 18079 E WebSocketRepository: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
07-10 10:48:05.318 17896 18079 E WebSocketRepository: 	at java.lang.Thread.run(Thread.java:920)
07-10 10:48:05.318 17896 18085 E WebSocketRepository: Unable to authenticate
07-10 10:48:05.318 17896 18085 E WebSocketRepository: java.net.ProtocolException: Expected HTTP 101 response but was '403 Forbidden'
07-10 10:48:05.318 17896 18085 E WebSocketRepository: 	at okhttp3.internal.ws.RealWebSocket.checkUpgradeSuccess$okhttp(RealWebSocket.kt:224)
07-10 10:48:05.318 17896 18085 E WebSocketRepository: 	at okhttp3.internal.ws.RealWebSocket$connect$1.onResponse(RealWebSocket.kt:170)
07-10 10:48:05.318 17896 18085 E WebSocketRepository: 	at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
07-10 10:48:05.318 17896 18085 E WebSocketRepository: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
07-10 10:48:05.318 17896 18085 E WebSocketRepository: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
07-10 10:48:05.318 17896 18085 E WebSocketRepository: 	at java.lang.Thread.run(Thread.java:920)
07-10 10:48:05.319 17896 18085 E WebSocketRepository: Unable to send message {type=get_config}
07-10 10:48:05.319 17896 18085 E IntegrationRepository: Issue getting config from core.

Full log is here --------- beginning of main07-10 10:48:04.750 17896 17896 W mpanion.androi: Un - Pastebin.com
(This log is from the app within the Windows Subsystem for Android, but I’m getting the same errors on my phone)

Also, I’ve reinstalled the app on my phone and now the app crashes when I try to open the tile settings x(
Crash Log:

2022-07-10 10:48:04.660: java.lang.IllegalStateException: Reading a state that was created after the snapshot was taken or in a snapshot that has not yet been applied
	at androidx.compose.runtime.snapshots.SnapshotKt.readError(Snapshot.kt:1826)
	at androidx.compose.runtime.snapshots.SnapshotKt.current(Snapshot.kt:2070)
	at androidx.compose.runtime.SnapshotMutableStateImpl.setValue(SnapshotState.kt:299)
	at io.homeassistant.companion.android.settings.qs.ManageTilesViewModel.setSortedEntities(ManageTilesViewModel.kt:114)
	at io.homeassistant.companion.android.settings.qs.ManageTilesViewModel.access$setSortedEntities(ManageTilesViewModel.kt:28)
	at io.homeassistant.companion.android.settings.qs.ManageTilesViewModel$1.invokeSuspend(ManageTilesViewModel.kt:59)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Scopes.kt:33)
	at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
	at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
	Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@bf09d76, Dispatchers.IO]

I’ve also tried to debug the WebSocket problem a bit.
Calling the websocket connection manually (using wss:///api/websocket) seems to work fine (returns {“type”:“auth_required”,“ha_version”:“2022.7.2”}) instead of a 403.
So I suspect something with HA’s own authentication is the issue.
Is there any way to turn on more logging for the WebSocket API on the HA instance side?

Double check you are on the latest version of the app, the last crash was already fixed in the latest app update. The first error seems to be network related, do you have a proxy or anything setup? If so try to bypass it to rule out a setup issue.

The app is on the latest version (2022.6.0), however the bug still happens sometimes (and always on WSA).

I’ve also discovered that my problem seems to be indeed at least related to a setup issue.
I’m using nginx as a reverse proxy on my opnsense router to redirect calls to a subdomain from my router to my home assistant device.
When I bypass this nginx instance, the issue disappears.
However I’m reasonably certain that the calls are getting through.
I’m only seeing 101 responses in the nginx log (unfortunately I found no way to log actual websocket connections) and the home assistant log is showing this:

DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/websocket to <androidIP> (auth: False)

Nginx is configured to play nice with websocket connections (the option for it in opnsense is active and other websocket connections e.g. for the homeassistant frontend work too).

Any tip on how I could debug this further?
My only idea is to setup a development instance of homeassistant and try to debug the http integration directly to see where and why exactly it throws the 403 “Forbidden”.

see if may be this helps: Companion App Networking | Home Assistant Companion Docs

One thing to keep in mind is that HA does not support proxies on its own so it will be a bit of trial and error on your part to figure out what you need to do. At least you konw it works when you bypass your setup :slight_smile:

I finally found the culprit:
The dedicated websocket connection the app wants to establish is created via the okhttp library.
This library sends a useragent (okhttp/4.10.0) that seems to be blocked by my nginx instance -.-

For nginx running under opnSense, the solution is to go to the HTTP Server settings and activate “Disable Bot Protection” (if it’s not visible, activate advanced options).

1 Like