[UPDATED] iPhone WiFi Presence Sensor

https://github.com/joelwetzel/Hubitat-iPhone-Presence-Sensor

iPhone WiFi Presence Sensor for Hubitat

A virtual presence sensor for Hubitat that checks if an iPhone is on the WiFi network.

Note: iPhones can put their WiFi to sleep, so you should not use this as your only way of detecting presence. However, it can be used to augment other presence sensors. Interpret results this way:

  • If this sensor shows "present", the iPhone is DEFINITELY present.
  • If this sensor shows "not present", the iPhone may or may not be present. We don't know.

Compatibility

I only have iPhone devices to test with, but other users have reported it working with the following Android devices. I cannot provide support for Android myself though.

  • Nexus 5x
  • Pixel XL
  • Pixel XL2
  • Pixel 3XL
  • S9
  • S8+
  • S3
  • Nokia 6
  • Note 9
  • MotoX4
  • Moto Z2play
  • Amazon Fire 7 tablet (2019)

Installation

IMPORTANT: If you update to iOS 14, by default it has a feature that randomizes your IP address. This will break this presence sensor. To fix this:

  • Go into your Wifi settings
  • Choose the settings for your home network
  • Turn OFF the "Private Address" feature

The best way to install this code is by using Hubitat Package Manager and then skipping to step 6 after installing the package.

However, if you need to install manually:

  1. Open your Hubitat web page
  2. Go to the "Drivers Code" page
  3. Click "+ New Driver"
  4. Paste in the contents of iPhoneWiFiPresenceSensor.groovy
  5. Click "Save"
  6. Go to the "Devices" page
  7. Click "+ Add Virtual Device"
  8. Set "Device Name" and "Device Network Id" to anything you like. Set "Type" to "iPhone Wifi Presence Sensor".
  9. Click "Save Device"
  10. On the device list, click the name of your new sensor
  11. Set "IP Address" to the local static IP address of the iPhone.
  12. Click "Save Preferences"
29 Likes

Just curious .... what makes this specific to iPhones? It looks like it checks for a device's (specific IP) connection to the WiFi network. Is there some reason this would not work for an Android phone .... or a laptop .... or any other mobile WiFi device? Unless the responses expected are iPhone specific ... I thought this may work any mobile WiFi device with a static (or permanent DHCP lease) IP. I'll try that out when I get home ... but thought I would ask first.

Thanks.

[UPDATE] I just saw your other post:

I think that will do what I was thinking about and this one may be specific to iPhone?

Yeah this is specific to the HTTP response codes and statuses that the iPhone returns. Other devices such as Android phones MAY return the same responses. But I don't have one to test.

The other device handler tries to do an HTTP GET and looks for a status code 200.

It worked on my Nexus 5x. It showed present when i was connected to my wifi. Then I turned my phone off and it showed not present.

Excellent!

Confirmed, working on Android Pixel XL too.

1 Like

My S9 works and looks like my wifes nokia 6 does as well!

Do you just put the ip of an Android phone?

Yes. Worked on my Note 9 too.

The iPhone version

Seems to work with an iPhone Xs Max and a Samsung Galaxy S8+. Both show ONLINE when they are active and go OFFLINE soon after any phone activity stops.

I have to think about any use for this? As you stated ONLINE is definitely present, but OFFLINE really doesn't provide any useful information (it might be present, or it might not be).

It's interesting that the phones are behaving differently. I've been watching mine all day (it's an iPhone SE if that matters) and the presence sensor only goes OFFLINE if I turn on airplane mode or leave the house. I wonder if I have a ton of apps constantly requesting updates, so it's just never going to sleep. Hard to know.

What I've done with this is basically make composite presence. I have this as a presence sensor, and I use the Alexa app as another presence sensor. Then if either of those are present, I have rules that set a "combined virtual sensor" to present. That way if Alexa doesn't detect my arrival fast enough when I drive up to the house, the phone will at least connect to wifi when I get in the driveway.

It could be something to do with “location services” you have enabled more than just the apps themselves.

Do have the location services toggle switched to on and any app set to “always”? I’ve noticed that it seems to keep the phone more active even if it locked.

Yes, I do have "Always" for some apps, such as Alexa.

I can’t be certain, but I think this and possibly “background data” are the two biggest things that keep an iPhone from sleeping. But I’m no expert.

My assumption is that if you have “location services” on that it won’t let the phone sleep completely if something is set to “Always”.

Who doesn’t have at least one app with always on? For 99% of end-users this will work without ANY device prep. Meaning once the device hits your network, you have a reserve IP and then can create a presence device for that phone. This is a HUGE benefit especially if you want to do something cool for guests who are staying longer than anticipated and can modify rules and routines simply based on if those guests are present at your home.

THANK YOU @jwetzel1492 for creating this! You have solved the last puzzle for Presence for me. Now be careful as the HE team may permanently borrow this for additional presence capabilities like they have with @Cobra’s many app contributions. :stuck_out_tongue_winking_eye:

2 Likes

Great app! But now that it works with Android phones too I would like to formally ask that you change the name! :grin::grin:

Also, one other small request. Please add a switch to turn off the logging.

Thanks

3 Likes

I have a Huawei (android) but it does not appear to be working.
Can the android users out there confirm how they configured the device.
Is it just the ip address. 192.168.0.xx?
I've tried various combinations with no joy.