Home Automation with OpenHab2 on Arch Linux

Home Assistant is a great automation system for some features, but after a while, it left me wanting more.  Additionally, with all of the updates, I felt like the HA team was really putting a focus on the implementation of Raspberry Pi's and not a "traditional" computer.  While customizations were nice, they left a lot to be desired.

So, I set out to find another solution that would conform to my wants in home automation.  Openhab was really the only other solution.  A great benefit to Openhab was the app interface on Android and iOS and the security.  Additionally, there isn't a charge for "cloud" functionality.

The installation was fairly simple;

$ yaourt -S openhab2

Everything seemed to be set up out of the box and OpenHab documentation was very easy to follow along. Most of the configuration files are located in /etc/openhab2/ and are pretty easy to understand.

There are two basic elements that capture objects within your automation network; Items and Things. Then you have Rules and Sitemaps. Rules are self-explanatory and provide specific automation triggers based on events that occur. Sitemaps are how you display your items (switches, toggles, sliders, etc). The last thing is Bindings which is OpenHab's method of connecting and communicating with devices. For instance, if you want to have support for Samsung TV's, then you would add the samsungtv binding. There are various ways of enabling your things, but the best way I have found is to enable that binding in /etc/openhab2/services/addon.cfg. Things typically won't work until the binding has been enabled.

binding = chromecast, exec, network, ntp, samsungtv, systeminfo, weather1, astro

Things are the actual devices that you want to use, for instance, smart bulbs, smart plugs, televisions, weather sites, astrological tracking, etc. Think of the stuff you purchase. (more here)

Items are the digital version of things and where all of the automation happens. You place items into your sitemaps so that you can manually control your things. If your smart TV is the "thing" then your associated items are the volume, power, input, etc. (more here)

Here are some basic configurations for things and items that are associated with each other.


Thing  tplinksmarthome:hs103:dining_f_lamp "Dining Room Floor Lamp"    @ "First Floor"     [ ipAddress="" ]


Switch     dining_f_lamp   "Dining Room Floor Lamp"        <light>       (devices, lights, diningRoom)   ["Switchable"]  {channel="tplinksmarthome:hs103:dining_f_lamp:switch"}

Looking at the -thing- first, the binding is "tplinksmarthome", the device type is "hs103" and the name is "dining_f_lamp". I have given a digestible name of "Dining Room Floor Lamp" to make it easier to incorporate with Google. After the @ sign, is the location and the ipAddress is pretty self-explanatory.

Now, looking at the Item, I have declared a switch that aligns with the thing. I have mirrored the label name (which is in " "), added it as a light for the icon (which is in < >) and also added it to groups ( which is in ( )). The switchable tag ( in [ ]) makes it viewable by Google so that I can control it with Google Home. Lastly, I have created a binding channel that encapsulates and associates the Item to the Thing as a switch.

The last piece to cover is the Sitemaps. In order to control this new switch in the app of the web interface, you need to add a sitemap and frame to list your items.

sitemap home label="Home" {
    Frame label="Quick Light Controls" {
        Switch  item=dining_f_lamp  label="Dining Room Lamp"

The sitemap is pretty straight forward. One thing to keep in mind, all of your configs must have the same name as sitemap in order to work properly. For instance;
- home.items
- home.things
- home.rules
- home.sitemap
All of these will be part of the initial sitemap labeled "home".

The frame will visually bundle your items together so that you can keep things organized and clean. And, as you can see, the Switch added is the dining_f_lamp (item) and it has a label.

In a nutshell, the configuration is very simple yet leaves room for growth and complexity where needed. In another post, I will start going over astronomical tracking for sunrise and sunset tracking and weather patterns. These two are perfect for the automation aspect.

September 22, 2019