Using Home Assistant Device Trackers to watch the Critical Components of your Smart Home

A Smart Home contains many moving parts, and monitoring them can be a hassle. When one of those moving parts stops, your Smart Home can quickly become a Dumb Home.

 

Identifying The Moving Parts

Let’s take a quick look at the Smart Home. How many moving parts do we have? Here’s some of the gadgets I’m using to make my own home smarter.

See the Smart Home Devices I use

I’ve created a Kit where you can see all the Smart Home Devices I use to automate my life.

Checkout My Kit

Straight away we can see some potential pain points. If the Philips Hue or LimitlessLED hubs go offline, lighting in our house stops working.

If the Vera Lite goes down, our Z-wave network stops working. Which can stop our Heating and Cooling automations, secondary lighting, and motion sensors.

On the less critical side of things, the Harmony Remote Control and Sonos speakers are an integral part of our entertainment system. If either of those stop working, then watching TV can turn into a complex process  very quickly.

 

Benefits of Monitoring Smart Devices

The last thing you want to be doing is troubleshooting why a light isn’t turning on, or trying to get the TV working before a live broadcast is about to begin.

By monitoring our smart devices, we can have a constant health check running against our Smart Home. The moment an issue arrives, such as a hub updating its software and not turning back on, we can be alerted to fix the problem straight away.

Hot Tip

This is a great opportunity to think about contingencies for your Smart Home when something goes wrong. I have a couple of LimitlessLED/MiLight Remote controls in a box ready, just incase the lights don’t turn on automatically.

 

Monitoring Smart Devices with Home Assistant

As with everything, there’s multiple ways to monitor things with Home Assistant. One of the easiest is to use one of the many types of Device Trackers / Presence Detection components. You can also mix-and-match of your choice, depending on what the device you’re trying to track needs. For example you could use Bluetooth and the NMAP Device Trackers to detect the Harmony Elite, as that device uses WiFi and Bluetooth.

When Home Assistant detects a device, it will mark it as “Home” in Home Assistant. If the device disconnects from the network, or can’t be seen by Bluetooth anymore, we can assume there is an issue with the device when it gets marked as “Not Home”.

 

Getting Your Network Ready

Before we start trying to track our devices with Home Assistant, we should first setup our home network so that we can track them effectively. If you’re planning on using something like the Ping Device Tracker, it might be good to setup a static IP address for each device you want to track.

 

Setting Up Home Assistant Devices

My preferred method is networking tracking. I have an ASUS router, so I am using the ASUS Home Assistant component, which will report any devices connected on my network as “home”. If the device disconnects from my network, it will be marked as “Not Home”.

Once you enable a Device Tracker, it will be added to your known_devices.yaml file. You can add a picture, icon and a name for it. For my Harmony Hub, I can see it in my known_devices.yaml as the following.

Using the information above, Home Assistant will add a new entity called device_tracker.harmonyhub. We can use this in a Home Assistant group to add it to the Home Assistant UI if we need.

 

The Latest In Your Inbox

Enter your email address below to receive my latest blog posts and videos about Home Automation in your Inbox

 

Using Template Sensors For Better Status Reports

By default the Device Trackers will report the devices as “Home” or “Not Home”. However, for what we’re trying to do here, this doesn’t make much sense.

We can use a Template Sensor to change the status of the device on the front-end. I’ve chosen to use the state “Offline” and “Online”, but you may choose to use anything you want, like “up” and “down”, “ok” and “issue” etc.

Here’s a template sensor for our Harmony Hub status. When the device is marked as “Home”, the Home Assistant front-end will say “Online”. For good measure (and to stop Home Assistant errors when we start Home Assistant for the first time) I’m using an if check to make sure the device has been initialized. If it hasn’t, Home Assistant will display “Unknown”.

Now that we’ve added that template sensor, Home Assistant will add a new entity called  sensor.harmony_online  which we can use. Let’s use customize to add an icon for good measure.

Here’s how it looks in Home Assistant.

 

Adding Alerts with the Alert Component

So now Home Assistant is monitoring our Harmony Hub. So what happens when something goes wrong? We can use Home Assistant’s Alert Component. The Alert Component will send repeating reminders and allow alerts to be snoozed/acknowledged in the front end.

Let’s go ahead and create an alert we can use in configuration.yaml

This will send an alert to my phone after a device has been marked as Offline for 15 minutes. This is because I have set the skip_first: true  flag.

That’s pretty easy, but what happens when we start tracking multiple devices? Let’s assume I want to start tracking my Philips Hue Hub. If that goes offline, the above alert wouldn’t be triggered.

We now have a couple of options. We can add another Alert component for each new device we want to track. For that we would just copy-and-paste the code above and change it for the Hue Hub entity. Another option is to make the alert more generic, and add another template sensor which we can use to monitor both devices.

First, let’s add a new template sensor that will change to “on” when either the Harmony Hub or Philips Hue Bridge go offline.

Now we can update the alert to look at that sensor instead.

Now if either of the Hue Hub or Harmony Hub go offline, this alert will be triggered.

 

Sending Alerts with the Notification Component

One of the things I don’t like about the Alert Component is that it requires an additional binary sensor to be setup to trigger the alert for multiple devices. Once the alert component has been triggered, the device that has an issue and raised the alert can’t be seen in the alert. All you can tell is that one of your devices has an issue.

This is where I prefer to use a plain old automation which sends a notification from a template.

Continuing on our example with the Hue Hub added in, let’s setup an automation which will send me an alert when either device is marked as offline.

That will send an alert to my phone when either the Harmony or Hue Hub goes offline. Thanks to the template condition, it will only send me the alert if it hasn’t been triggered in the previous hour.

However the message that is sent to my phone is still generic. Let’s jazz it up a bit with some templating.

Using the trigger entity, we’ll be able to send the name of the device that is causing issues. Here is an example of a message which might be sent to me.

Harmony Hub has gone offline. Please check the status of this device as some features may stop functioning.

Taking this approach, there’s only one automation that needs to be updated when I add a new device I need to monitor.

 

Getting Smart – Disabling Automations On Device State

Now that we know what the state of our hubs are, we could even get a bit smarter. If your Hue Hub is offline, and your automation tries to turn on/off a Hue Light, your log files are going to grow. We can now tell Home Assistant not to fire an automation unless the Hue Hub is online by adding the following condition to our automations.

If the Hue Hub is not online, any automation with that condition won’t be fired.

You could also get a bit smarter, by adding your automations that use Hue to a group, and then disabling all automations in that group when the Hue hub goes offline. To do that, you could do something like this:

Of course, disabling automations when a Hub is offline is completely optional, and may not be the best idea in all situations.

 

Wrapping Up

By using Device Trackers, we’re now monitoring various moving parts of our Smart Home. You can easily expand on the examples I’ve given here to track virtually all Smart Home devices that can have their presence seen in Home Assistant. You can then have Home Assistant alert you when something isn’t right. Once you’ve been alerted, you can take action before a family war breaks out, or your Smart Home makes you look like a fool.

There may be times where you may need to get a little more complex. One of those I’ve had to deal with I’ll cover in a future post. Until then, happy automating.

Buy me a hot chocolateBuy me a hot chocolate
Recommended Posts
  • PuckStar32

    thanks for this nice guide. I had to change 1 thing otherwise it wouldn’t work:

    - platform: template
    sensors:
    monitoring_sonoff1:
    value_template: "{% if 'states.device_tracker.5ccf7fa792a6' %}
    {% if is_state('device_tracker.5ccf7fa792a6', 'home') %}
    Online
    {% else %}
    Offline
    {% endif %}
    {% else %}
    Unknown
    {% endif %}"
    friendly_name: 'Sonoff 1'

    I had to put quotes around the first: states.device_tracker.5ccf7fa792a6
    otherwise I got errors. Probably because it has numbers in it.

    Also I added an automation to notify me when a device comes back online again.

  • Adam Michael Rochford

    Very great article for those getting started with home automation. Many of us learned the hard way (myself included) that automating your home and daily routine is useless if the 1% of time that it fails it doesn’t do so gracefully (with the respective manual controls in place). There is an art to building robust automations that accommodate others.

  • Ced

    Here is what I came up with:

    tplink_modem:
    friendly_name: “TP-Link Modem”
    value_template: >-
    {% if is_state(‘device_tracker.tplink_modem’, ‘home’) %}
    Online
    {% else %}
    Offline
    {% endif %}
    icon_template: >-
    {% if is_state(‘device_tracker.tplink_modem’, ‘home’) %}
    mdi:lan-connect
    {% else %}
    mdi:lan-disconnect
    {% endif %}

    I like the way the icons change according to the state and not having to make a call to the customize.yaml file…

    Hope this can help some!

  • Ced

    By the way, does anyone know a way that I could add the IP address of devices under the friendly_name in the ui. Ideally, this would be done dynamically, but all my devices are set on reserved IPs so a manual input would work too.
    Here is how I would like it to look:
    TP-Link Modem Online
    192.168.1.1 Uptime

    • Check out this GitHub repo, seems to have what you’re asking for

      https://github.com/maattdiy/home-assistant-config

      I actually tried to do the same thing this weekend. Installed this repo: https://github.com/andrey-git/home-assistant-custom-ui

      However couldn’t get any of the UI elements to work for me. If you manage to get them to work, would love to hear how easy it was for you.

      • Ced

        That’s a nice config right there! Cheers for sharing…
        I was thinking of just adding SNMP sensors with friendly name as IP address under each sensors. If I do this for every device, that will be a lot of new sensors, though!

  • Ruel Baclay

    I know I’m a bit late, but still, thank you very much for sharing this sir. This is what my setup looks like. https://uploads.disquscdn.com/images/3f7a79b619aca826da0798168fd780becd141efc101c33a42ddf66d8ae33b78a.png

    • Looking sexy!

    • Shah Imran

      Any documentation for this? Thanks

      • Ruel Baclay

        I just followed Phil’s guide above…

  • eran cantor

    Hello Phil! I had been using this solution for about a year now and it was working wonderfully to monitor all my core devices in Home assistant. Now that known_devies has been deprecated home assistant is no longer automatically creating the ‘device_tracker’ entities based on the known_devices.yaml file. Is there a simple work around to continue using this solution? Thanks so much for all your help.

    • Hi Eran,

      Great question. I might need think about doing an updated version of this article with more up-to-date info.

      Although known_devices doesn’t exist anymore, the device trackers should still be created. Depending on what type of method you’re using to get the devices.

      What method are you using to check the status of devices? Ping? Router etc?

      • eran cantor

        Thanks so much for the quick response Phil!

        Right now i am using nmap doing a simple ping sweep of my LAN. I have found that more reliable than some of the fancier integration with my WiFi controller or router.

        Thanks again.

Start typing and press Enter to search