OpenHAB

"A vendor and technology agnostic open source automation software for your home"

On this page

What's OpenHAB?

OpenHAB is free, open-source software that can talk to lots of open and closed home automation systems.

It runs a website on your Pi where you can view the status of all your sensors as well as an Android and iOS interface, and it has a rules engine for setting up automation.

Installing OpenHAB

We'll install OpenHAB in /opt/openhab:

sudo mkdir /opt/openhab
cd /opt/openhab

Now check the download page and mouse over any of the Download buttons to check the latest release version. At the time of writing this was 1.7.0, so if a more recent version is available just replace "1.7.0" in the instructions below with that latest version. We'll start by downloading, unzipping, and cleaning up the zip file of the core runtime:

sudo wget https://bintray.com/artifact/download/openhab/bin/distribution-1.7.0-runtime.zip
sudo unzip distribution-1.7.0-runtime.zip
sudo rm distribution-1.7.0-runtime.zip

Now for the addons, we'll download ALL of them into a separate folder. Later you can just copy over the ones you want (only installing the bindings you need makes OpenHAB start faster):

sudo mkdir addons_repo
cd addons_repo
sudo wget https://bintray.com/artifact/download/openhab/bin/distribution-1.7.0-addons.zip
sudo unzip distribution-1.7.0-addons.zip
sudo rm distribution-1.7.0-addons.zip

Remember how I said we can just copy over the bindings we need? We'll do that now for the MQTT binding:

cd /opt/openhab
sudo cp addons_repo/org.openhab.binding.mqtt-1.7.0.jar addons/org.openhab.binding.mqtt-1.7.0.jar

Configure MQTT Binding

Now we can start setting up OpenHAB by first creating our own copy of the config file:

sudo cp /opt/openhab/configurations/openhab_default.cfg /opt/openhab/configurations/openhab.cfg
sudo nano /opt/openhab/configurations/openhab.cfg

Scroll all the way down to the MQTT Transport section (under Transport Configurations). If you see the MQTT Persistence section, keep going. It’s further down still. Find the line with <broker>.url and <broker>.retain and activate them by removing the # sign at the start. Change them to the Mosquitto broker that's running on this very same Pi:

mqtt:mymosquitto.url=tcp://localhost:1883
mqtt:mymosquitto.retain=true
Exit & Save (the usual CTRL + X, Y, Enter).

Set Up Default Items & Sitemap

Two things left to configure:

  • Create an items file. This is the file where you tell OpenHAB about the HA stuff in your house and how to organise that stuff into groups.
  • Create a sitemap file, where you specify what you want to see on the OpenHAB site and where.

First the items file:

sudo nano /opt/openhab/configurations/items/default.items

We'll create a main group "All" with just a single "Ground Floor" and on that floor a single "Living Room":

Group All
Group gGroundFloor (All)

Group GF_Living "Living Room" <video> (gGroundFloor)

Number TestTemperature "Temperature [%.1f F]" <temperature> (GF_Living) {mqtt="<[mymosquitto:home/temperature:state:default]"}
That last line is where we tell OpenHAB about our temperature sensor. The parts are:
  • Number: the type of the value.
  • TestTemperature: a name for this item.
  • "Temperature [%.1f F]": how we want the value to be displayed. "%.1f" is a way to format a decimal number and F stands for Fahrenheit (change this to C if you're sending Celsius values).
  • <temperature>: the name of a built-in icon to display (a thermometer).
  • (GF_Living): which group this item belongs to.
  • {mqtt="<[mymosquitto:home/temperature:state:default]"}: where to get the value. This is telling OpenHAB to use the MQTT binding named "mymosquitto" (which we set up earlier) and to listen to the home/temperature channel. "state" is the type (another value is "command") and "default" is the transformation (in this case, no transformation). The < sign near the beginning means that we'll read from the channel (as opposed to writing to it).

Now create a sitemap file:

sudo nano /opt/openhab/configurations/sitemaps/default.sitemap
Where we'll just add a single page with a single frame with a single value:
sitemap default label="Main Menu"
{
        Frame label="MQTT Test" {
                Text item=TestTemperature
        }
}

Next

Start All The Things!

Start OpenHAB