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.

known_devices.yaml

YAML

1

2

3

4

5

6

7

8

9

harmonyhub:

hide_if_away: false

mac: XX;XX;XX;XX:XX;XX

name: HarmonyHub

picture:

track: true

vendor: Slim Devices,Inc.

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”.

configuration.yaml

YAML

1

2

3

4

5

6

7

8

9

10

11

12

13

harmony_online:

value_template: "{%ifstates.device_tracker.harmonyhub%}

{%ifis_state('device_tracker.harmonyhub','home')%}

Online

{%else%}

Offline

{%endif%}

{%else%}

Unknown

{%endif%}"

friendly_name: 'Harmony Hub'

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.

customize.yaml

YAML

1

2

3

4

sensor.harmony_online:

icon: mdi:remote

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

configuration.yaml

YAML

1

2

3

4

5

6

7

8

9

10

11

12

alert:

harmony_critical:

name: Harmony Hub is critical

entity_id: sensor.harmonyhub

state: Offline

repeat: 15

can_acknowledge: True

skip_first: True

notifiers:

-phil

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 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.

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.

automation.yaml

YAML

1

2

3

4

5

condition: state

entity_id: sensor.hue_hub_online

state: Online

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:

groups.yaml

YAML

1

2

3

4

5

6

7

8

9

hue_automations:

name: Hue Automations

entities:

-automation.living_room_hue_on

-automation.living_room_hue_off

-automation.bed_room_hue_on

-automation.bed_room_hue_on

automation.yaml

YAML

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

- alias: Disable Hue Automations

trigger:

- platform: state

entity_id: sensor.hue_hub_online

from: 'Online'

to: 'Offline'

action:

- service: automation.turn_off

entity_id: group.hue_automations

- alias: Enable Hue Automations

trigger:

- platform: state

entity_id: sensor.hue_hub_online

from: 'Offline'

to: 'Online'

action:

- service: automation.turn_on

entity_id: group.hue_automations

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.

Using Home Assistant Device Trackers to watch the Critical Components of your Smart Home2017-06-172017-08-01https://philhawthorne.com/wp-content/uploads/2015/12/philhawthorne_black.pngPhil Hawthornehttps://philhawthorne.com/wp-content/uploads/2017/06/observation-1459105.jpg200px200px