Kristian Glass - Do I Smell Burning?

Connect Together Your Smart Home With Home Assistant

From my smart home user-stories:

For my home, I want a centralised abstracted event hub for connecting sensor/actor devices together, so I can separate “automation logic” from “interfacing code” – even better if the interfacing code is done for me!

Home Assistant handles this nicely.

Previously I’d been wiring things together in a very ad-hoc fashion. My “smart doorbell” had the logic to connect to Slack and SES to send me notifications, my cameras had similar logic replicated, et cetera. Event-handling and automation code lived on each device, and coordinating and managing it all was a pain.

Enter Home Assistant, which acts as a generalised abstraction layer and centralised event-bus between all the things.

You tell it about your devices (“components” - it has support for nearly a thousand), it provides you with a nice interface for manual control, and powerful but easy-to-write “automations” to hook everything together.

Here’s a snippet from a configuration.yaml that defines two components, a pseudo-sensor that determines whether it’s a “work day” (e.g. a week day vs the weekend) and a TP-Link Smart Switch:

binary_sensor:
  -
    platform: workday
    country: UK

switch:
  -
    platform: tplink
    host: front-lamp.example.com

And here’s an automation that ensures the front lamp is automatically switched on, on work-days when my wife gets up to go catch a train:

-
  trigger:
    platform: time
    at: '05:50:00'
  condition:
    condition: state
    entity_id: 'binary_sensor.workday_sensor'
    state: 'on'
  action:
    service: switch.turn_on
    entity_id: switch.front_lamp

You can group things for convenience:

living_room_lights:
  name: "Living Room Lights"
  entities:
    - switch.living_room_back_lamp
    - switch.living_room_mantelpiece_lamp
    - switch.living_room_uplighter

You can compose scripts for more complex actions, like this one that saves me having to go downstairs when I inevitably forget to switch a light off:

sleep_time:
  sequence:
    -
      service: switch.turn_off
      data:
        entity_id: group.all_switches

and getting third-party devices to send events is fairly straight-forward (taken from an Ansible Jinja2 template):

#!/bin/bash

curl --header "X-HA-ACCESS: {{ hass_password }}" --header "Content-Type: application/json" --data "{\"hostname\": \"$(hostname -s)\"}" {{ hass_url_root }}/api/events/motion.on_event_start

It’s pretty straightforward to install and operate. I’m currently running it on a spare Raspberry Pi Zero W with my own install of their Python package and my configuration living in GitHub - they offer a convenient all-in-one image for the Raspberry Pi, but that doesn’t play nicely with my existing server management setup.

All-in-all, I’m really impressed - Home Assistant offers an excellent easy-to-operate platform for tying together “smart devices”, combining sensible and useful defaults with powerful yet simple opportunities for customisation.

Comments