[UPDATED] iPhone WiFi Presence Sensor

I've got the family's Android Pixel phones reporting via the Hubitat app, Alexa presence, and Owntracks, and I wanted to see if I could throw the "iPhone" WiFi Presence Sensor into the mix to generate Combined Presence.

The main issue I ran into during setup was assigning a static IP to each phone in our router. It's not an impossibility, but we use a block of static IP addresses on our LAN for other reasons and a mobile device that comes and goes wouldn't play so well being assigned that way.

My first thought was to use the phone's unique and static ipv6 address instead of a static ipv4 address, passing it as a string in square brackets - but that just resulted in an error from asynchttpGet in the logs:

debug Steve's Pixel WiFi: httpGetCallback({"headers":null,"warningMessages":[],"status":408,"errorMessage":"Connect to [fe80::6435:9b15:9ad8:4b0d]:80 [/fe80:0:0:0:6435:9b15:9ad8:4b0d] failed: Invalid argument (connect failed)","errorData":null}, data)

Should an ipv6 address enclosed in square brackets qualify as a valid URI for asynchhttpGet and similar Http calls? I only drilled down as far as the java.net.URI class, whose methods seem to accomodate ipv6 addresses in this format. I have tried entering the address with and without square brackets, and with and without compressed sections of 0000 blocks.

So where is the fail occurring when trying to register ipv6 addresses for our mobile phones in "iPhone" WiFi Presence Sensor ?

I'm not the author, but I looked at the code itself. It needs an actual browser useable IP address, because it is trying to contact the phone using http and then looking for a "connection refused" message. Since an alphanumeric mac address cannot be used in a browser, it cannot be used in this presence sensor.

	asynchttpGet("httpGetCallback", [
		uri: "http://${ipAddress}/",
        timeout: 10
	]);

Not sure what router you use. I'm running an Eero mesh, and it has worked well for several years to assign IP reservations to our phones. The phones still request IP from the routers DHCP, but the Eero always assigns them the same one.

1 Like

The only hiccup I could see is if they were allowing the phones to use random MAC's. You have to toggle off Private Address so that it will use the same MAC everytime it connects to that network.

Yes, this is necessary.

1 Like

Where do you get the contents of iPhoneWiFiPresenceSensor.groovy? I tried going on GitHub, but no matter what I search for, I keep getting "Your search did not match any packages." Also, there is no option for "Virtual Device" under the Device type. I selected Virtual switch.

The link is in the first post of this thread. A more direct link to the Groovy code is Hubitat-iPhone-Presence-Sensor/iphoneWiFiPresenceSensor.groovy at master · joelwetzel/Hubitat-iPhone-Presence-Sensor · GitHub.

2 Likes

Thanks. I completely missed that on first read. My link color was set to yellow and it just washed out. Great driver!!