How to set up Home Assistant Presence Detection using NMAP
Today, I tackled Presence Detection with Home Assistant. To get the most out of your home automation, you need good presence detection. A way for the house to know if you are home or away and then react accordingly. If no one is home, you would want the system to start shutting down unnecessary lights and scaling back the HVAC. If you are home, you want everything perfect and lights coming on and off based on the sensors in the home. This all starts will reliable presence detection. For my smart home, I use the NMAP component. It is one of the oldest components in the system and I have used it from the very beginning. It does a simple scan of my network to determine all the devices connected to it and if there are new devices, it will list them in my known_devices.yaml file. It uses the MAC addresses as the unique identifier so even when IP addresses change, the system can still keep track of the particular device.
When a new device is found on my network, the system voice will announce it and I then usually do some HA configuration or Circle assignments to make sure the device can (or cannot) access the internet. Using NMAP, I then create groups to track presence within the house based on our phones. When we come to the house, our phones connect to the Wi-Fi network and then NMAP marks the device as Home. When we leave the house (with our phones), the IP addresses (and MAC) eventually drop off the network and then NMAP marks us as away. In my home, this works pretty flawlessly. There are always some things you need to tweak and change (as detailed in the video below) but otherwise it’s pretty rock solid.
I do have plans to add in a secondary Ubiquiti device tracker eventually.