This home automation project write-up is part 1 of 4 parts. We chose to break things up into chunks that are more easily digestible and to make it easier for people to focus on the aspects of our project that are applicable to them without having to wade through a bunch of stuff that has no value to them. Here's what you have to look forward to:Part 1 - Overview. We lay out the main components of our home automation system and install the core software component, OpenHABPart 2 - Data Persistence. We install a MySQL database server and tools to manage it. We then integrate it with OpenHAB for the purposes of storing our home automation data indefinitely.Part 3 - Messaging. We install a lightweight messaging system (MQTT broker), Mosquitto, and integrate it with OpenHAB to exchange information with custom, home-grown IoT sensors and controls.Part 4 - Custom Interfaces. We install and configure an Apache web server and briefly discuss integrating custom web pages with OpenHAB. This will provide a platform for building custom user interfaces for our home automation system.
A perfect storm:My family moved into a new, non-automated home in May 2016.We discovered the joy of Pi.We needed to incorporate our newly minted indoor weather nodes into a more user-friendly platform.Home automation has been a hobby of mine for years (X10 anyone? Anyone? Bueller?), and I was looking to dabble in the next generation of HA technology.
So we went looking for a home automation platform that would run on a Raspberry Pi, could integrate custom IoT devices as well as common off-the-shelf devices, and could be accessed and operated from a variety of clients (web browser, smart phone app, etc.)
We didn't have to search long before discovering that OpenHAB checked all of our boxes and would be the heart and soul of our new home automation system.
OverviewOur home automation system, lovingly called Home Automation Laboratory, or "HAL" for short, is composed of several open-source components. This write-up will not cover the details of installing and configuring each of these components. That information has been documented many times already and far better than anything we could add here. We will be providing references to the documentation that we utilized. We will also be providing details on how we integrated each of these components with each other and with our home automation devices.
Introducing Home Automation Laboratory, aka "HAL"
This 4-part project write-up will cover the install and integration of the main software components that comprise our home automation system. Future project write-ups will document how we integrated various home automation devices and custom UI's with HAL as well as adding voice control. Here's a sneak-peek at what's to come:Integrating Z-Wave devices with OpenHABIntegrating Particle Photon-based IoT devices with OpenHABIntegrating Belkin Wemo devices with OpenHABIntegrating Philips Hue with OpenHABIntegrating Insteon devices with OpenHABUsing Amazon Alexa to control OpenHABCreating custom user interfaces for OpenHAB (Star Trek LCARS panels for all my friends!)
ComponentsRaspberry PiThe groundbreaking, ubiquitous all-in-one single board computer. It doesn't have earth-shattering power, but it is very capable and an ideal platform for our HA system. We're using 4 Raspberry Pi 3's in our home automation system.
1 / 2 • Raspberry Pi 3. Yum!
What we like about the Pi:Inexpensive ($30 at our local Microcenter)World-wide acclaim and supportCompact yet capableEasy to install and configureOpenHABAs we stated above, OpenHAB was practically a no-brainer to be the brains of HAL. Google "home automation raspberry pi" and OpenHAB is front and center in the results.
OpenHAB is essentially a platform, or framework into which you can add "bindings" and/or services that allow OpenHAB to interact with a wide-variety of home automation devices. There are approximately 200 different bindings available. Everything from Amazon Dash buttons, to Insteon, to Phillips Hue, Z-Wave, and more. Just about any current home automation protocol, technology or standard can be integrated with OpenHAB.
1 / 2 • OpenHAB's home. Everything you need starts here.
Here's what we found particularly attractive about OpenHAB:Open SourceCan be installed on just about any platform including Windows, Mac, and Linux, with tons of support for Raspberry PiWe're not locked into a single, proprietary HA technology or vendor. That frees us up to pick-and-choose the best device for the task-at-hand regardless of what specific technology it uses.Our home-brewed devices can be integrated into an OpenHAB environment. It has bindings for common networking/communication protocols (http, mqtt, etc.) that let it communicate with just about anything you can hang on a network.Pre-baked smartphone apps. Free apps for Android and iOS make our OpenHAB system very accessible and user-friendly.Web-based UI. In fact, OpenHAB offers several web-based UI's, one of which is panel-based and targeted at tablet devices.User interfaces are configurable. We can layout user interfaces that are tailored to each member of the family or targeted to specific uses.Custom interfaces. OpenHAB comes complete with a RESTful API making it easy to build custom front-ends.MySQLOpenHAB offers a variety of ways to persist, or store, device data. Database, JSON, MQTT, and a couple other options are available. We wanted to be able to store historical weather information for analysis. I'm fairly familiar with relational database as a side-effect of my day job, so it was a comfortable choice to save our data in a database. MySQL is Open Source, very common, and thus has a ton of support available. For us, this was another easy decision.
Attractive characteristics for us:Open SourceLots of supportThere are many, many options available for accessing and presenting stored dataIt's a technology we have experience with.MySQL WorkbenchAlthough you can manage MySQL through a command-line interface, it's much easier and efficient to have a GUI tool to manage users, databases, tables, etc. Fortunately, MySQL provides an excellent, Open Source option, My SQL Workbench
MySQL Workbench. Serious stuff happens here! :)
Why MySQL Workbench:Easily integrates with MySQL serverOpen SourceIf you have any experience working with relational database systems, it's very easy to learn.ApacheAlthough OpenHAB offers several very useful user interfaces, we also wanted to roll our own. Fortunately, OpenHAB provides a REST API that easily facilitates custom front-ends. We chose to use fairly basic HTML5 web pages as our presentation layer. So we needed a web server to "talk" to HAL and serve up our custom web pages. We chose Apache.
The venerable Unix/Linux web server
Here's why:Open SourceVery popular, so tons of support.Works well on the PiEasy to get up and running.MosquittoMosquitto is a very popular MQTT broker. MQTT is a light-weight protocol for exchanging messages between 2 or more systems. Mosquitto brokers, or routes, messages between HAL and some of our home-grown devices.
Makes me itch just thinking about it, but does it's job very well!
What we like about Mosquitto:Open SourceEasy to install and configureWorks well on the Pi as well as other devices (Arduino, Photon, etc.)Lots of supportFast and efficient
As mentioned, we utilized 4 Pi's in our HA system. This may be overkill and might be causing more problems than it's solving. Time will tell. Each of the major software components is installed and running on it's own Pi. OpenHAB runs on a Pi named "HAL", Apache runs on "Spidey", MySQL runs on "Dolly", and Mosquitto runs on "Zapper".
The method behind this madness is to spread the computing load. While all of these components can certainly be installed on a single Pi, we chose to divide the labor so as not to overtax the Pi. This should give us ample room for growth.Each of our 4 Pi's starts with a basic, standard install of Raspbian. We found that the instructions on the official Raspberry Pi web site were more than adequate. Hit the "instructions" link for step-by-step details. Here's the high-level run-down:Using another computer (Mac, PC, Unix/Linux), copy the OS installer "Noobs" onto a micro SD card.Insert the SD card into the Pi.Connect the Pi to a keyboard, mouse and monitor.Optionally connect a cat5 cable to your network (with internet access).Connect the Pi to power.The Pi will boot up and eventually display a dialog box containing various operating systems. Choose Raspbian. If you didn't hard-wire the Pi to the internet, configure wifi access, and let 'er rip!The install process will run for 15-20 minutes or soOnce complete, the Pi should boot into its GUI OS.We enabled VNC and SSH so that we can access the Pi without it being connected to keyboard, mouse and monitor (aka "headless").At this point, we configure locale information, rename the device, and assign a static IP
1 / 6 • Click the Raspberry icon (yours may be at the top of the screen), click "Preferences", click "Raspberry Pi configuration"
We followed this same process for all 4 of our Pi's. The only difference between our Pi's is the size of the SD card we used. The database server got a larger card (64mb), the MQTT server a smallish card (8mb), the other 2 got a medium sized cards (16 MB).
At this point, the Pi is ready for it's specialized software install.OpenHAB
Out installation of OpenHAB used the "apt-get" software/repository management tool. When we first installed OpenHAB, version 2 was still in a pre-release phase. They have since formally released OpenHAB 2. So, there might be slight differences in the install procedure we went through vs. what it is now. I apologize in advance for any discrepancies.Here's a link to Raspberry Pi install. It includes prerequisites.This page has more specifics/step-by-step instructions
Here are the highlights of the install process:Install prerequisites (notably Oracle Java 8)Add OpenHAB repository key to the apt package managerAdd OpenHAB repository locations to the apt package managerapt-get install ....Configure your Pi to launch OpenHAB automatically when your Pi starts up.
You can then point a browser to your Pi's IP address, port 8080. This will connect to your OpenHAB server. The first time you connect, it'll walk you through a set-up wizard. The wizard wasn't in place when we did our OpenHAB install, so I can't directly comment on it, but it seems fairly straightforward.
The links above include instructions for doing a manual install for the more adventurous. There's also an install image called "Openhabian" that takes care of installing the OS (Raspbian) and OpenHAB install all in one shot, for the less adventurous :)
The OpenHAB install includes a demo. Instant gratification! And a good starting point for your custom set-up.
We now have the heart and soul of our home automation system up and running. As mentioned earlier, OpenHAB is really just a framework for integrating various sensors and controls, so it's not very functional at this point apart from the demo. However, subsequent write-ups will add more and more functionality.Head on over to Part 2 - Data Persistence for more fun!