Why does WiFi connection sensor require Location?

Why does the “WiFi connection” sensor in Home Assistant Companion app for Android require Location service to be enabled on the phone ? If location is disabled, the sensor in HA ( sensor.phonename_wifi_connection) reports “unknown” and the moment I enable location on the phone it will correctly report the name of my home WiFi network.

When first trying to enable this sensor in the Home Assistant Companion app settings (Location turned off), I get this message:

Location is disabled

The location is disabled. The following enabled option(s) require you to enable location. If you do not enable the location, the sensor(s)/setting(s) will not work!

  • WiFi Connection

This doesn’t make sense to me. Seemingly the two shouldn’t be related.

I’m playing around with different ways to do presence detection and checking for the WiFi name seems like a good idea. My WiFi is stable and while home my phone is always connected. But I don’t like to keep the location service turned on (slight battery drain), unless I’m using Maps for navigation etc.

The generic router provided by the ISP doesn’t integrate with HA so I can’t use that to check if my phone is connected to the WiFi.

It’s an Android thing. Several Wifi related API calls, like listing available SSIDs, need location permissions because access to this information allows an app to more or less precisely locate the device using Wifi SSID fingerprinting (see Google’s Wifi location service). I don’t know which Wifi services the HA companion app uses exactly, but a lot of them (maybe all ?) do require location permissions by design.

From the Android SDK docs:

A successful call to WifiManager.startScan() requires all of the following conditions to be met:

 *  Your app has the ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission.
 *  Your app has the CHANGE_WIFI_STATE permission.
 *  Location services are enabled on the device (under Settings > Location).

See here for more details.

2 Likes

Yup it’s a Google requirement.

1 Like

Google is using wifi ssid information to find out location of user and sharing wifi ssid information might be used to find out location.

When i moved my previous to new home, i had used same ssid name with a new router and google thought that i am in old home address.

1 Like

Thanks everyone for the answers, that explains it :slight_smile:
Guess I’ll have to find another solution for presence detection or start keeping Location enabled on the phone.

I don’t know if you have tried it, but the simple easy way is to use a ping sensor. Cons is it is slow to detect.

Yep, that was my next plan, set static IP for the phone, use ping and set scan_interval to something like 30sec or 1min. Will test it and see how it goes. For now it doesn’t need to be fast but in the future may need another solution