The holiday season traditionally is a time to reflect and to look forward to next year. Last year was quite a ride both professionally as well as personally. Continued our double-digit growth rates for DotControl & RockBoost, winning a golden DIA award, my wife and I moving from Rotterdam back to our hometown in Limburg and moving our Limburg office from Maastricht to a bigger one in Heerlen.
So at the end of last year, in a desperate need of some digital detox, instead of just working during the holidays like I usually do, I decided to take a more radical approach by taking a two-week "staycation" around Christmas and New Years Eve. My new year's resolution was to leave my laptop in my backpack and severely limit mobile phone usage.
The first week went quite well actually, at least better than expected. (OK, I admit, just checking my mail and the occasional Jira issue... guilty pleasures). But then, somewhere during the second week, things went completely wrong. I had been thinking a lot about what home automation platform I would choose in our new home. As usual, I was stuck in over-thinking mode: Should I go for Philips Hue or IKEA TRÅDFRI smart light?
My parents had their home fitted with Somfy Tahoma motorized blinds. You can only imagine how disappointed I was to find out our existing Luxaflex Blinds could not be retrofitted with Luxaflex PowerView motorization, so that's still on my wishlist.
My best friend spent two days installing an automatic swing gate which supported Apple Homekit. Unfortunately, our iPad was too old to be able to set it up as a home hub. You need a home hub to enable access from outside your home wifi network. You can either configure a HomePod, Apple TV, or (recent) iPad as your Apple Home Hub.
Choices, choices, choices…
Introducing home assistant
Then suddenly I remembered I had been planning to have a look at a home automation platform called Home Assistant, to which my brother in law pointed out to me a while ago… Before I knew it I switched to action mode: ordered a Raspberry Pi starter kit online and found myself flashing the SD card upon arrival the next morning with the Hass.io image. A new hobby was born.
Home Assistant is a free, open-source home automation platform that “puts local control and privacy first.” Most of the global technology corporate brands are trying to monopolize the home automation market by creating mutually exclusive proprietary software and hardware solutions, (often based on in itself open communication standards such as MQTT, zigbee and Z-wave). Home Assistant can be seen as the missing link between all these different vendor technologies. So Home Assistant acts as the central hub in your home automation setup that allows you to control all kinds of smart device types across multiple brands from a single management UI.
Plug & play
Although you can build and run Home Assistant source yourself from GitHub, it’s advised to use the Hass.io image for newbies (like me). Hass.io is a home-assistant distribution optimized for embedded devices which includes an easy installation and updates procedure, snapshot backups, some Add-on utilities, and a nice Web UI management interface. So all you need to do to get Home Assistant up and running is boot a Raspberry Pi with the Hass.io image on the SD card and wait for a little while for the Home Assistant to download and install. After a short wait, you should be able to access the Home Assistant Management UI from your browser using http://hassio.local:8123 and see some default components like weather and sun added to the interface.
If auto-discovery is enabled, Home Assistant will automatically detect any supported home automation components which are available within your home network. Configuring a new component is as easy as just clicking through the discovered component’s configuration wizard, which differs per home automation platform. For me, the AHA moment was seeing the first IoT devices in my home popup in the Home Assistant management web UI. Since then I’m hooked and I’ve been steadily adding different brands of home automation devices into our house (thanks Hun for being so supportive...)
One of the first things I added to my Home Assistant were our Sonos speakers. The nice thing about Home Assistant is that you don’t need to have any technical knowledge. If you start Home Assistant for the first time, it automatically detects the Sonos devices within your wifi network and simply asks you if you want to configure the speakers:
Configuration is literally clicking some confirmation buttons in the wizard and tadaa: you can control your Sonos speakers from Home Assistant:
The next thing you would probably want to automate in your house would be the lights. I was having a hard time deciding between Philips Hue and IKEA TRÅDFRI. But then I thought: why choose if you can have both? Well, the beauty of Home Assistant is that you can mix & match home automation systems as you please. So for example in the living room, we now have the more expensive Philips Hue lights, while in my garage I have the cheaper IKEA TRÅDFRI.
Home Assistant recognises both Philips Hue as well as the IKEA TRÅDFRI lights as a generic light component (https://www.home-assistant.io/components/light/). So from the Home Assistant management web UI perspective, all lights are displayed and controlled in the same way. Depending on the light bulb-specific features different options become available, such as brightness, color, etc. Home Assistant even automatically recognises Hue rooms and allows you to for example control all the lights per room.
The only downside is that you have to buy both a Philips Hue Hub as well as an IKEA TRÅDFRI hub. Both Hue and TRÅDFRI make use of the Zigbee networking protocol. This is a low energy protocol that creates a mesh radio network. Wifi would be costing too much energy, draining the batteries of your devices. If that bothers you, you could even add a generic Zigbee component (https://www.home-assistant.io/components/zha/) so you can control both Hue and TRÅDFRI lights using one generic Zigbee radio module. So without the need of having a specific Hue and/or TRÅDFRI bridge.
Besides light components both Hue and TRÅDFRI also offer motion detectors. I used this to automatically turn on the TRÅDFRI light when entering our storage room. Although the TRÅDFRI motion sensor is not made available to Home Assistant by TRÅDFRI directly, you could use the status of the connected TRÅDFRI light bulb to trigger automations based on motion detection.
I’m also using the TRÅDFRI smart power outlet to control the power of my recirculation pump. We have a recirculation pipe that makes sure you have instant hot water by constantly pumping hot water through the water pipes. This will eventually damage the water pipes and waste a lot of energy. I, therefore, created an automation that only switches on the power outlet between 7 and 8 a.m. during weekdays and a bit later on the weekends. So Home Assistant helps to save the environment, saving my water pipes as well as saving energy costs :)
Add-ons and how-to edit your configuration manually
Now that we have our basic home automation devices in place, it's time to get our hands a little bit dirtier. Home Assistant can be configured using the UI for most of the basic operations.
The main point of entry for more advanced configuration changes is the configuration.yaml file located in the Config directory. As the file extension suggests, the YAML format is used to store configuration files. Hass.io is running on a Raspberry Pi, so you could of course also connect to the Raspberry Pi directly by hooking up a keyboard and monitor or by using an SSH connection and change the configuration files directly.
But Hass.io has another concept called Add-ons that makes this even easier. Add-ons are extensions of Hass.io functionality created by the community and can be easily installed from the Hass.io add-on store.
One of the first add-ons you could try is the HASS Configurator. This add-on will add a web-based configuration editor to the Home Assistant management interface:
Using the configuration editor will allow you to easily change your configuration.
For example, you can use it to configure different zones. Zones are basically circular regions that will help Home Assistant to determine whether persons or devices are at home or away. This can be used in automations, such as for example turn off the lights when nobody is home, but more on that later. Hass.io offers a collection of official as well as community add-ons. I will list a few I’m using below:
- Duck DNS: Allows you to access your Home Assistant from outside your local network using Duck DNS dynamic DNS service. This includes Let’s Encrypt support, but still be very careful.
- IDE: A full-blown Cloud9 IDE-based code editor including a Z Unix Shell
- UniFi Controller: Run a UniFi controller inside Hass.io. So no need for a UniFi Cloud Key and still be able to manage your Ubiquiti UniFi network from everywhere.
Another thing I was quite stoked to see was that Home Assistant supports a Tesla component out of the box. You simply add the tesla component to your configuration.yaml and enter your MyTesla credentials. Be careful to store your password separately in the secrets.yaml file. After restarting Home Assistant the tesla component automatically connects to your car and adds the UI components to the Home Assistant management UI:
The Tesla component allows you to see a lot of different information about your car. Such as for example mileage, in and outside temperature, battery status, range etc. In Home Assistant terms these are called sensors and they gather and display all sorts of data. You can also see the historical data of the Sensor and discover all sorts of patterns. For example, in the battery status sensor graph, you can see my Tesla charging slowly overnight, while during the day it decreases when I’m driving from Rotterdam to Limburg.
That brings me to explain another type of component, the device tracker. A device tracker allows you to track the location of objects, such as for example my Model X, iPhone and MacBook, and automate rules accordingly. By default, it only tracks location when you're inside the range of any of the zones you configured.
Another type of component that is included in the tesla integration is so-called (binary) switches. For example, you can control the tesla max range and charger switches.
You can even lock and unlock your Tesla from the Home Assistant management UI using the Lock component. (Discussion whether this is safe/wise to do, is beyond the scope of this blog post ;-) )
In the end, you are able to do almost anything you can do with the Tesla app in your Home Assistant as well. This actually makes sense as the Tesla component is probably reverse-engineered from the Tesla mobile app API. You can even turn on the heating which saved me from de-icing the windows.
A lazy developer uses automations
Up until now, we have been talking about viewing information and controlling devices from the Home Assistant management UI. But it’s called home automation not home controlling. Luckily Home Assistant allows us to easily configure automations using the Home Assistant UI.
It’s quite easy for example, to configure automation that turns on certain lights when the sunsets. The nice thing about this is that it saves energy because it adjusts to changing sunset times automatically (and as an edit bonus it also might seem a little bit more random to potential burglars).
Let’s take a little more complex automation scenario so I can explain all the different parts that makeup automation.
Tesla parked unlocked automation
I had a little issue with my Tesla that it doesn't “suck” in the passenger front door. This basically leaves your parked car unlocked because the Tesla app doesn’t warn you for this. So let’s create a new automation and name it: “Tesla Parked Unlocked Automation”:
After choosing a name for your automation, the first part of any automation is the trigger that should signal the automation to start. In this case, the trigger should be that the car brake sensor is in the “parked” state for at least 5 minutes:
Next step is any condition that needs to be checked before the automation actually triggers. In our case the condition is that the Tesla door lock state should be “unlocked”:
Last but not least are the actual actions that need to be executed by Home Assistant if the trigger matches the condition(s). In our case, I want to receive a push notification on my iPhone so I can run back to my car and lock it. (In order to receive push notifications on your mobile you need to enable the ios/android component and have the Home Assistant native app).
You can add multiple triggers conditions and actions.
As you can see the automation management UI is quite flexible, but if you need more complex automations you can create automations programmatically in Yaml by editing the automations.yaml file.
Another thing that was high on my wishlist was to be able to control my swing gate using Home Assistant. My swing gate supported Apple Homekit. But as I mentioned before my home wifi signal had too little reach on my driveway. This meant I would have to buy additional Apple home hub hardware so I could control the swing gate remotely using Homekit. Luckily Home Assistant supports Homekit. So I enabled the Home Assistant “Homekit controller” component.
This should not be confused with the Home Assistant “Homekit” component:
With the “Homekit” component you can expose Home Assistant controlled devices who don’t necessarily support home kit themselves as Homekit devices.
Using the Home Assistant “Homekit controller” you can control Homekit supporting devices from the Home Assistant management UI.
First, you have to disconnect the swing gate Homekit accessory in the Apple Home app. Home Assistant than automatically discovers the Homekit accessory. After manually entering the Homekit code the swing gate is connected to Home Assistant. But for some reason, the Cover never showed up in the Home Assistant UI. After checking the logs I discovered that Home Assistant doesn’t support all Homekit device types. At that time, the garage-door-opener was not supported, you cannot imagine my disappointment…
At this point, I was so hooked that I spend a whole day of my offline staycation to face my fears and actually dive into the Home Assistant python source code. Home Assistant source code setup is elegant by its simplicity. Home Assistant defines different types of generic components, such as light, switch, cover, thermostat etc. For these generic components, Home Assistant implements generic UI elements that allow you to control these components. On the other hand, the community can implement these generic components for specific brands of home automations systems.
It turns out that you can override implementations of components by placing copies of the GitHub source in the custom_components folder. The Homekit controller implementation consists of a init.py file where I could simply add the “garage-door-opener” type to the list of supported devices and link it to a Cover component type. This would actually display the Cover in the Home Assistant UI.
But of course, I couldn’t control it yet. So the next step was to have a look at the Homekit implementations for the switch, light and thermostat components. From that, I was able to “reverse engineer” the Homekit Cover implementation.
After a lot of trial & error, I was able to get it working. I was the happiest man alive when I actually saw the 3-meter long gate swinging open for the first time. Usually, my programming is limited to the digital world and it’s quite refreshing to see your code having an effect on the actual physical world.
I decided to submit my code back to Home Assistant as a GitHub pull request. I was actually pleasantly surprised by the great GitHub automation setup and the responsiveness of the Home Assistant community. After fixing the automated code style warnings I ran into an issue with my GitHub account which GitHub support needed 10+ days to fix. By that time someone else submitted a similar PR that was merged before mine. I must admit that his implementation was a lot better, but it’s great to know that there is such an active developer community for Home Assistant. So within a few days, it was released in the official Home Assistant version and I could update my hass.io instance with a click of a button.
One thing to note is that a Homekit device can only be linked to one system. So if you connect your Homekit device to Home Assistant, you can no longer control it from the Apple home app. The attentive reader might notice you could, in theory, control a Homekit device from Home Assistant using the Homekit controller component and then expose that Home Assistant device from Home Assistant as a Homekit device using the Homekit component. I still have to try and verify this, but in theory, it should work.
Switching to lovelace ui
What I really like about Home Assistant is that by default everything seems to work automatically. Devices are auto-discovered and even the UI is generated for you automatically. This is handled by the smart UI generator based on the different device types/components that are added. This is great for the less tech-savvy user.
On the other hand, if you want complete control over the UI, you can switch from automatic UI generation to controlling the UI manually using the recently released Lovelace UI. By switching to edit mode, you can simply add entities and build up your UI as you please using the integrated UI editor.
If you’re really into it, you can even switch to yaml mode and define the complete UI in yaml. You can even write your own Lovelace UI components from scratch.
What makes Home Assistant especially interesting for Dutch users is that there seems to be a very active Dutch user community. Home Assistant was actually started by a Dutchman called Paulus Schoutsen and Franck Nijhof, for example, seems to be a very involved Hass.io add-on developer. Having this high-level of Dutch involvement means that some typically Dutch devices are supported by Home Assistant by default. For example the Eneco Toon thermostat component. You can also physically connect your Dutch utility smart meters to Home Assistant using the DSMR component (Dutch Smart Meter Requirements). This will allow you to track your power and gas consumption quite detailed:
Within the Home Assistant community, it’s common for “Homies” to share their personal configuration.yaml file on GitHub (https://www.home-assistant.io/cookbook/ ). This is a great way to learn and to find inspiration. So without further ado, please find my current (humble) configuration:
- Philips Hue
- IKEA TRÅDFRI
- Nice4You SPA Swing Gate (using Homekit Controller)
- Samsung Smart TV
- Samsung SmartThings Washer & Dryer
- Vaillant vSmart thermostat
- Essent Slimme Meter (DSMR, power and gas consumption)
- Overnight Stay Rotterdam
- Heerlen Office
- Rotterdam Office
- Coming Home
- Tesla parked unlocked
- Go to sleep
- Hassio Add-ons
- Unifi Controller
- Raspberry Pi 3 Model B+
For the sake of readability, I listed a textual representation of my configuration. I still need to push my actual configuration.yaml to github.com. Please be very careful to not publish any personal information to GitHub, such as passwords and geo coordinates etc. You can use the secrets.yaml files to store secrets in Home Assistant and then make sure to exclude these files in your .gitignore.
- Data Science
- Azure IoT
- Apple Homekit
- thermostat servo motor based on Netduino
I will regularly try to update this blog post to reflect my upcoming home automation adventures.
As mentioned before, Home Assistant uses a different approach in that it puts privacy and local control first. So in contrast with other solutions, no data is stored in the cloud. That being said, a lot of sensor data is being stored locally and wouldn’t it be nice if we could use all this data to learn? Introducing Home Assistant Data Science portal that as its name suggests allows us to perform data science on our homes data.
For example, consider the analysis of our Vaillant vsmart thermostat historical data as an example of the things you can do with Home Assistant data science:
Great but what’s the business value?
Well, actually it was quite refreshing to have some tech fun without thinking about business value for once. Unleash your inner nerd!
On the other hand, there are tons of business applications. For starters automating lighting etc would save a lot of energy. This is not only good for in terms of costs but it’s of course also environmentally friendly. Some other scenarios’ we plan on doing in one of our upcoming DotControl hackathons are:
- Automating the demo room “on-air” alerts in our kitchen using a motion detector and connected lights. >>> done
- Using the text to speech feature to notify CICD deployments or production issues over the office Sonos speakers.
The possibilities are literally endless.
What do you need to start?
I really hope this blog post will trigger to start automating your home. As described above, starting and initial setup is really easy. Please find below a list of the minimal hardware required:
- Raspberry Pi Starters Kit
- Memory card reader/writer to flash the hass.io image onto the memory card
- Ethernet Cable (or a USB stick to configure your WiFi connection) *
- At least one of the starter kits below
- Philips Hue Starter Kit
- IKEA TRÅDFRI
* = HDMI cable and USB mouse and keyboard could come in handy in case you need to troubleshoot the Raspberry Pi.
You can download the Hass.io image here: https://www.home-assistant.io/hassio/installation/
I also listed a few arguments that you could use to fool yourself as to why this would make a wise investment:
- Saving on your electricity bill by only turning on lights when needed
- Saving on power and gas consumption by monitoring smart meter usage
- Saving on a UniFi cloud key
- Saving the environment
Last but not least I want to take this opportunity to thank my wife Femke, without whom's everlasting support this would not have been possible. (I'm so sorry again for the noob mistake of my "coming home" automation where I messed up the Sunrise condition triggering the Sonos to play on full volume when I arrived home in the middle of the night...)
Happy Home Automating!