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.

known_devices.yaml harmonyhub: hide_if_away: false mac: XX;XX;XX;XX:XX;XX name: HarmonyHub picture: track: true vendor: Slim Devices, Inc. 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.

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

configuration.yaml harmony_online: value_template: "{% if states.device_tracker.harmonyhub %} {% if is_state('device_tracker.harmonyhub', 'home') %} Online {% else %} Offline {% endif %} {% else %} Unknown {% endif %}" friendly_name: 'Harmony Hub' 1 2 3 4 5 6 7 8 9 10 11 12 13 harmony _ online : value _ template : " { % if states . device _ tracker . harmonyhub % } { % if is _ 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 sensor.harmony_online: icon: mdi:remote 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 alert: harmony_critical: name: Harmony Hub is critical entity_id: sensor.harmonyhub state: Offline repeat: 15 can_acknowledge: True skip_first: True notifiers: - phil 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.

configuration.yaml binary_sensor: - platform: template sensors: device_critical: value_template: '{{ states.sensor.harmony_online = "Offline" or states.sensor.hue_online = "Offline" }}' friendly_name: 'Device Critical' 1 2 3 4 5 6 7 8 binary _ sensor : - platform : template sensors : device _ critical : value _ template : ' { { states . sensor . harmony _ online = "Offline" or states . sensor . hue _ online = "Offline" } } ' friendly_name: ' Device Critical'

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

configuration.yaml alert: device_critical: name: A device is critical entity_id: sensor.device_critical state: 'on' repeat: 15 can_acknowledge: True skip_first: True notifiers: - phil 1 2 3 4 5 6 7 8 9 10 11 12 alert : device _ critical : name : A device is critical entity _ id : sensor.device_critical state : 'on' repeat : 15 can _ acknowledge : True skip _ first : True notifiers : - phil

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.

automation.yaml - alias: Alert when a critical device goes offline trigger: - platform: state entity_id: sensor.hue_hub_online, sensor.harmony_online from: 'Online' to: 'Offline' for: minutes: 2 condition: condition: and conditions: - condition: template value_template: > {% if states.automation.alert_when_a_critical_device_goes_offline.last_triggered is not none %} {% if as_timestamp(now()) | int - as_timestamp(states.automation.alert_when_a_critical_device_goes_offline.attributes.last_triggered) | int > 3600 %} true {% else %} false {% endif %} {% else %} false {% endif %} action: - service: notify.phil data: message: 'A device is offline. Please check Home Assistant' title: Device Alert 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 - alias : Alert when a critical device goes offline trigger : - platform : state entity _ id : sensor.hue_hub_online , sensor . harmony _ online from : 'Online' to : 'Offline' for : minutes : 2 condition : condition : and conditions : - condition : template value _ template : > { % if states . automation . alert _ when _ a _ critical _ device _ goes _ offline . last _ triggered is not none % } { % if as _ timestamp ( now ( ) ) | int - as _ timestamp ( states . automation . alert _ when _ a _ critical _ device _ goes _ offline . attributes . last _ triggered ) | int > 3600 % } true { % else % } false { % endif % } { % else % } false { % endif % } action : - service : notify.phil data : message : 'A device is offline. Please check Home Assistant' title : Device Alert

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.

automation.yaml - alias: Alert when a critical device goes offline trigger: - platform: state entity_id: sensor.hue_hub_online, sensor.harmony_online from: 'Online' to: 'Offline' for: minutes: 2 condition: condition: and conditions: - condition: template value_template: > {% if states.automation.alert_when_a_critical_device_goes_offline.last_triggered is not none %} {% if as_timestamp(now()) | int - as_timestamp(states.automation.alert_when_a_critical_device_goes_offline.attributes.last_triggered) | int > 3600 %} true {% else %} false {% endif %} {% else %} false {% endif %} action: - service: notify.phil data_template: message: '{{trigger.to_state.attributes.friendly_name}} has gone offline. Please check the status of this device as some features may stop functioning.' title: Device Alert 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 - alias : Alert when a critical device goes offline trigger : - platform : state entity _ id : sensor.hue_hub_online , sensor . harmony _ online from : 'Online' to : 'Offline' for : minutes : 2 condition : condition : and conditions : - condition : template value _ template : > { % if states . automation . alert _ when _ a _ critical _ device _ goes _ offline . last _ triggered is not none % } { % if as _ timestamp ( now ( ) ) | int - as _ timestamp ( states . automation . alert _ when _ a _ critical _ device _ goes _ offline . attributes . last _ triggered ) | int > 3600 % } true { % else % } false { % endif % } { % else % } false { % endif % } action : - service : notify.phil data _ template : message : ' { { trigger . to _ state . attributes . friendly _ name } } has gone offline . Please check the status of this device as some features may stop functioning . ' title : Device Alert

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 condition: state entity_id: sensor.hue_hub_online state: Online 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 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 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 - 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 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.