Detecting if the phone is connected to Wi-Fi

While geofencing in the HA Companion app is a convenient way to determine presence, I’ve often read that it can be more reliable to track whether a phone is connected to Wi-Fi. (or a combination of both)
Could you please guide me on how to configure this in HA so that it detects when my phone is connected to Wi-Fi?
I don’t know if it’s important or not, but I’m using eero 6+ mesh routers at home.
Update: I’m using iPhone

Assuming you have the companion app installed, there’s a sensor provided - you don’t need to do anything with your router.

If you go to Settings | Companion app | Manage Sensors and scroll down to Network Sensors, enabling Wi-Fi connection will give you a sensor sensor.<device>_wi_fi_connection which should contain the name of the network you’re connected to.

1 Like

If it’s an iPhone, use iphonedetect in HACS

2 Likes

If you have the mobile companion app installed, you might find sensors like “connection type” and “ssid” useful.

Personally I find presence detection based on querying a router for WiFi connections to be clunky and unreliable, particularly for phones with aggressive power saving that might appear to the router as being “away” when only asleep.

If you have an iPhone, you might want to look at a HACS integration called iPhone Detect which I have had good luck with, as it seems to work even if the phone is asleep.

2 Likes

Thank you so much, everyone! I was able to use my iPhone’s connection_type along with the HA Companion App’s GPS to set up the following automation:

alias: When both of us are away from home
mode: single
trigger:
  - platform: state
    entity_id: sensor.my_iphone_connection_type
    to: Cellular
  - platform: state
    entity_id: sensor.her_iphone_connection_type
    to: Cellular
  - platform: state
    entity_id: person.me
    to: not_home
  - platform: state
    entity_id: person.she
    to: not_home
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: sensor.my_iphone_connection_type
        state: Cellular
      - condition: state
        entity_id: sensor.her_iphone_connection_type
        state: Cellular
      - condition: state
        entity_id: person.me
        state: not_home
      - condition: state
        entity_id: person.she
        state: not_home
action:
  - service: lock.lock
    target:
      entity_id: lock.door_lock

I would appreciate your feedback on my approach and whether you consider it effective.

Next will look into " iPhone Detect for Home-Assistant" HACS.

I’ve created a template sensor like so (for each person I want to track):-

-  binary_sensor:
      - name: "X Phone on Home Wifi"
        unique_id: x_phone_at_home
        device_class: presence
        state: >-
          {% if (is_state('sensor.x_phone_wi_fi_connection','ssid1') or is_state('sensor.x_phone_wi_fi_connection','ssid2')) %}
          on
          {% else %}
          off
          {% endif %}

Basically if person X is connected to either of my wifi networks (the names for 2.4 and 5g are slightly different), it sets the template to true.

I then have a binary helper group that has these in it, so if all ‘off’ then no one is in the house, otherwise at least 1 person is home.

1 Like

Thanks @Rofo. Using the ssid sensor is indeed a better and more reliable approach for this automation. I just updated my automation to use that.

I use the ‘zones’ feature to set my home ‘away mode’ because it gives you a count of the number of people (with the companion app) inside the zone and doesn’t rely on you being connected to Wi-Fi. Quite useful if you’re in the garden or out front and/or your phone drops off Wi-Fi for any reason.

It’s been super reliable for me.

1 Like

I also use this, but I have the wifi/ ssid detection as a backup, as I’ve had issues with the accuracy of the gps from time to time, putting me outside my home zone.