Tracking Phones and Other Devices

How-To Guide

Posted by Ron Mar on April 10, 2017

Recently by the same author:


Getting Started with Home Automation in 2017

How-To Guide

You may find interesting:


My Home Automation Setup 2017

Personal Setup


My Home Automation Setup 2017

Personal Setup

See how I track devices on my network and use the status in automations. Watch the YouTube video here:

There are tons of ways to track devices using Home Assistant. I’ll walk you through two and introduce you to a few more.

Table of Contents

Track Devices with Your Wireless Router

The simplest way to track devices is using your wireless router

I have a tp-link router. To use it within Home Assistant, I inserted the following code in my configuration.yaml file.

device_tracker:
  - platform: tplink
    host: YOUR_ROUTER_IP
    username: YOUR_ADMIN_USERNAME
    password: YOUR_ADMIN_PASSWORD

For more details, check out the this page on the Home Assistant site.

Here are components for other routers:

Customizations

Customize Device Tracker

Once the tracker is set up, it can be further configured with parameters to control how it discovers new devices and considers devices as “home”.

Note that these work with any device_tracker platform, but if you have multiple platforms, Home Assistant will use the parameters from the first as global settings. Find available parameters here.

Customize Known Devices

Once you discover devices, you can customize their appearance by editing the object name, friendly name, picture, and other details.

Find a list of customizations here.

Nmap

Nmap (a.k.a., Network Mapper) discovers hosts by reaching out to devices on your network.

Two steps are required to install:

  1. Install Nmap on your host device (I use a Raspberry Pi). I use the Hassbian image, which is based on Debian, so I use the following code on my Raspberry Pi: sudo apt-get install net-tools nmap
  2. Add the Nmap tracker component to Home Assistant. I added the following code to my configuration.yaml file:
device_tracker:
  - platform: nmap_tracker
    hosts: IP_ADDRESSES_TO_SCAN

I also added the parameters home_interval: 10 to limit how often nmap scans my devices and exclude: HOME_ASSISTANT_HOST_IP to prevent my Raspberry Pi from trying to scan itself, which can cause problems.

Find more details about the nmap_tracker platform here.

Other Device Tracking Methods

You can also track devices using:

Bluetooth: great if Home Assistant is already running on a Raspberry Pi with Bluetooth.

OwnTracks: Can provide specific locations outside your home using a phone GPS. Uses the MQTT protocol.

iCloud: also works with Home Assistant.

Additional methods are listed on the Home Assistant site.

Tracking Un-Networked Devices

Using current sensors, I can evaluate the status of electronics not connected to my network, for example my computer monitor and TV.

I use the following code to translate a reading of >10 Watts from my Smart Sensor to an on/off status:

binary_sensor:
  - platform: template 
    sensors:
      tv_status:
        friendly_name: 'TV Status'
        value_template: "{{ states.switch.smart_switch1.attributes.current_power_w  > 10 }}"

Find more information on template binary sensors here.

Creating Automations Using Tracked Devices

I primarily use device status to control my automations in two ways

  1. Trigger for automations - start automations
  2. Condition for automations - control when they running

Triggers are helpful when you want an automation to run when you arrive home, for example. You can also log the status with other Home Assistant components, such as IFTTT.

Conditions can be used to prevent certain automations from running when your other half is home.

I hope this article was helpful. Let me know what else you’re interested in!