One of the keys to enabling a smart home is to track who is home and when they come and go, also known as presence detection. Home Assistant has a few built-in methods for doing this. For now, I’m not looking for fine-grained tracking i.e. detecting the exact moment someone enters or leaves the house. I just want to detect if someone is home or not, give or take 20 minutes, based on whether their smart phone is at home or not. Eventually I may try to get fancier with Bluetooth tracking, door sensors, iBeacons, etc., but that’s not my goal right now.
To get this started, I used the ping platform for the device tracker component along with setting static IP addresses for all smart phones used by the family in my router. Setting static IP addresses will vary by router, but you should be able to find instructions online.
Once the static IPs are set, edit the
configuration.yaml file and add the following entry using the IP address(es):
device_tracker: - platform: ping interval_seconds: 30 consider_home: 1200 hosts: josh_iphone: 192.168.0.140 stephanie_iphone: 192.168.0.141
This tells Home Assistant to track my iPhone and my wife’s iPhone using the
ping platform by checking for them every
30 seconds, and if they are not “seen” for
1200 seconds (20 minutes) then change the status to “away” for that device. I’m using 20 minutes for the
consider_home option because iPhones turn off WiFi to save battery when they are not being used, and I want to reduce the chance that Home Assistant thinks a phone is “away” when it is home but idle.
After saving the
configuration.yaml file, check the configuration and then restart Home Assistant. When it boots back up again you should see new entries at the top of the States section of the web UI:
To make that look a little better, you can edit the
known_devices.yaml file that Home Assistant created now that device tracking is enabled. I updated mine by changing the
name value and adding a
gravatar value because my wife and I both have Gravatars set up:
josh_iphone: hide_if_away: false icon: mac: name: Josh picture: track: true vendor: gravatar: email@example.com stephanie_iphone: hide_if_away: false icon: mac: name: Stephanie picture: track: true vendor: gravatar: firstname.lastname@example.org
Save the changes to
known_devices.yaml, check the config, and restart Home Assistant. Now you should see nicer names along with a Gravatar (if you have one set up):
Now I can use the home/away status in my automations. For example, I could create an automation that checks if someone is home an hour before sunset and turns on the lamp in the family room so it doesn’t get too dark in the room. If nobody is home I can leave the lamp off to save energy. We’ll see how well this presence detection method works before I try more accurate/complex solutions.
Series: Creating My Smart Home
- Making All of My Smart Home Devices Work Together with Home Assistant
- Initial Setup and Configuration of Home Assistant on a Raspberry Pi
- Control Z-Wave Devices with Home Assistant Using an Aeotec Z-Stick
- How to Fix GE Z-Wave Switches Not Updating in the Home Assistant UI
- Track Home/Away Status for Your Household Using Their Smart Phones and Home Assistant
- Add Alexa Voice Control to Home Assistant with the Emulated Hue Bridge
- Control TP-Link Smart Plug with Harmony Hub via Emulated Hue Bridge
- Add System Monitoring to Home Assistant
- Organize the Home Assistant Web UI with Groups
- Set Up Secure Remote Access for Home Assistant
- Install and Configure the Home Assistant iOS App and Enable Notifications