Slowly making my home smart

Lights and media

This post isn’t in my normal theme. I’m gonna describe how I made my home smart. Well, semi-smart.

Over the past couple of years I’ve slowly been making my house lights be smart. In many places I’ve used Hue White Bulbs. They’re frequently on sale and can be got for around $10/bulb, which isn’t bad. With the hub they can be controlled by Alexa, or locally by using the API exposed on the hub.

Where I can’t use Hue, I’ve been using Lutron Caseta switches. These can work without a neutral wire, so are a great retrofit for older houses. It also has a hub that works with Alexa, and some smart people have worked out how to talk to the hub with python libraries.

I was able to extend the use of Alexa to other areas by emulating Hue bulbs. So now when I come home I can say “Alexa I’m home” and it will turn on the living room lights and start iTunes playing on the media center (turning on stuff that’s needed). Other routines (“Alexa I’m going out”, “Alexa bedtime”) do other useful stuff.

I replaced my thermostat with a Radio Thermostat CT50. This has a local API, so with my “fake hue” software I was also able to add basic Alexa controls.

But this is just the beginning.

Enter Home Assistant. This is an open source program written in python. It can be run in docker, on a Pi, as a VM, or inside a python venv. I chose the latter approach; created a CentOS VM (chosen so all my management tools work with it) and deployed HA.

HA can integrate with Hue via the API, with Caseta via the previously mentioned python libraries. Someone even worked out how to talk to the Alexa service (although it’s really not production ready). This lets me create a reporting interface such as

all the things

Or a simpler “light” panel.

all the lights

These panels are reactive; if a light turns on then the corresponding icon lights up. You can also control the lights from here; click on a light and it will turn on/off the real light.

OK, so far so controllable. It’s providing interesting and new ways of looking and managing the environment. But there’s no smarts.

Enter the “automation” part of HA.

Firstly, my basement has two sets of old-school florescent bulbs; one by the stairs and controlled by a switch outside the basement, and one in the back (where I have my computers set up), controlled by another switch. I wanted to treat these lights as one. So if I turn on the basement light then the one by the computer also turn on.

With HA you can write a trigger:

- alias: Basement Automation Turn On
  initial_state: true
  trigger:
    - platform: state
      entity_id: switch.basement_computer_lights, switch.basement_main_lights
      from: 'off'
      to: 'on'
  action:
    service: switch.turn_on
    entity_id:
      - switch.basement_computer_lights
      - switch.basement_main_lights

This basically says that if either of the Caseta light switches are turned on then make sure they’re both turned on. There’s also an equivalent “off” function (not shown); if one is turned off then both are turned off. Now HA doesn’t get instant notification of changes because it has to poll the hub, but it generally fires within 3 to 5 seconds, which is good enough.

We can also use this idea to cross environments. In my laundry room I have two Hue bulbs and a motion sensor. When I enter the room the motion sensor detects it, checks the lights levels and turns on the bulbs if necessary. This is out of box Hue functionality. But we can set up an automation that detects the bulbs turn on and also turn on the florescent bulb in that area. This one is a bit more complicated because I’ve combined on/off functionality and the Caseta switch detection into one routine.

- alias: Laundry Automation
  initial_state: true
  trigger:
    - platform: state
      entity_id: switch.laundry_main_lights, light.laundry
      from: 'off'
      to: 'on'
    - platform: state
      entity_id: switch.laundry_main_lights, light.laundry
      from: 'on'
      to: 'off'
  action:
    - service_template: >
        {% if trigger.to_state.state == "on" %}
        switch.turn_on
        {% else %}
        switch.turn_off
        {% endif %}
      entity_id: switch.laundry_main_lights
    - service_template: >
        {% if trigger.to_state.state == "on" %}
        light.turn_on
        {% else %}
        light.turn_off
        {% endif %}
      entity_id: light.laundry

The result is that I can walk into the laundry room and all 3 lights turn on, and a few minutes after I leave the hue motion sensor turns off the Hue bulbs and all the lights go out. Or I can manually turn on/off the florescent bulb from the Caseta switch and the Hue bulbs will follow.

This is just the beginning of making my home smart. Just with what I’ve got I could set up triggers based on, for example, sunset. In most cases I’m happy to have trigger based routines (‘Alexa foobarbaz’) but it’s nice to have the laundry lights work when my hands are full with a basket of dirty clothes.

Which reminds me… I need to do laundry!