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.

 

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.

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.

Start typing and press Enter to search