Track Home/Away Status for Your Household Using Their Smart Phones and Home Assistant

This entry is part 5 of 11 in the series Creating My Smart Home.

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:

Once device tracking is enabled, Home Assistant will display the home/away status of each device that is tracked.

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: josh_email_address@example.com

stephanie_iphone:
  hide_if_away: false
  icon:
  mac:
  name: Stephanie
  picture:
  track: true
  vendor:
  gravatar: stephanie_email_address@example.com

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):

Changing the name and adding an image can make the home/away tracking look much nicer.

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.

2 thoughts on “Track Home/Away Status for Your Household Using Their Smart Phones and Home Assistant

  1. Thanks for your post. You have done exactly what I am trying to do, except I have no success. My first attempt is to use PING to see if HA can detect the devices. What I’m using to test is HA is Ubuntu running as a virtual PC. I can use it to ping the addresses myself, but HA does not a generate known_device.yaml, any help would be greatly appreciated. See my configuration snippet below.

    device_tracker:
    – platform: ping
    interval_seconds: 20
    consider_home: 600
    hosts:
    brother_printer: 192.168.100.60
    my_pc: 192.168.100.112

Leave a Reply

Your email address will not be published. Required fields are marked *