Switch between nabucasa and local doesn't happen

My desire is to get seamless switching between nabucasa and the local URL without any additional user intervention. When I move from my home network into the world and back the app never automatically switches the URL being utilized. Once I get a successful connection to either the external or internal URL it seems to be good until I need to switch between the URLs. To get the nabucasa connection to work I have to disable “Prioritize Internal URL” in the companion app. To get the local connection to work I have to enable “Prioritize Internal URL”. This works when switching from between the URLs but not 100% of the time. Sometimes when I’m in the process of switching remote and local access I get the following error in my homeassistant.log error:

2022-01-20 16:40:44 WARNING (MainThread) [homeassistant.components.http.ban] Login attempt or request with invalid authentication from 192.168.10.60 (192.168.10.60). (HomeAssistant/Android Pixel 5a 2022.1.1-full)

It seems like closing the app help with getting a connection after the home/not_home switch happens. That is after I change the state of “Prioritize Internal URL”.

I’m using a simple ping tracker to tell if I’m on the local network or not. When it indicates I’m home I use an automation to disable nabucasa. When it indicates I’m not_home I use an automation to enable the nabucasa connection. For testing I simple enable and disable the wifi on the phone and the ping tracker detects home and not_home.

Prior to bring nabucasa into the picture, I had HA set up for some time using duckdns to support https and the associated cert. Remote access was really just local access via openvpn. I just introduced nabucasa into the mix.

Am I correct that the app is supposed to allow seamless transition between home and away, with switching between nabucasa and the local URL? Any thoughts on how I fix the authentication error? Finally any suggestion on how to get a seamless transition between home and away?

UPDATE: In the HA GUI under the users profile I deleted all refresh tokens. I then reinstalled the app on my phone. It’s only been about 20 minutes of testing with 6 switches between home and away, but it now seems to be working. I’m not sure how it got in the strange condition and hopefully it things will not fall back into the same state in the future.

Yes so once you define your Home Wifi SSID the app will use the internal URL, the app can only read the connected Wifi SSID if location permissions are not only granted but also enabled on the device. If you turn off location frequently on your device then you want to use Prioritize Internal, otherwise it will behave oddly.

it happens, sometimes data just gets corrupted which is why we have these steps: Troubleshooting | Home Assistant Companion Docs

I have a question related to this. Is there a way to actually see which connection is being used by the companion app? (android in my case) I have a similar setup as OP, so nabu casa for outdoors and local connection for home. But how can I make sure the correct connection is being used in the correct place?
Thanks for any help!

the companion app logs will print when either URL is being used

Yes that would be my guess, but when I’m switching between wifi and mobile connection, nothing shows up in the logs. The app does reconnect and everything works fine, but no new entries in the logs. Is there something I need to turn on maybe?

Edit:
My bad, I was waiting for something to show up in HA logs, until I re-read you message. Indeed, the connection shows up in the companion app logs :+1: