Like many of us I’ve struggled with using nmap & other network scanners to track iPhones/iPads because if they sit on the charger for a while they go to sleep and drop off the network, appearing “away”. Then I realized that the built-in iOS geofencing retains appropriate home status and can be automated so that HA knows what it knows. Note that this won’t give you location tracking on a map, but for those folks in your home that don’t want the companion app on their phone or tracking via custom components like iCloud3, this is an easy workaround so that HA at least knows if they are home or away. So far in my testing I haven’t had any false “away” statuses.
Prerequisites: a Homekit hub; iDevices logged into Home
Steps:
Create a virtual switch and publish it to homekit in configuration.yaml.
Restart HA & wait for the switch to show up in the Home app. Automate the switch to turn on/off when the person comes/goes in iOS. HA will see these changes.
Enter a dummy entry in known_devices
dummy:
name: dummy tracker
mac: <enter fake mac not on your network>
icon:
picture:
track: true
Set up automations in HA using device_tracker.see to establish whether the dummy tracker is home based on the virtual switch. The time_pattern trigger is probably unnecessary and just there for redundancy (and thus the conditions).
- id: id 29.1
alias: "xxx home per homekit"
trigger:
- platform: time_pattern
minutes: "*"
- platform: state
entity_id: switch.vs_tracker
from: "off"
to: "on"
condition:
- condition: state
entity_id: switch.vs_tracker
state: "on"
action:
- service: device_tracker.see
data:
dev_id: dummy
location_name: "home"
- id: id 29.2
alias: "xxx gone per homekit"
trigger:
- platform: time_pattern
minutes: "*"
- platform: state
entity_id: switch.vs_tracker
to: "off"
condition:
- condition: state
entity_id: switch.vs_tracker
state: "off"
action:
- service: device_tracker.see
data:
dev_id: dummy
location_name: "not_home"
Tie the person of interest to the dummy device_tracker in the HA UI (configuration -> people).
Build coming & going automations to use person.<whoever> and enjoy!
The first set being the home/away data feed from my router, and the 2nd data set being from mudape/iphonedetect, over last 8 hours or so. I’ll call it a tie.
Is anyone seeing the same?
I am interested in fmon’s project above. And it would definitely help if someone could elaborate a bit further - how does the geofencing work exactly? I’m not sure I understand the automation. Also is there any limitation we should be aware of?
I have no idea… my thought was to leverage whatever secret sauce Apple already has baked into iPhones such that HA can automate off where the iPhone thinks it is. I can tell you that it works flawlessly. It’s also quite handy if you have a household member who
A) leaves the WiFi off on their phone (in which case iphonedetect won’t work) and
B) won’t allow the HA companion app on their phone
Also as above perhaps you don’t want constant pinging by a custom component to drain all your iBatteries.
The only limitation is that the person of interest has to be willing to allow location tracking by HomeKit.
As far as how the automations work, you’re creating a virtual switch in HA and then by adding it to homekit: in your config, it will show up in the Home app, where you can automate it to turn on or off based on the person coming/going. HA will be able to see the virtual switch change state and you automate off of that the same way you would a motion detector or something. So:
iPhone comes home → Homekit turns virtual switch on → HA sees this and sets dummy device tracker to home → person tied to device tracker is home → automations happen based on the person state change
You could simplify that a bit by automating off of the device tracker, but I chose to tie everything back to the person
There’s also now this “private address” setting on iPhones that scrambles the WiFi radio’s MAC and I don’t know if that may interfere w/ custom components that rely on identifying the MAC to determine presence on a LAN; with the method I’ve described it won’t affect tracking.
In the end I am using input_boolean, instead of a virtual template switch.
(Reference: HomeKit as a Presence Sensor)
And the home app (the one from Apple) would still recognize the boolean as a switch just fine, via Home Assistant’s homekit integration.
I’m now seeing “no response” from time to time in the home app, but that’s a different subject, I suppose.