Installing openHAB Home Automation on Raspberry Pi

DZone 's Guide to

Installing openHAB Home Automation on Raspberry Pi

I’m currently building a home automation project around my Raspberry Pi. This article explains how to install openHab on a Rasberry Pi.

· IoT Zone ·
Free Resource

I’m currently building a home automation project around Raspberry Pi: I want to be able to monitor and control things like the lights, garage doors and the heating system both at home and from remote. I already have added a touch screen to one of my Raspberry Pi 2 computers (see Adding a Touch LCD to the Raspberry Pi 2). This article is about how to install openHAB on that Raspberry so that it can be the brain of the automation system.

openHAB Demo House on Pi

openHAB Demo House on Pi


openHAB (http://www.openhab.org/) is an open source platform which runs on many platforms for home automation. openHAB is a very flexible "concentrator" and "smart hub" for anything you can imagine: to turn on/off lights, to report temperature, to control heating systems, etc. openHAB implements a server which talks to devices with multiple protocols. And, of course, it comes with tools to configure it. Plus, there are apps available for tablets and smart phones. openHAB includes a powerful engine to parse and process messages and to perform any task implemented.

openHAB Architecture

openHAB Architecture (Source: https://github.com/openhab/openhab/wiki)

openHAB is using an Event Bus and ‘Bindings’ to communicate with everything connected to the bus:

OpenHAB Event Bus

OpenHAB Event Bus ((Source: https://github.com/openhab/openhab/wiki))


I’m using the following base hardware and software:

  1. Raspberry Pi Model 2 (while it is possible to use the model B, the model 2 is highly recommended)
  2. Linux distribution, I’m using Raspian (see “From Zero to NOOBS: Starting with Raspberry Pi Zero“)
  3. The usual USB cables, keyboard, mouse, LCD/monitor, and a power supply for the Raspberry Pi
  4. A network connection (wired or WiFi)

Update Check

openHAB is using Java. First, make sure that Java is installed with:

sudo apt-get install oracle-java7-jdk


java -version

I can check the version. For me it shows:

java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) Client VM (build 25.0-b70, mixed mode)

As a good practice before doing any larger changes, do a full update of the system while connected to the internet:

sudo apt-get update

Then do:

sudo apt-get upgrade

Installation: Runtime

*Update* installing openHAB via apt-get on Raspberry Pi leads to far fewer pitfalls and allows easy upgrade to 1.8 which is due out soon.  This is the consensus at https://community.openhab.org. A tutorial is available on the wiki.

openHAB comes in two parts: the runtime and the addons which are available on http://www.openhab.org/getting-started/downloads.html

Create the openHAB directory with:

sudo mkdir /opt/openhab

Then go to the directory with:

cd /opt/openhab

Download the Runtime core file from http://www.openhab.org/getting-started/downloads.html and place the file into the /opt/openhab folder.

Next, unzip the file with:

sudo unzip distribution*.zip

As the zip file is not needed any more, delete it with:

sudo rm distribution*.zip

Installation: Bindings (Add-Ons)

In order for openHAB to communicate with different protocols over the event bus, we need to install the bindings. For this, download the Addons from http://www.openhab.org/getting-started/downloads.html and place the zip file into/opt/openhab/addons.

Go to the addons folder:

cd /opt/openhab/addons

Extract the bindings:

sudo unzip *addons.zip

:idea: At the end, we will *not* keep all add-ons, as the more add-ons exists, the slower openHAB will start. Removing addons or bindings means to remove them from the addons folder

Then remove the zip file as it's not used any more:

sudo rm *addons.zip

Configuration File Copy

Next step makes a copy of the default configuration file:

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

The openhab_default.cfg comes with every openHAB distribution, but my personal settings are in openhap.cfg. If I update openHAB later, it will overwrite theopenhab_default.cfg. Having a copy in openhab.cfg will make sure that I keep my personal settings.

Demo Application: Demo House

To check first if openHAB is workign properly, let’s install the demo. From http://www.openhab.org/getting-started/downloads.html download the "Demo setup" (distribution-1.7.1-demo.zip) and copy it to /opt/openhab.

To speed up the demo, the original "addons" folder should be renamed, as it has many add-ons which affect performance, and items in the demo might not be updated properly. Rename to a different directory name with:

sudo mv addons addons.org

Then unzip the demo.zip with:

sudo unzip *demo.zip

As we are overwriting existing configuration files, agree to overwrite them.

As the zip file is not needed any more, it can be removed:

sudo rm *demo.zip

Starting openHAB

In case the start.sh is not executable, add the "x" executable flag to it:

sudo chmod +x start.sh

Then start openHAB with:

sudo ./start.sh

This will write a bunch of startup messages. Because we have all bindings included, that might take a minute or so.

Demo House: Web Browser

Now, with openHAB (hopefully) running, I can use a web browser to inspect it. All I need is a web browser and the IP address of the Raspberry Pi (see “Raspberry Pi Tips: IP Address“).

Then, I can use the following URL (replace the IP address with the one from your Raspberry Pi):

openHAB Demo in Web Browser

openHAB Demo in Web Browser

I can show the same thing on the Raspberry Pi itself (see “Adding a Touch LCD to the Raspberry Pi 2“):

openHAB Demo House on Pi

openHAB Demo House on Pi

openHAB supports many, many widgets, including charts:

openHAB Chart

openHAB Chart


Now, I have openHAB installed and running with a demo on my Raspberry Pi 2. That way I have an inexpensive, versatile, and flexible home automation server. In future posts I will describe how to further configure it, making it capable of communicating with Freescale (now NXP) Freedom boards or other NXP Kinetis devices.


home automation, iot, iot hardware, openhab, raspberry pi, raspberry pi 2

Published at DZone with permission of Erich Styger , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}