By implementing presence detection in Home Assistant, you will be able to get many fun opportunities. For example, you can get a nice welcome message on the speaker when you get home, and the lights are turned on automatically.
There are several ways to track your mobile phone, this is described in a previous post.
One of the possibilities to check whether you are home or not is to check if your mobile phone is connected to the home network.
Home Assistant has an option to use Nmap Tracker. Home Assistant will then send a “ping” to the IP address that you set up, and as long as we get a response so the phone is present. As soon as you disconnect it from the home network, it will be marked as gone.
Example setup
# Example configuration.yaml for Nmap
device_tracker:
- platform: nmap_tracker
hosts:
- 10.0.0.2
- 10.0.0.15
home_interval: 10
The challenge of using Nmap Tracker is that what the note on the page says
Keep in mind that modern smartphones will usually turn off WiFi when inactive. Simple trackers like this may not be reliable on their own.
In reality, Wifi is not turned off, but the phone goes into “deep sleep” mode. So we need to “wake up” the phone for it to respond to ping.
The solution to the challenge, for the iPhone, is to install an integration called “iPhone Device Tracker“. As it is written on the integration page of the developer:
This integration sends a message to the defined hosts on UDP port 5353.
The iPhone responds, even when in deep sleep, and an entry in the ARP cache is made .
The installation itself is made very easy with HACS, and the setup is a few simple lines in configuration.yaml afterward.
Example configuration
device_tracker:
- platform: iphonedetect
consider_home: 60
scan_interval: 12
new_device_defaults:
track_new_devices: true
hosts:
hostname1: 192.168.0.17
hostname2: 192.168.0.24
The example above creates two entities in Home Assistant when they are detected on the home network for the first time device_tracker.hostname1 and device_tracker.hostname2
Furthermore, you can then make automation that says that when “hostname1” is no longer online, you should turn off the lights, or adjust the heat in one room.
Why not create automation that plays “Imperial March” when you get home.
Thank you for your articles, they ‘re full of usefull information! Having said that, is there a similar solution- integration for android phones?
Since I have iPhones, I have not checked. But you might use the wifi to control whether the device is on the network.