Why does Location have to be enabled for the internal URL to be supported?

Hi,

I’m starting to use Home Assistant, with a view on mainly setting up a home-made alarm system. Though the activation could be manual, I’m already thinking of using phones to switch it on/off automatically. I have one big constraint though: I can’t rely on Location info being enabled on our Android phones (my wife will not agree to that, for battery and privacy reasons; it is what it is).

I’ve considered the following approaches:

  • use Wifi-based rules using the phones’ Wifi-based sensors to detect when we’re home => requires Location, out of the equation
  • use our Wifi router and PLCs to detect the phones’ presence => our router has no integration, and the PLC has one but it seems to only count the connections, not identify the devices; discarded
  • compare the public IP of the server (using the My_IP sensor) and of the phones (using the public IP sensor from the apps) => sounds great! It doesn’t require location to be on. But …

After setting that up, I realized I needed the phones to be able to communicate the public IP when out of the home network. So I set up a reverse proxy. The app is configured for my public, HTTPS address as external URL, and the local, HTTP one for internal. For added security, I set up Authelia password protection on the URLs that don’t start with /api/ (can’t do much about the /api/ ones, of course!). But that doesn’t work. As soon as I switch off location on my phone, the internal URL support becomes grayed out, and the app only attempts to connect via the public URL – which means, it has to go through Authelia, and for some reason, that doesn’t work. From that point on I can’t go back to the app at all, it keeps opening a browser and showing an error message after I log into Authelia.

Now … Why is internal URL not supported when location is off? especially when the option to “always use the internal URL first” is explained as “good if you typically leave location off” !!! I would really like to have this simple logic: location is off, but the app tries to communicate using the local address first, and if that times out, it reverts to the public one. What’s wrong with that, except for some extra delay, I suppose, as it would need to wait for the timeout every time? This has driven me half-crazy.

For now I’ve just removed Authelia entirely, so I’ll rely on Home Assistant’s own security only for the landing page, still behind HTTPS of course. But I’m not 100% happy with that state of things. In fact, I’d really like an easy way to know when my phone is home without location services and without opening Home Assistant to the outside, if there were such a way.

Cheers,
Pierric.

just a guess, but the internal URL is ofcourse available in your home, so it has to detect you are home, to be able to use the internal url?

bit weird to try to use that url when you are not even on your home network?

:stuck_out_tongue:

because android need location in order to read the SSID.

Hi,

Sorry for the delay, I didn’t get email notifications for some reason.

@DamianQuest : well, in my opinion, it should be able to try and contact the local URL, see if it fails and fall back to the public one. That’s what the switch for “always try to use the internal URL first” seems to say it will do. It’s not weird, it would be the way to ensure data is pushed no matter where one is, even if location services are disabled and wifi status is therefore impossible to know.

@dshokouhi : I’m aware of that; I understand that if location is off then accessing the SSID’s or knowing about wifi status is impossible. But I’d still want the option to default to internal URL, as mentioned above.

In any case I’m afraid I won’t be able to get very far, even with location services enabled. I’ve found that the updates from the app are sometimes pushed with a lot of delay, and often not at all. I’ve set up my phone to let the app run in the background without restrictions and to allow autostart, but when I close the app no updates reach the server anymore. It seems my phone keeps resetting the autostart setting, which is strange as it doesn’t happen on other apps. But that may be specific to Xiaomi’s OS. Android systems are such a mess. For now, I’ll have to manually enable/disable the alarm instead of relying on phone detection.

thats precisely what prioritize internal is for.

closing the app tells the app to stop working, do not close the app instead place it in the background. You are not letting it run in the background by closing it :wink:

I have a similar problem. My Android companion app allways tries to connect external when I am home (and my phone is considered home by HA) and my home has no internet access at the moment. We had an Internet connection breakdowns at home several times last month and though internal url is priorised companion app always tries to connect externally, which of course does not work, when my home is not connected to the internet. The only way to connect internal is switching off mobile data in the general settings of the phone. But of course I need mobile data when my home internet is not working. So maybe my companion app always goes externally, or it does when home is not connected to internet. Home network Wifi ssid is set correctly and the app is set to use internal ssid when it is unknown if connected to this ssid. What am I doing wrong?

I believe I have this same issue. ISP is currently down, have internal and external URLs set, Android permission for location access is “allow always”, and it appears the app is always trying to connect to the external URL, not the internal.