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

One option is to install OpenHAB in /opt/openhab:

sudo mkdir /opt/openhab
cd /opt/openhab

Now check the OpenHAB downloads 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.

The following commands will download, unzip, and clean 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, I recommend downloading ALL of them, but 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

For example, if you want to "install" the MQTT binding you can copy it over like this:

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

Set Up Default Items & Sitemap

Before you can see and control your HA hardware in OpenHAB, you need to create two files:

  • 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.
  • A sitemap file, where you specify what you want to see on the OpenHAB site and where.

Let's start with 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 MyFirstSensor "Temperature [%.1f F]" <temperature> (GF_Living) {mqtt="<[mymosquitto:home/temperature:state:default]"}
That last line is where we tell OpenHAB about our temperature sensor. This example assumes a temperature sensor that publishes data on the home/temperature MQTT channel The parts are:
  • Number: the type of the value.
  • MyFirstSensor: 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" 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).

The second file to create is the sitemap file:

sudo nano /opt/openhab/configurations/sitemaps/default.sitemap

For now, you just have a single page with a single frame with a single value:

sitemap default label="Main Menu"
{
        Frame label="My First Sensor" {
                Text item=MyFirstSensor
        }
}

Next

Starting OpenHAB for the first time

Start OpenHAB