This is my first contribution to home-assistan comunity with a custom component device tracker.
I am reading lots of complaining about how accurate or not is nmap or ping for device tracking.
I am been testing by myself both of them to track my iOS devices (iPhone/iPad) and these are my findings:
When a iOS device is turned on, connected to a wifi ap but not active (sleep), the device remain connected but after a few seconds it will start dropping icmp packets, not all of them but most of them.
Depending of your active services (push notification, etc) the device need to get back awake. During those short period, the device can answer icmp packets, but it will start droping them as soon as it get back to sleep. Thats why ICMP solutions (Ping, Nmap, etc) for tracking is very erratic.
The good thing is that even if the device is in a sleep state, it will still keep sending arp packets continuously (check it by your own using wireshark)
In this scenario, the arp table on the HA Server contain all the pairs ip-mac of the discovered devices, even if the iPhone is in a sleep state, his arp registry is still active on the HA Server arp table because, as I said, the iOS device is still sending arp querys to the network.
If you turn off the wifi on the iOS device, the arp registry will remain active on you HA Server during some time untill it gets deleted but you can speed up by just pinging the iOS device ip. Doing this, just keep ping-ing the IOS device ip from the HA Server, as soon as you turn off the wifi on the iOS device, the HA Server will update his arp table deleting the iOS arp registry within seconds.
Keeping all this in mind, I have create a custom tracking component that implement both ideas (ping a device + query HA Server arp table)
To use, put device_tracker.py in your /custom_components/ping_arp/ directory
Then just create a device_tracker entry on your configuration.yaml with something like this:-
device_tracker:
- platform: ping_arp
count: 5
consider_home: 600 #10 Minutes
hosts:
myIphone: 192.168.10.40
and define the level of logging to
logger:
default: info
Reboot your server and tail your home-assistant.log from a ssh session and check the ping and arp status messages for your defined host. You will see how, even if the ping is not responding, the arp record is still detected untill you turn off the wifi on the iOS device.
With this you can finally set up a presence detection based on the new entity created (device_tracker.myiphone) by the device_tracker.
Hope you find this info usefull and I apologize for my poor english (IĀ“m spanish)
Best regards.