Presence detection using mobile phone's reported wifi connection name?

Hi all,

I’m using the Home Assistant Android app on my mobile phone. The app is reporting my mobile’s wifi connection name to HA when I’m at home and connected to my wifi (which I am when I’m at home :p). When I’m not connected to my wifi, the app reports “not connected” (or similar).

I would like to use this as my presence detection, but I can’t figure out how - at all. When I search, I only find really contrived solutions like using MQTT, or some Bayesian detector, or other strange stuff, but surely it can’t be that hard? In my mind I should just have to (perhaps) create a new binary_sensor or something and use that?

(My motivation is that the “asuswrt” platform device tracker I have been using doesn’t work any more since I’ve been forced to start using a wifi extender, which is an older Asus thingy, which does not use asuswrt, and every time my phone jumps to the extender I’m “not_home”. The Android app “solution” that I’m thinking of does not have this problem.)

You can’t use your wifi connection as a device tracker without some workaround. MQTT is really easy, create an MQTT device tracker and create an automation that sends the payload “home” or “not_home” to the topic of the mqtt device tracker and you are done.

You could also use the device_tracker.see service or use the custustom device tracker component, which can use binary_sensors etc as input.

Precisely!, but using the template sensor

  - platform: template
        value_template: >-
          {% if states('sensor.phone_name_wifi_connection') == "WiFi_Name" %}
          {% else %}
          {% endif %}
        friendly_name: 'what_ever_u_want_to_call_it'

You should also have a device_tracker.phone_name if you allow the app to use your background gps location service, which is what I use most effectively, but like your idea, which I never thought of.


I read from lots of people that the wifi connection is a faster/more reliable indicator for presence detection with the phone than the gps location.


Agreed, except for devices drops off WiFi for some odd reason, or enter power save / low power mode, etc…

Yeah, but GPS from the phone has the same issues :slight_smile: personally I only use the GPS location when I’m away and not to detect home presence. My BLE presence detection is way more reliable and I didn’t have a single false event in the last 3 years.

:man_facepalming: Far from WiFi or GPS, but works well if coverage is adiqute due to the short range of most devices.

What you mean with far from WiFi and GPS?

[quote=“Burningstone, post:6, topic:227491”]
BLE presence detection
[/quote]I meant all very different tech

Ah okay, now I got it :slight_smile:

Our phones do not do that.
Not even during the night.
Both our phones report our home wifi connection throughout the night.
But the ping/router says the connection was lost.

Probably the app saves the wifi during the time it’s off and when it was up it reconnects before the app sees that it’s not connected.
Have a look at the stats of your phone and see what it shows.

:+1: Got it

Thank you all for your responses! Using tips from both Burningstone and Coolie1101, I managed to create a presence detector. Or, well… Reveal at the bottom :stuck_out_tongue:

First, I created a binary sensor:

- platform: template
      value_template: >-
        {{ is_state('sensor.bebos_mobile_wifi_connection', 'da_house') }}
      friendly_name: "Bebo in da house" 

and restarted to verify that it appeared in the GUI.

Second, I cloned the repo, and symlinked the composite folder to the custom_components/composite - basically, like this:

cd /var/lib/hass/
install -d src custom_components
git clone src/ha-composite-tracker
cd custom_components
ln -s ../src/ha-composite-tracker/custom_components/composite
cd -

Third, I added this device tracker to my device trackers in configuration.yaml:

  - platform: composite
    name: bebo_in_da_house 
    time_as: device_or_local
    entity_id: binary_sensor.bebo_in_da_house

and restarted for good measure.

Fourth, I made sure that the device was tracked in known_devices.yaml:

  name: Bebo in da house
  track: true

…and now I could use it for presence detection.

But, I forgot about timeouts. When I leave home, the mobile app can’t update the wifi connection - of course, and I knew that. What I missed is that there seems to be no timeout on the value, so the phone always looks connected. So back to the drawing board… Crap.

Why? When I leave the house and the phone disconnects from WiFi the sensor changes to <not connected>

Why what? Why I knew it, or why that happened? Well, maybe I didn’t know that, I’m not sure. When I started having this idea I was certain that it would flip over to <not connected>, but now when I tried it, it didn’t, and it felt very logical, so I second-guessed my certainty. However, there is one difference: when I go from home, I do not switch off wifi, I just leave the house and let it disconnect on its own. This time, to test it, I switched off wifi manually on the phone. Perhaps that’s the problem?

Why is it logical that it doesn’t change? It should change as soon as youe phone disconnects from WiFi. I assume you have setup remote acces to HA, meaning you can access HA from your phone while you are away?

Ah, thank you, now I think I know what happened :slight_smile: I have not set up remote access - well, except for when I connect over vpn. And I did that the other day, and saw the <not connected>. Then I assumed that it would always change - I guess I thought by timeout - which it didn’t.

So, now one way forward would perhaps be to have a timeout on the binary sensor state change - if that’s even possible. I’m not sure about (1) how often the app updates the wifi connection status, and (2) if it’s possible to set a timestamp on a binary sensor (or switching to some other means so that the state change would have a timestamp).

On the other hand, this “solution” kind of exploded in my face now, so perhaps I need to do something else entirely. It would be nice to be able to query my Asus EA-N66 for connected clients, but then I guess I need to concoct some scraper… And now I’m off topic. Hm, I think I’ll look into what other information the app sends and see if there is any state that changes when not connected.

I do not recommend using the router.
It will not give you good data.

But why not set up a proper remote access and you’re done.

Why bother with timeouts and all that?
As I noticed, it seems the sensors react “on demand”.
Wifi, battery state, and such is instantly updated.

1 Like

Thank you for the info, Hellis81 - yeah, I guess I’ll need to look into remote access to make this work, but I’m not that keen on exposing my server to the Internet nor having the vpn going all the time.

Hm, I see that the mobile app has this location_background sensor, with a lastAccurateLocationRequest timestamp - if that is updated periodically, I can use that. But I can’t find it in HA at all, weird.