Introduction: Install OpenHAB on Raspberry Pi
Install latest version of openHAB on Raspberry Pi and get the demo running. For many makers, the internet of things is all about home automation. openHAB is the leading open-source home automation hub.
I struggled with openHAB's installation instructions. Home Automation for Geeks' instructions helped me get an old version running (1.7). However, I wanted to install the latest stable version.
The instructions were verified with 1.8.3, but should work for any new stable version.
In general, raspbian and debian variants use packages enabling simple installation with apt-get. However, java is operating system independent and uses zip files for installation. openHAB has apt-get install, but it didn't work for me.
Notes:
- Replace text enclosed in spades with an actual value ♣replace-this♣
- Remove spaces around the colon (https : //)
- Setup Raspberry Pi (any model) running raspbian or DietPi
- I use a MacBook but any computer can be used. I think the only change if you are using a PC, is to use putty to login and open a terminal window.
- My openHab Raspberry Pi is using ♣ip-address♣ = 192.168.1.100
Step 1: Step-by-Step Install
Step-by-step instructions follow, or go to the next step and use an unattended install to do the steps below.
Open terminal window and ssh into Raspberry Pi
$ ssh pi@♣ip-address♣
Always update and upgrade
$ cd ~/. $ sudo apt-get update $ sudo apt-get upgrade
Install java and eclipse
Check if java and eclipse are installed. If installed, then you should see /usr/bin/java or /usr/bin/eclipse. If not installed, install them
$ which java $ sudo apt-get install oracle-java8-jdk -y $ which eclipse $ sudo apt-get install eclipse -y
Install Mosquito
Remove the spaces around the colons.
$ wget http : //repo.mosquitto.org/debian/mosquitto-repo.gpg.key $ sudo apt-key add mosquitto-repo.gpg.key $ rm mosquitto-repo.gpg.key $ cd /etc/apt/sources.list.d/ $ sudo wget http : //repo.mosquitto.org/debian/mosquitto-jessie.list $ sudo apt-get update $ sudo apt-get install mosquitto mosquitto-clients
Test Mosquito
$ mosquitto_sub -d -t hello/world
Open a second terminal and ssh in
$ ssh pi@♣ip-address♣ $ mosquitto_pub -d -t hello/world -m "Hello from terminal window 2!"
The message from window 2 should appear in the first window.
Logout and close second terminal window.
CTRL-c in the first terminal window
Make directories
$ ssh pi@♣ip-address♣ $ sudo mkdir /opt $ sudo mkdir /opt/openhab $ sudo chmod -R ugo+rw /opt/openhab
Get links to latest version of openHAB
On MacBook (or PC):
- open browser
- open text file
In browser, go to openHAB downloads page and copy the following links to text file:
- Runtime core
- Addons
- Demo setup
To copy a link on a MacBook, hold CTRL and click on link, then select Copy Link
Paste each link into text file. You will see something like this:
CTRL-Click on Download and Edit Link. Select the link, copy it and paste it to text file. You will see something like this:
https : //bintray.com/artifact/download/openhab/bin/distribution-1.8.3-runtime.zip
Remember to remove spaces around the colon.
As of 27MAY2016, the current openHab links for the stable release 1.8.3 are:
♣runtime-core♣ = ♣https : //bintray.com/artifact/download/openhab/bin/distribution-1.8.3-runtime.zip♣
♣addons♣ = ♣https : //bintray.com/artifact/download/openhab/bin/distribution-1.8.3-addons.zip♣
♣demo-setup♣ = ♣https : //bintray.com/artifact/download/openhab/bin/distribution-1.8.3-demo.zip♣
Download latest version of openHAB
Run the following commands using links and names from above
$ cd /opt/openhab $ sudo wget ♣runtime-core♣ $ ls ♣runtime-core-zip-file♣ $ sudo unzip ♣runtime-core-zip-file♣ $ sudo rm ♣runtime-core-zip-file♣ $ cd /opt/openhab/addons $ sudo wget ♣addons♣ $ ls ♣addons-zip-file♣ $ sudo unzip ♣addons-zip-file♣ $ sudo rm ♣addons-zip-file♣ $ cd .. $ sudo wget ♣demo-setup♣ $ ls ♣demo-setup-zip-file♣ $ sudo unzip ♣demo-setup-zip-file♣ $ sudo rm ♣demo-setup-zip-file♣ $ sudo chmod +x start.sh
Start openHAB running
$ cd /opt/openhab $ sudo ./start.sh
openHAB takes about 5 minutes to start
In the browser, open a new tab and go to (remove spaces around colon):
http : //♣ip-address♣:8080/openhab.app?sitemap=demo
And it should work!
However, openHAB should really start and run on boot.
Stop openHAB
CTRL-z to stop openHAB. I haven't figured out how to recover from stopping openHAB. The only way to get openHAB to work after stopping is to reboot.
Add username and password
$ sudo nano /opt/openhab/configurations/users.cfg
and add the following line, replacing names in spades with real values. Even though I am using diet-pi, I created a pi username.
user=password,user,role ♣username♣=♣password♣
Add MQTT binding
$ cd /opt/openhab/configurations $ sudo cp openhab_default.cfg openhab.cfg $ sudo nano openhab.cfg
CTRL-w to search for mqtt and uncomment the lines and edit to look like:
mqtt:broker.url=tcp://localhost:1883 mqtt:broker.clientId=openhab
Use localhost and not your ♣ip-address♣. DHCP might change the ip-address and localhost will keep up with these changes.
CTRL-o, ENTER, CTRL-x to write and exit nano editor
Start openHAB on boot
Unless running an old version of raspbian, don't use init.d. Diet-Pi and raspbian use systemd, which is is a linux init system to bootstrap user space and manage processes. To check if systemd is being used, enter the command:
$ ps -p 1 -o comm= systemd
Make system directory if it doesn't exist and create a start-up file
$ sudo mkdir /usr/lib/systemd/system $ sudo nano /usr/lib/systemd/system/openhab.service
And add
[Unit] Description=openHAB Home Automation Bus Documentation=http://www.openhab.org Wants=network-online.target After=network-online.target [Service] Type=simple GuessMainPID=yes User=pi ExecStart=/opt/openhab/start.sh ExecStop=kill -SIGINT $MAINPID Restart=on-failure WorkingDirectory=/opt/openhab [Install] WantedBy=multi-user.target
To save and exit: CTRL-o, ENTER, CTRL-x
Change owner recursively on openhab.
$ sudo chown -R pi:pi /opt/openhab
Reload systemd to make the daemon aware of the new configuration.
$ sudo systemctl --system daemon-reload $ cd /usr/lib/systemd/system $ sudo systemctl enable openhab.service $ sudo systemctl start openhab.service $ sudo reboot
Fix any issues in the logs. To see the log, enter the command:
$ sudo journalctl -f -u openhab.service
CTRL-c to stop
$ sudo reboot
openHAB takes about 5 minutes to start
In the browser, open a new tab and go to
http : //♣ip-address♣:8080/openhab.app?sitemap=demo
And it works!
Step 2: Unattended Install of OpenHAB Demo
Make openHAB Demo Installation very easy by automating the previous step using a bash unattended install script. The script assumes a raspberry pi running raspbian or dietpi, which was setup using one of the embedded links.
I finished the script on github and
- tested the source on dietpi
- tested unattended install script on dietpi
- ran one time
- ran multiple times, with CTRL-c interrupts
The script assumes the username = pi, and the password = raspberry, and the script is trying to install openHAB 1.8.3. If these aren't correct, then edit the file accordingly.
Open terminal window on a MacBook or PC and run the following commands:
$ ssh pi@♣ip-address♣ $ sudo wget "https://raw.githubusercontent.com/dumbo25/install-openhab-demo/master/openhab_uai.sh" $ sudo chmod o+x openhab_uai.sh $ sudo bash openhab_uai.sh $ sudo reboot
The script takes about ten minutes to run onraspbian.
Be sure to reboot the Raspberry Pi and wait 5 minutes until openhab starts
And it should work!
Once it works, be sure to change the hostname and password.

Participated in the
Internet of Things Contest 2016
48 Comments
Question 5 years ago on Introduction
Hi. Thanks for the instructable, I really appreciate you taking the time to write it. This is the first project for my RPi 2b which has been sitting around patiently for two years waiting for me to get inspired; the posibility of a 'free' home automation hub is what encouraged me to try this out.
Unfortunately I'm having quite a lot of problems just getting OH installed. Most of the errors I'm getting seem to be permission related. I'm going to try a 'from-scratch' approach and flash NOOBS again to see if it helps but is there something else I can try if that doesn't work?
I've tried running as root instead of pi but still the same. I can create directories but then can't write to them. I can't even get past the first line on your instructable because when I ssh I get 'connection refused' lol
Thanks.
6 years ago
Got it. Used unattended install and it worked great. Thanks.
6 years ago
Dont misunderstand, I think you did a great instructable, but after a few days experience with openhab, I get more and more frustrated by the application. Apart from what I mentioned earlier there is just another problem with it every time I try it. Not anything that I would trust my house to. Dont want to come from holiday home and find the heating up to 30 degrees, all the lights on and my alarm not functioning.
I sure hope your experience with it is better
Reply 6 years ago
I am a bit insane. Before I start on an instructable, I make a list of my requirements and then do a search for all possible solutions. Some solutions I throw out before I get too deep because they don't meet my requirements. Of those solutions remaining, I try to implement each one to some level. I'll start a draft instructable for each solution, and then at some point give up on it because it is more problematic than helpful. I then move on to the next one.
I am sorry that OpenHab is not working for you.
I found that OpenHab was confusing to install and get running, which is why I wrote the instructable. However, OpenHab meets my requirements and seems to be the most extensible home automation solution and works with my other home automation stuff: garage door opener, security system, Ring, Nest, OpenSprinkler, Echo, etc. I haven't done lights yet.
Yes, I agree there are issues. At about 2am one night, my garage door opened and then the security alarm went off when the door between the house and garage was apparently opened. However, I am still not sure what happened. Because my dog and I were up pretty quick and outside, but there was no one around. Did someone actually try to break in, or did something just go wrong in the code? I've put in some safeguards to prevent cached commands from being executed at unexpected times, and some more messages to log events if it happens again.
There are many other DIY solutions. And, if you want to try off-the-shelf, I lean towards Samsung's SmartThings Home Automation Hub.
Reply 6 years ago
Jeff, thanks for your extensive reply. I want to be absolutely clear your install guide is the best I came across. That I have problems with openhab is absolutely not on your account.
I havent given up yet, so I may just wipe my entire TPi clean, do a fresh Raspi install and a fresh Openhab install and apart from Webmin put nothing else on it.
The people behind Openhab apparently agree that it has issues as one of the flash words for OH2 is 'less complicated to install' and 'less issues in running' (or similar words)
Not much of an 'off the shelf man' but if you have any other DIY suggestion, always interested to have a look.
Thanks again and enjoy yr day
6 years ago
Great instructable. Tnx
yet I am till now not really trilled by the combo Raspberry and Openhab.
not sure which one of the two is unreliable.
After setting it up and getting it to work.
it needed frequent restarts,sometimes just the openhab sometimes both.
and then it stopped working giving me all sorts of errors on non queriable persistence modules (e.g. rr4dj) missing Mongo databases and what have you.
I am sure there is all a reason for it but I am a simple man. If at one moment it works and then stops and can't get it to work again then obviously it isnt very stable.
I am going to try a fresh install of Raspi and openhab and see where that brings me
6 years ago
my service not started... got some error msg, how do i solve this?
sudo journalctl -f -u openhab.service
-- Logs begin at Fri 2016-11-04 12:59:30 CET. --
Nov 04 12:59:36 HOMESRV systemd[1]: Starting openHAB Home Automation Bus...
Nov 04 12:59:36 HOMESRV systemd[1]: Started openHAB Home Automation Bus.
Nov 04 12:59:36 HOMESRV systemd[1]: openhab.service: main process exited, code=exited, status=200/CHDIR
Nov 04 12:59:36 HOMESRV systemd[1]: Unit openhab.service entered failed state.
Nov 04 12:59:36 HOMESRV systemd[1]: openhab.service holdoff time over, scheduling restart.
Nov 04 12:59:36 HOMESRV systemd[1]: Stopping openHAB Home Automation Bus...
Nov 04 12:59:36 HOMESRV systemd[1]: Starting openHAB Home Automation Bus...
Nov 04 12:59:36 HOMESRV systemd[1]: openhab.service start request repeated too quickly, refusing to start.
Nov 04 12:59:36 HOMESRV systemd[1]: Failed to start openHAB Home Automation Bus.
Nov 04 12:59:36 HOMESRV systemd[1]: Unit openhab.service entered failed state.
Reply 6 years ago
Also trying to change the start.h following this instructions:
https://github.com/openhab/openhab/wiki/Samples-Tr...
it doesnt help.
service openhab status
● openhab.service - openHAB Home Automation Bus
Loaded: loaded (/usr/lib/systemd/system/openhab.service; enabled)
Active: failed (Result: start-limit) since Fri 2016-11-04 14:15:00 CET; 3min 53s ago
Docs: http://www.openhab.org
Process: 577 ExecStart=/opt/openhab/start.sh (code=exited, status=200/CHDIR)
Main PID: 577 (code=exited, status=200/CHDIR)
Reply 6 years ago
From your posts, it looks like you are trying things from other sites to get openhab to work. If you are trying my instructable and it does not work, I can help.
I believe the unattended install script will fix many problems, but I have not tried it on other people's instructions. Have you tried logging into your raspberry pi and running these commands:
$ ssh pi@♣ip-address♣
$ sudo wget "https://raw.githubusercontent.com/dumbo25/install-openhab-demo/master/openhab_uai.sh"
$ sudo chmod o+x openhab_uai.sh
$ sudo bash openhab_uai.sh
$ sudo reboot
Wait about five for the raspberry pi to boot and openhab to start. Open a browser on your laptop and enter:
http://♣ip-address♣:8080/openhab.app?sitemap=demo
Be sure to replace ♣ip-address♣ with the actual raspberry pi's ip address.
Can you run the following commands and post results?
$ cat /etc/*-release
$ uname -mrs
$ ps -A | egrep -i "gnome|kde|mate|cinnamon|lxde|xfce|jwm"
Also, could you try the following command and post 100 or so lines to pastebin?
$ sudo journalctl -f
Finally, can you run this command and post the results:
$ /usr/lib/systemd/system/openhab.service
Reply 6 years ago
Thanks for ur reply.
i followed your intructions, install the latest build of Jessie, turn on VNC and after that starting ur how to.
everything was ok except the last step installing as service
this is the last execute in terminal:
currently i dont have time for reinstalling the whole openhab, because already using and configuring, testing some MQTT device on it.
Next time i will try the openhab_uai.sh install.
Here it is the other logs:
Reply 6 years ago
There is typo in this line (it should be openhab):
sudo chown -R pi:pi /opt/opanhab/
Explains the permission denied, and the issue in the first part. Running the UAI script would avoid things like this.
6 years ago
Thanks a million!
I have been struggling to get it to install and run for the past few days...
I am looking to connect an enocean module to my pi and everything integrated with openhab.
This is a great starting point for me.
Thanks again!
7 years ago
Odd problem I don't know how to troubleshoot.
Before installing openhab using this instructable, my pi3 connected to my ethernet just fine. After installing but before adding openhab to the boot, all was still good (and openhab worked too!). Added the openhab.service segment and it stopped connecting. removed the openhab.service and now it only connects on every other reboot.
Boot message it is hanging on is: (works every other time)A start job is running of LSB: Rais network interfaces.
How do I troubleshoot this one??
Reply 7 years ago
I am not sure I understand the issue. Is the Raspberry Pi hanging, or is your laptop unable to connect using a browser to OpenHab on the RPI? Please provide additional details.
This seems to be an incomplete statement: "Boot message it is hanging on is:" What is the message it is hanging on? A boot message seems like the raspberry pi is hanging.
Also, this doesn't look correct: "LSB: Rais network interfaces"
Are you using Wi-Fi or wired connection? If Wi-Fi on Pi3, how is it configured?
Are you using DietPi or Raspbian?
Did you try running the unattended install, it should fix whatever is wrong?
My wild guess is the openhab directory does not have the correct permissions. Some file in one of the sub-directories contains a file that cannot be read or written.
Reply 7 years ago
A couple more guesses:
* If all of the addons are installed, then it takes 5+ minutes for openhab to get to a stable state. Are you waiting long enough?
* If the raspberry pi is operating correctly, then it should work the same way on every boot. Can you measure voltage on the raspberry pi 5v and ground pins? If voltage fluctuates and drops below 4.9v, then the power supply is at issue.
7 years ago
Hi, I am new to MQTT and openHAB. By following your instructions successfully installed MQTT and openHAB on Raspberry pi 3. Thank you for the instructions.
I would like to know how to send MQTT subscribed messages to openHAB. For example client running on rpi3 has subscribed to topic /home/light1. I would like to send this to openHAB and see the status in web browser. Please guide me.
Reply 7 years ago
You have jumped ahead of me. Try posting your question to this forum
https://community.openhab.org/t/openhab-mqtt-inbou...
This forum focuses on getting mqtt inputs & outputs to display in the browser.
7 years ago
Hi, great directions. Question though, once you get the service setup for the auto reboot start how do you stop just the openhab service? then how would you restart in debug mode? i need to check out the logs in debug mode.
thanks!
Reply 7 years ago
To stop after auto reboot, try:
$ sudo systemctl stop openhab.service
I have not used debug. However, I use this command to view logs:
$ sudo journalctl -f -u openhab.service
7 years ago
But I must add, I have been playing around with OpenHAB a lot on Windows before installing it on my Pi.