OpenHAB on Raspberry Pi





Introduction: OpenHAB on Raspberry Pi

About: I am a life long biz owner. I've been fortunate enough to have a successful business and a fun life.

NOTE: Updated 6/4/16 This instructable is outdated. It can certainly be of assistance but please also checkout Jeff's instructable below. Two little babies can suck the free time right out of you.

This instrucable covers how to download and install openHAB on your Raspberry Pi through the command line. I also go one step further and show you how to configure your openHAB to load at boot.

As many of you may know openHAB is a server system design to integrate the myriad of available home automation gadgets in the market and control them with one single interface. You can do away with all of the apps that come with each individual gadget and have one central control.

I understand that many people haven't taken the plunge to use openHAB simply because they think it is too complex. I put this instructable together so others can see that there is really nothing to it. I myself had a few issue when I was installing openHAB so I thought others might find this helpful.

Step 1: Downloading and Installing OpenHAB on Pi

Its always good practice to be certain you are working with the latest updated software packages so lets begin with this:

sudo apt-get updatesudo apt-get upgrade

Certain apps may require you to update the firmware but typically its not a requirement. I suggest to do it anyway.

sudo rpi-update

You can use any kind of way that you would like to copy files to your Pi. I choose to do download them. I also like to download them directly to the folder that I will be extracting them from. I then do some housekeeping and remove the unnecessary zip file. First lets make the folders we need.

sudo mkdir /opt/openhab

You will then want to download the latest release to that folder. You can do that by going to the openHab downloads page and right clicking on the runtime core download and copying the link address to get the latest version. You can then replace the url below with the one you copied.

cd /opt/openhab


Ok, lets install this b*tch. The zip files that you downloaded should be extracted to the correct location already. If your not already there go to the openhab folder and extract the runtime zip file there.

cd /opt/openhabsudo


Lets now remove the zip file which will no longer be needed.


Great, the runtime is installed and the zip files erased, but in order for openHAB to work you will need to add bindings. Upon extrating the runtime zip a "addons" folder was created. All bindings belong in this folder. Go to the addons folder and extract the addons zip. First lets download them to the appropriate folder.

cd addons/


This contains all the bindings available for openHAB. As stated in the openHAB wiki, Bindings are optional packages that can be used to extend functionality of openHAB. By help of bindings openHAB users can e.g. access Asterisk communications software or connect to the KNX Home Automation Bus.

Lets just install all of them and later we can sift through and decide which one we keep. You simply remove the .jar file from the addons folder.
sudo unzip
Remove or erase the zip file.

Next lets go back one folder to the openhab folder and make a copy of the "openhab_default.cfg" file. You will call the copy "openhab.cfg". In the event that you have to update your openhab the default file will be updated as well. By making a copy of this file, openhab will use this file for configurations and also not update it. Since you will be making your own custom configurations, it is important that those get written in the "openhab.cfg" file for safe keeping.

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

In order to understand how this crazy thing works I recommend deploying the demo app. Its a good way to get your foot on the ground and make some sense of this.

cd /opt/openhab


Go to the openhab folder and extract the demo zip files there.
cd /opt/openhab

sudo unzip

remove the garbage files


By default the "" script is not an executable file. Do the following in order to make it executable:

sudo chmod +x

sudo ./

And the fun begins! You should have a fully loaded demo that you can use to familiarize yourself with openHAB. Just go to your telephone or computer and place the following url in your favorite browser. Be sure to replace the ip address with the Ip address of your Pi.


Step 2: Configuring OpenHAB to Start Automatically at Boot

In the event of a power surge, outage or if you decide to restart your Pi, your OpenHAB program will need to be re-booted. That is a big pain the rear end so we will want to configure it to boot at start.

First off you will want to create a new file in the /etc/init.d folder called "openhab".

You will want to add a few lines of code to your openhab file by using the nano editor or your favorite editor of choice.
sudo nano /etc/init.d/openhab

Add this code:
#! /bin/sh<br>### BEGIN INIT INFO # Provides: openhab # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: OpenHAB Daemon ### END INIT INFO# Author: Thomas Brettinger# Do NOT "set -e"# PATH should only include /usr/* if it runs after the script PATH=/sbin:/usr/sbin:/bin:/usr/binDESC="Open Home Automation Bus Daemon" NAME=openhab DAEMON=/usr/bin/java PIDFILE=/var/run/$ SCRIPTNAME=/etc/init.d/$NAME ECLIPSEHOME="/opt/openhab"; HTTPPORT=8080 HTTPSPORT=8443 TELNETPORT=5555 # be sure you are adopting the user to your local OH user RUN_AS=pi# get path to equinox jar inside $eclipsehome folder cp=$(find $ECLIPSEHOME/server -name "org.eclipse.equinox.launcher_*.jar" | sort | tail -1);DAEMON_ARGS="-Dosgi.clean=true -Declipse.ignoreApp=true -Dosgi.noShutdown=true -Djetty.port=$HTTPPORT -Djetty.port.ssl=$HTTPSPORT -Djetty.home=$ECLIPSEHOME -Dlogback.configurationFile=$ECLIPSEHOME/configurations/logback.xml -Dfelix.fileinstall.dir=$ECLIPSEHOME/addons -Djava.library.path=$ECLIPSEHOME/lib$ECLIPSEHOME/etc/login.conf$ECLIPSEHOME/etc/ -Djava.awt.headless=true -jar $cp -console ${TELNETPORT}"# Exit if the package is not installed [ -x "$DAEMON" ] || exit 0# Read configuration variable file if it is present [ -r /etc/default/$NAME ] && . /etc/default/$NAME# Load the VERBOSE setting and other rcS variables . /lib/init/ Define LSB log_* functions. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present # and status_of_proc is working. . /lib/lsb/init-functions# # Function that starts the daemon/service # do_start() { # Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started start-stop-daemon --start --quiet --make-pidfile --pidfile $PIDFILE --chuid $RUN_AS --chdir $ECLIPSEHOME --exec $DAEMON --test > /dev/null \ || return 1 start-stop-daemon --start --quiet --background --make-pidfile --pidfile $PIDFILE --chuid $RUN_AS --chdir $ECLIPSEHOME --exec $DAEMON -- $DAEMON_ARGS \ || return 2 # Add code here, if necessary, that waits for the process to be ready # to handle requests from services started subsequently which depend # on this one. As a last resort, sleep for some time. return 0 }# # Function that stops the daemon/service # do_stop() { # Return # 0 if daemon has been stopped # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME RETVAL="$?" [ "$RETVAL" = 2 ] && return 2 # Wait for children to finish too if this is a daemon that forks # and if the daemon is only ever run from this initscript. # If the above conditions are not satisfied then add some other code # that waits for the process to drop all resources that could be # needed by services started subsequently. A last resort is to # sleep for some time. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON [ "$?" = 2 ] && return 2 # Many daemons don't delete their pidfiles when they exit. rm -f $PIDFILE return "$RETVAL" }# # Function that sends a SIGHUP to the daemon/service # do_reload() { # # If the daemon can reload its configuration without # restarting (for example, when it is sent a SIGHUP), # then implement that here. # do_stop sleep 1 do_start return 0 }case "$1" in start) log_daemon_msg "Starting $DESC" do_start case "$?" in 0|1) log_end_msg 0 ;; 2) log_end_msg 1 ;; esac ;; stop) log_daemon_msg "Stopping $DESC" do_stop case "$?" in 0|1) log_end_msg 0 ;; 2) log_end_msg 1 ;; esac ;; status) status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? ;; #reload|force-reload) # # If do_reload() is not implemented then leave this commented out # and leave 'force-reload' as an alias for 'restart'. # #log_daemon_msg "Reloading $DESC" "$NAME" #do_reload #log_end_msg $? #;; restart|force-reload) # # If the "reload" option is implemented then remove the # 'force-reload' alias # log_daemon_msg "Restarting $DESC" do_stop case "$?" in 0|1) do_start case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 ;; # Old process is still running *) log_end_msg 1 ;; # Failed to start esac ;; *) # Failed to stop log_end_msg 1 ;; esac ;; *) #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 exit 3 ;; esac :

You can also go here to see the readable version or you can copy and paste the code from there.

You may need to change the RUN_AS=pi to your current user.

Lastly you will want to make this an executable file.
sudo chmod a+x /etc/init.d/openhab

And for it to automatically boot at the start of Pi
sudo update-rc.d openhab defaults

If you get an error that looks like this:
insserv: Script openhab is broken: incomplete LSB comment. insserv: missing `Provides:' entry: please add. insserv: missing `Required-Start:' entry: please add even if empty. insserv: missing `Required-Stop:' entry: please add even if empty. insserv: missing `Default-Start:' entry: please add even if empty. insserv: missing `Default-Stop:' entry: please add even if empty. insserv: Default-Start undefined, assuming empty start runlevel(s) for script `openhab' insserv: Default-Stop undefined, assuming empty stop runlevel(s) for script `openhab'

Then you have an indentation problem. Sometimes upon pasting into your editor the text gets placed into an easy to read format which places indentations into some of the initial lines of code. Any information that is written for update-rc.d must be in first column. And there should not be any tabulation or space before the "#". If there are any remove them or you will generate that error.

Go back to your file and double check.
sudo nano /etc/init.d/openhab

The first few columns should look like this (DO NOT COPY AND PASTE, CONTAINS ASCII CHARACTER SPACING) just use it as a visual example:

#! /bin/sh

# Provides: openhab
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OpenHAB Daemon

Notice how there are no spaces or indents before each # sign.

Complete, your Raspberry Pi will now boot openHAB at start.

Step 3: Extras (Admin Console)

There is a cool Admin Console for openHAB called HABmin. Its great for performing administrative tasks as well as configuring various procedures. Google it and decide whether or not its right for you. Its quite easy to install. If you are interested I have created an instructable on how to install it here.



  • Creative Misuse Contest

    Creative Misuse Contest
  • Clocks Contest

    Clocks Contest
  • Oil Contest

    Oil Contest

39 Discussions

I had varying success getting openhab to fully work using different sites. Each site had something different and something wrong. Since your tutorial was that last I could find, I decided to diagnose and fix the problem here. The auto start script was not starting openhab. It turns out that during boot, the user is root, not pi. So to fix this, in the auto start script, I changed RUN_AS=pi to RUN_AS=root. That fixed the start problem, but then you must use sudo when using the script at runtime:

sudo /etc/init.d/openhab status
sudo /etc/init.d/openhab stop
sudo /etc/init.d/openhab start

BTW, I installed openhab v1.8.3 using:
sudo mkdir /opt/openhab
cd /opt/openhab
sudo wget
sudo unzip
sudo rm

cd /opt/openhab
sudo mkdir addons_repo
cd addons_repo
sudo wget
sudo unzip
sudo rm

cd /opt/openhab
sudo rm


I got a response of "update-rc.d: using dependency based boot sequencing" and that is fine.

The fact that it says that it can't see your directory tells me there's still a permissions problem. Is it set up to run as user pi? If so this should fix that:
sudo chown -hR pi:pi /opt/openhab

or if running as say, bananapi then this:
sudo chown -hR bananapi:pi /opt/openhab

And of course you already did this I guess: sudo chmod a+x /etc/init.d/openhab

The answer was that the openHAB files had owner of root. Doing a chown to make them pi pi made it come to life.

7 replies

Can you elaborate on the steps you performed to allow it to auto-start? I am using pi as the user also. Not a heavy user in linux, I know enough to get me headaches. Thanks in advance.

Did you reboot your Pi and allow ample time for openhab to boot up? Did you also follow the others recommendation of "chown"? Lastly are you able to start and stop openhab manualy by " /etc/init.d/openhab start" or "/etc/init.d/openhab stop"?

I am having the same problem "using dependency based boot sequence" I did all of the other recommendation of chown. i am unable to start and stop openhab manually. it tells me that no such directory exists. yet if i drill down to the path i see openhab. if when i am in the init.d dir and type in openhab it says command not found. sorry to be a noob. not sure where to go from here

Thought I actualIy performed a chown. A little research on how to verify (ls -l /opt/openhab) and now it works like a charm! Know of any good light reading on using Arduino Micros as senders to this Rpi receiver would be appreciated and thanks for the kickstart!

What command did you use to change the ownership, and did you do any additional commands? I used:

sudo chown pi /etc/init.d/openhab

sudo update-rc.d openhab defaults

and still received the message "update-rc.d: using dependency based boot sequencing" and still can't get it to run at startup.


Use this on your configuration files to make your owner & group pi: : sudo chown -hR pi:pi /opt/openhab

That is the correct message from your update command.

Use the startup script from here:

You need to remove the 3 spaces from the start of each line for it to work properly.

Thank you shedzong! I just added the github link to the instructable in case it is helpfull others.

I was not able to make this work. I suspect that it could be related to me not really being able to edit and transfer text files correctly. Instead I just used pico to edited the file


and added this line towards the end:

sudo /opt/openhab/

And it works perfectly. Also I did remember to remove the openhab file and do a remove with update-rc.d

Would you care to let me know the pros and cons for doing the autostart this much simpler way?

Cheers and Thanks from Copenhagen

2 replies


I also had an issue and I spent hours trying to fix the script with no success. Finally I found the site below, when copying that script provided in the article, it worked. I would explain the differences but the scripts are very different but I can confirm it worked for me. I am running a Raspberry Pi 2 with NOOB.

In an effort to ensure this is not lost if the link dies, here is the script:

# Provides: openhab
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OpenHAB Daemon
# Description: Build your smart home in no time!
# set path to eclipse folder. If local folder, use '.'; otherwise, use /path/to/eclipse/
# set ports for HTTP(S) server
# get path to equinox jar inside $eclipsehome folder
cp=$(find $eclipsehome -name "org.eclipse.equinox.launcher_*.jar" | sort | tail -1);
# This next line determines what user the script runs as.
# Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python.
DAEMON_ARGS="-Djna.boot.library.path=/usr/lib/jni -Dosgi.clean=true -Declipse.ignoreApp=true -Dosgi.noShutdown=true -Djetty.port=$HTTP_PORT -Djetty.port.ssl=$HTTPS_PORT -Djetty.home=. -Dlogback.configurationFile=configurations/logback.xml -Dfelix.fileinstall.dir=addons -Djava.library.path=lib -Dequinox.ds.block_timeout=240000 -Dequinox.scr.waitTimeOnBlock=60000 -Djava.awt.headless=true -jar $cp $* -console "
. /lib/lsb/init-functions

do_start() {
log_daemon_msg "Starting system $DAEMON_NAME daemon"
start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --chdir $ROOT_DIR --exec $DAEMON -- $DAEMON_ARGS
log_end_msg $?
do_stop() {
log_daemon_msg "Stopping system $DAEMON_NAME daemon"
start-stop-daemon --stop --pidfile $PIDFILE --retry 10
log_end_msg $?

case "$1" in



status_of_proc "$DAEMON_NAME" "$DAEMON" && exit 0 || exit $?
echo "Usage: /etc/init.d/$DAEMON_NAME {start|stop|restart|status}"
exit 1

exit 0

Just for other noobs like me trying to do this: The remove command is:

sudo update-rc.d openhab remove

sudo rm /etc/init.d/openhab

And remember to put an "&" at the command end (before exit 0) in /etc/rc.local like this

sudo /opt/openhab/ &

the god way to iinstall it :

Hi, do I have to have root privilege? I've a permission denied when I try to write distribution 1-5-1 Sorry, dummy with linux...

1 reply

I am new to Linux and the Raspberry Pi, but trying desperately to get OpenHAB working and am getting this error:


Problem accessing / Reason:

    Sitemap '"demo"' could not be found

Caused by:

org.openhab.ui.webapp.render.RenderException: Sitemap '"demo"' could not be found 
at org.openhab.ui.webapp.internal.servlet.WebAppServlet.service(
at org.eclipse.equinox.http.servlet.internal.ServletRegistration.service(
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.eclipse.jetty.servlet.ServletHolder.handle(
at org.eclipse.jetty.servlet.ServletHandler.doHandle(
at org.eclipse.jetty.server.session.SessionHandler.doHandle(
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(
at org.eclipse.jetty.servlet.ServletHandler.doScope(
at org.eclipse.jetty.server.session.SessionHandler.doScope(
at org.eclipse.jetty.server.handler.ContextHandler.doScope(
at org.eclipse.jetty.server.handler.ScopedHandler.handle(
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(
at org.eclipse.jetty.server.handler.HandlerCollection.handle(
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(
at org.eclipse.jetty.server.Server.handle(
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(
at org.eclipse.jetty.http.HttpParser.parseNext(
at org.eclipse.jetty.http.HttpParser.parseAvailable(
at org.eclipse.jetty.server.AsyncHttpConnection.handle(
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(
at org.eclipse.jetty.util.thread.QueuedThreadPool$

I am willing to pay someone who can tutor who help me with this, as I am trying to get an aeotec Z-stick gen5 working with a few z-wave sensors (after I can get some headway). you can contact me at Thanks in advance.


I installed Openhab and mosquitto on the pi. Can somebody help me with proceeding further? I am more interested in controlling outputs than reading data. Thanks in advance

First, congratulations for this incredible tutorial, it is very helpful

The first terminal command is wrong, the command is duplicate,
sudo apt-get updatesudo apt-get upgrade

it s just: sudo apt-get update

Well I see some problem with the /opt/openhab files which should be allocated to the user "pi", so once the directory /opt/openhab is created the owner should be changed to pi.

Here is the sequence I did follow (based on the last NOOBS release 1.4.0 on a Raspberry Pi2 model B).

1. Verify Java version

= = = = = = = = = = =

java -version

#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)

if not OK see

2. Install OpenHab by following step 1

= = = = = = = = = = = = = = = = = = =


2.1 Find the last Openhab distribution

- - - - - - - - - - - - - - - - - - - -

2.2 Summary of the actions

- - - - - — - - - - - - -

sudo mkdir /opt/openhab

sudo chown -hR pi:pi /opt/openhab # changing the directory owner here will avoid a lot of pain!




cd addons




cd /opt/openhab

cp configurations/openhab_default.cfg configurations/openhab.cfg



## Archive:

## replace addons/org.openhab.binding.http-1.6.2.jar? [y]es, [n]o, [A]ll, [N]one, [r]ename: A


chmod +x


2.3 Check connection

- - - - - - - - - - -

http://<host IP>:8080/