Architecture for a smart home

in technology •  2 years ago

I would like to add a little bit of "smartness" to my home, but I found myself spending hours walking in a maze of:

  • proprietary protocols

  • feature bloat

  • pricey devices

  • limited extensibility (or you have to shell out more bucks)

  • cumbersome interfaces

Recently, some nice and nexpensive smart home kits got some hype like SmartThings. Unfortunately, they are built around a "walled garden" philosophy.

I'm an open source and open hardware enthusiast so I knew that I wanted something different.

The turnaround for me point was when I got to know openHAB; it's a mature and feature rich Home Automation Bus project, with a single UI for mobile, remote, and desktop control. Moreover, it has time and event based triggers, a flexible rule language, it supports several databases and has a gazillion different bindings for devices like Nest, Samsung TV, Sonos, Tivo, and so on.

openHAB also has a stable support for MQTT, pairing those technologies could provide a really robust and flexible automation system.


The idea is to have a few microcontrollers (MCU) that gather data from sensors and publish them to an MQTT topic, then openHAB will apply the rule for a specific value incoming from a sensor through MQTT and will publish the corresponding command to another topic. Finally there will be a microcontroller that will "listen" the command and will operate the actuator.

The logic will be concentrated in openHAB that speaks with a few "dumb" MCUs, MQTT messages will be delivered on the domestic Wi-Fi, so it's not required to pull cables through walls.

Even if my wishlist for a "smart" home is fairly basic:

  1. A flood sensor to detect water leaks and shut down the water supply

  2. A light sensor to turn on outdoor lights when the surroundings gets dark

  3. A moisture sensor to turn on sprinklers

  4. Indoor/outdoor temperature and humidity sensors

the system described is able to handle much more complex scenarios.


In the MCU compartment I found this little and cheap gem: ESP8266. It integrates Wi-Fi connectivity, GPIO pins, ADC in a single package. There are some boards based on that MCU, all them comes with NodeMCU firmware that enables to run Lua scripts, recently ESP8266 got also the support in the Arduino IDE, so you can flash an Arduino firmware if you prefer.

Other components may include relay boards, DHT22 for humidity and temperature, LDR as a light sensor and solenoid valves.

I'm not sure about a Raspberry Pi 2 but an ODROID-XU4 is certainly powerful enough to host openHAB plus the software described below.


Besides openHAB, I need a good MQTT broker, there are plenty of choices:

  • Mosquitto - C language, BSD license

  • RabbitMQ - Erlang language, MPL license or commercial

  • HornetQ - Java language, Apache 2.0 Licence

  • Apache Apollo - Java language, Apache 2.0 Licence

I used Mosquitto for my initial tests and it worked pretty well.

InfluxDB and Grafana will complete the software stack as a time series database and visualization tool respectively.

Among the visualization / dashboard crowd I would like to also mention:

Real life scenarios

I want to measure outside light and turn on the lights in the front of the house if it gets dark and the light value is above a specific threshold for at least n minutes. The lights should be switched off at a fixed time during the night to avoid energy waste. I also need a "software" button to manually turn on/off lights.

That can be implemented with a couple of items:

Number Outside_Light        "Outside Light [%.1f]"  <light> (Light)  {mqtt="<[main_broker:sensor/light/outside/A:state:default]"}

Switch Outside_Light_Switch "Outside Light Switch"  <switch> (Light) {mqtt=">[main_broker:switch/light/outside/B:state:ON:1],>[main_broker:switch/light/outside/B:state:OFF:0]"}

The first item Outside_Light is a type of Number; it listens for light values coming from MCU that are published in sensor/light/outside/A topic. The second item Outside_Light_Switch is a type of Switch and publishes its state to switch/light/outside/B topic, converting the state to 0 or 1 and can be pressed using openHAB's UI. You can note the use of a custom topic naming scheme.

Then two rules defines automation and ties together these items:

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

var Number lightThreshold = 600
var Number lightIteration = 0

rule "Change outside light status"
      Time cron "0 0/2 15-23 * * ?"
      logInfo("Sensor", "Light value: " + Outside_Light.state)
      var Number maxCount = 2

      if((Outside_Light.state > lightThreshold){
         lightIteration = lightIteration + 1
         if(lightIteration == maxCount){
           postUpdate(Outside_Light_Switch, ON)
       } else{
          lightIteration = 0
       logInfo("Sensor", "Iteration: " + lightIteration)

rule "Scheduled change outside light status MON-SUN"
      Time cron "0 30 1 ? * MON-SUN *"
      lightIteration = 0
      postUpdate(Outside_Light_Switch, OFF)

The rules above are fairly self-explaining: I use a time based trigger to check light values every two minutes from 3 p.m. till midnight, then I use a counter to wait at least n minutes (4 minutes in the example above) before switching on the lights. Another time based trigger switches off the lights at 1:30 a.m.



  • Flexible

  • Extensible

  • Cheap


  • Not plug and play, requires technical skills like programming, wiring things, and may be soldering

  • Lack of enclosure for sensors while commercial ones are nice, see for example Fibaro Flood Sensor. 3D printing could help realize custom enclosures, and on-line there are some designs to start with.

I didn't tested openHAB 2 because at the time of this writing it is still in alpha release, but it looks promising in lowering the required programming skills.

This project is still a work in progress; I have to choose some hardware and software components and work on network security, but the main idea has been described.


This post intentionally doesn't contains any schematics or instructions about how to connects things. You have to be technically prepared and you need to know your country's home security laws before doing any work, because you may severely injury yourself or damage your house!

Update 1:

I'm really glad that Vlad found this post interesting and was so kind to translate it in his mother tongue. So any Russian reader can enjoy it better at: Архитектура для умного дома

Update 2:

openHAB 2 has reached beta4 phase, check it out!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Hi! I am a content-detection robot. I found similar content that readers might be interested in:


Please check more carefully, since the content was moved to steemit :)

I got into home automation a dew months ago but kept walking into a brick wall with OpenHAB and ended up using Home Assistant instead. Check them out too if you want :)

Congratulations @alesm! You have received a personal award!

Happy Birthday - 1 Year on Steemit Happy Birthday - 1 Year on Steemit
Click on the badge to view your own Board of Honor on SteemitBoard.

For more information about this award, click here

By upvoting this notification, you can help all Steemit users. Learn how here!