Home automation from nothing to done: Part 2


This is one of a serie of 7 posts about home automation from nothing to done. Each of them marks a milestone in the project and none of them should be too long to comfortably read in the metro when commuting.

In this post I’ll write how to start wiring some smart appliances to your home automation system. In case you didn’t read the first part, please take into account that I’m using Home assistant as my home automation software. I have it running on a Raspberry Pi 3, but if you just want to try it out and don’t want to commit buying a device you can install it on your desktop or laptop. I strongly recommend using their docker image in this case since it’s the fastest and less intrusive way to try it out.

At the end of this post we’ll be able to:

  • control our lights through home assistant
  • control our lights with the Philips Hue mobile app
  • control our lights with the Philips Hue dimmers
  • control our lights with the wall switches

  • control our smart plugs through home assistant

  • control our smart plugs with the TP-Link Kasa mobile app

In my opinion it’s important to have multiple fallbacks to make sure that everybody (not only us, but also guests for instance) can interact with our smart home even if they don’t have access to our software or mobile apps.

Smart lights

First of all, when talking about smart lights we have to agree on what they are, as there are several ways to accomplish the same (or quite the same) result.

The first difference is whether the bulbs themselves are smart, or the outlets they’re plugged into. In some cases (for instance sofa lights, or bedside lights) this doesn’t make a big difference, but for ceiling lights smart bulbs is the only way to go.

The second difference is “how smart” do we want the lights to be: bulbs or plugs can be controlled via Wi-Fi, radio waves (e.g. Z-Wave) or proprietary remotes. Some bulbs require a hub to connect to, some are stand-alone.

In most cases appliances controllable via proprietary remotes don’t classify as smart in my opinion. They can just be “more comfortable” to use, but not much more. This is why we’ll only consider appliances controllable via WiFi or radio waves in this and the following posts.

For my setup I decided to go with Philips Hue bulbs. I find they are really easy to setup, very reliable, and offer a quite extensible setup thanks to the hub they come with, even in case you later decide not to use an underlying home automation software. Moreover, Philips has apps for both Android and iOS to easily control the lights, even when outside home!

A cheaper alternative could be the bulbs from IKEA (TRÅDFRI). I’m not sure whether to recommend them or not, since they had some issue with the Zigbee protocol in the beginning and thus required their own hub. Ideally you can use these bulbs with Hue bridges, the same way as you can use OSRAM Lightify bulbs with Hue bridges. You don’t want to buy a bridge for every different bulb brand you have, and you don’t want to be locked into buying all the bulbs from the same brand just because you have their bridge.

To start, the set I suggest is the one including the Hub (required to use the bulbs), one or more white bulbs and optionally one or more dimmers that can be mounted on the wall (but detached if needed) to simulate normal light switches.

Setting up the Hue apps

Let’s remember we want to be able to control our home even in absence of our home automation system. To achieve this, we’ll setup everything through the official Hue app I mentioned above. As I don’t want to make this post too long and also I don’t intend to make it a step by step guide that can be easily found in other places, I’ll just link to a possible tutorial to set everything up.

Once you follow the instructions, please make sure to go into Settings -> Hue bridges -> your hub, then tap info -> Network settings and specify a static IP address. You can also do this in your router of choice if you know how to, but the app is another option that will work totally fine. We need this to setup home assistant later.

If you follow the instructions, you’ll be able to query the state of your lights and turn them on or off from inside and outside your home. You’ll also be able to setup “home” and “away” scenes to turn specific lights on or off depending on you coming or leaving your home, as well as specifying “wake up” and “sleep” behaviors or custom routines, but this is not the kind of things I recommend doing because it’s exactly what we’re going to do with Home assistant. The important part as I said is that we have a secondary fallback mechanism in case of issues with our automation software, while the primary fallback is the one we get for free with our legacy wall switches (by default they should always be turned on so that the bulbs can talk to the hub, but in the catastrophic case the hub breaks, you will still be able to control the lights through them). We should be pretty safe!

Wiring the lights to Home assistant

In order for home assistant to know which lights we have in our flat, we have to open the configuration.yaml file in the main installation folder (if you installed it on a Raspberry Pi with the all-in-one installer, that would be /home/hass/.homeassistant/), and add the light component:

light: 
  platform: hue
  host: [YOUR_HUB_IP]

where [YOUR_HUB_IP] should be replaced with the IP address you configured in the previous step.

Now you can restart home assistant by going to Services (the first icon in the Developer Tools in the bottom left corner), and calling the homeassistant.restart service as shown in the screenshots below:

services

restart

If you reload the page after about a minute, you should see a new widget with a Configure button. Press it and follow the instructions (you will need to press the button on the Hub and then wait a few seconds before all the lights are automatically detected by home assistant).

Now you are able to turn the lights on/off and dim them to any desired brightness from your mobile phone or laptop. If you have Hue color lights, you’ll also be able to pick any color. This doesn’t sound like a huge achievement until now, but stay with me and we’ll be able to unleash the power of home automation without lifting a finger!

Smart plugs

When it comes to types of smart plugs, the same applies as for smart lights. As we want to build an ecosystem where everything is remotely controllable (and with multimodal interaction), we’ll only look for Wi-Fi or Z-Wave controllable plugs.

The plugs I found when searching on the web are mostly:

I have 2 TP-Link HS110 and a Osram plug and they work very well with Home assistant (it can also retrieve energy consumption for the TP-Link ones).

Note: I bought the TP-Link first since they were discounted on Amazon, but the Osram are probably a better option since they integrate with the Hue bridge and thus don’t need a static IP to be set.

Some models of D-Link plugs are also supported and they don’t require any hub, just like the TP-Link.

Belkin Wemo is supported too.

All of these smart plugs can also be controlled through proprietary apps (as a fallback mechanism).

If you are interested in the energy consumption feature of the TP-Link, or you don’t have smart lights yet - and so you don’t have a hub - go with the TP-Link. Otherwise, go with the Osram.

Setting up the TP-Link smart plug is really easy. Follow the instructions by plugging the plug (!!) and using the Kasa mobile app (for iOS or Android) to connect it to your home WiFi network. From then on, you can easily turn the plug on and off through the app (or even schedule usages, simulate presence when you’re away, and setup timers). If you login with a TP-Link account, you will even be able to control the plug remotely.

With the Kasa app is unfortunately not possible to set a static IP address for each plug. In this case though, I believe it’s really important to make sure each plug has the same IP over time because there is no discovery in Home assistant for TP-Link plugs, so we’ll need to set a static IP in the Home assistant configuration file. If the IP address of a plug changes after a lease or after you restart your router, you’ll need to update the configuration and restart Home assistant before it can talk to the plug again.

For this reason I highly recommend to setup a static IP address for each plug through your router.

Setting up the Osram smart switches

Setting up the Osram smart switch is also quite easy. You can follow the instructions by plugging the plug (!!) and add the switch just as you would add another smart bulb (that is, by triggering search from the hub). I watched this YouTube video but be aware it’s in German.

From then on, the switch works as a on/off lamp and should appear in Home Assistant on the next restart. The nice things you get with this setup are:

  • you don’t need to set a static IP
  • you don’t need any additional configuration for Home Assistant
  • you get remote control for free through the Hue hub!

In order for home assistant to know which plugs we have in our flat, we have to open the configuration.yaml file once again, and add the switch component:

switch: 
  - name: Smartphones Charger
    platform: tplink
    host: [YOUR_PLUG_IP]
  - name: Media Center
    platform: tplink
    host: [YOUR_PLUG_IP]

where [YOUR_PLUG_IP] should be replaced with the IP address you configured in the previous step.

Now you can restart home assistant (read the previous paragraph to know how to do it if you don’t remember).

If you reload the page after about a minute, you should see a new widget just as in the picture below:

configured switch

You can toggle it on and off, and your associated smart plug will respond accordingly. Great!

With this post we were able to configure smart lights and smart plugs with Home assistant and are now able to control them through its web interface (also from our mobile phone).

With the next post I’ll write about a smart heating system. Keep reading!