What makes a home smart? Does your house tell you that the washing machine is finished? Do you get a push notification on your phone when there is someone at the door? Do your light and the fan on the toilet go on and off automatically? Can you see in the blink of an eye, what your central heating unit is doing and how your solar boiler is performing? My house does all of that, for me this is what a smart home is about. Being in control, being informed and if possible let your house make autonomous decisions.
I always liked gadgets and was always interested in how my computers etc are performing. In small steps I am building my own smart home, using all kinds of open source technologies. I use openHAB, an open source Java solution. For me openHAB is perfect; its flexible, its open source, its Java and it supports a lot of smart devices. But many other (open source) solutions are available.
In this blog I will focus on openHAB and how I built some parts of my smart home, with openHAB and other open source technologies. I will tell you why its fun and what makes it a great exercise for your daily practice as a developer.
The architecture of openHAB is cool and enterprise worthy. The most important feature is definitely the usage of OSGi (via Eclipse Equinox) in this way modularity can be provided and OSGi also delivers a scalable eventbus, the so-called OSGi EventAdmin service. The implementation of OSGi has been done good and bindings can truly be added, replaced or removed at run-time, so restarting should normally not be required.
The architecture of openHAB source
All bindings should read from and/or publish their events to the eventbus, in that way a flexible and scalable application is created in which bindings are unaware of each others existence.
The abstractions for the commands and events are well chosen and not too complex and are well documented. Of course a flexible API is available, supporting REST XML, REST JSON and WebSockets.
As a whole openHAB is very flexible and highly configurable.
However the hardware requirements are not enterprise grade; my openHAB instance is currently running on a Raspberry Pi 2
Smart home, infrastructure
Besides the architecture, the infrastructure surrounding my openHAB instance is very comparable to our daily developers practice, as databases, queues and reverse proxies are very common components there. A short overview of what I currently have running:
Message queue for MQTT
MQTT is a machine-to-machine (M2M)/”Internet of Things” connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. source: MQTT
Mosquitto provides me with a lightweight message queue, running on my old Raspberry Pi B2. At this moment data is published there which originates from my Solar Boiler and my OpenTherm GateWay. Currently openHAB is only a subscriber to MQTT, but this can be extended if desired. In the past (before my Smart meter arrived) an ESP8266 was also publishing data regarding my power usage.
For persistence I use three different parallel options:
- For long-term historical data I use MySQL running in a Docker container on my central server, this data can be used to discover trends or debug rules.
- For charting RRD4J is used, it’s a Round Robin Database, so data is not permanently stored but automatically rotated away.
- To easily recover the states of switches and sensors on restart I use MapDB, a nice and high-performance storage framework for single data points.
NGINX is used as a reverse proxy, in front of openHAB. NGINX takes care of authorization and SSL offloading. The certificates are (of course) also free, and are provided by let’s encrypt.
Bridging to the real world
Not that common in our daily practice are bridges to the real world. But we want to automate something, say lights, switches, chimes and we want to monitor other things. So a lot of bridging devices are (indirectly) connected:
- Philips Hue Bridge to connect my Hue lights, using the ZigBee protocol
- RFXtrx433E USB 433.92MHz Transceiver to receive and switch Klik-aan-klik-uit and other 433,92 MHz RF devices.
- Z-Wave controller, to control a mesh network of plugs, smoke detector(s), switches and more devices coming soon.
- P1-cable to receive data from my smart meter.
OpenHAB is just one of the available open source projects for your smart home. Not only the price makes its great, besides that the fact that you can view and / or modify the source comes in handy quite often.
My first smart home project was building my own OpenTherm Gateway to monitor my thermostat and central heating unit. This is another great open source project, because not only the software has been made available, but also the hardware designs. So anyone who wants to build or extend can use these designs.
I did not extend anything to hardware, but just added some software in front. I exposed its information by building a small Bootstrap website.
My homemade OpenTherm Gateway Bootstrap website
When I was looking for a way to extract status information from my Remeha ZentaSol, I found a USB to RS485 adapter for 82 cents on aliexpress. After I connected it and made some minor change to some C++ code (which I found on an abandoned Google Code project) it worked. I adopted the vbusdecode project and added tests and such. Thanks to this existing project I could start extracting data in 10 minutes and did not to have spent a big amount of money.
My solar boiler overview, a little bit edited visually
Shortly after I purchased the RFXCom RF-receiver I noticed that my chime was incorrectly recognized, as an unknown device. Luckily I could modify the existing binding and I now receive a push message on my phone when there is someone at the door. Of course I created a pull requests to enable others to profit from the improved device support.
My smart home is coming together one step at a time, thanks to openHAB and other (open source) technologies. Besides that all these technologies make a wonderful playground to work with interesting and relevant technologies at home. So building your own smart home is a very good exercise for your daily job and of course a lot of fun.
PS: did you know you can get started very quick with an openHAB Docker container