Introduction: Installing OpenHAB2 on Raspberry Pi

Picture of Installing OpenHAB2 on Raspberry Pi

Please keep an eye out as we add more connect to our YouTube channels as well as here at Instructables.

John's DIY Playground at YouTube

My YouTube Channel

openHAB Community

This is an adaptation from the docs.openhab.org site as I show you how to install OpenHAB onto your Raspberry PI via the openHAB package repository. This will be a multiple part series as we (John Wills) and I (Joshua Abramson) partner on a internet of things project. The goal is to provide a guide that will produce a secure IOT implementation at your home or work.

Because of it’s low price, it’s small form factor and the low energy consumption, the Raspberry Pi is a quite popular platform for openHAB.

Prerequisites:

  • Raspberry Pi Generation 2 or newer with Raspbian installed and running with at least a 8GB SD card.
  • PuTTY- a free SSH and telnet client for Windows. (if your are using windows)

Step 1: A Little Raspbian House Cleaning

Connected via SSH, execute the Raspbian configuration menu by running sudo raspi-config. Go through the following steps:

  • Expand the file system
  • Change your password(Change the host name if you wish, e.g. “openhabpi”)
  • From the advanced menu, change the memory split for the GPU to “16”
  • Restart

As a good practice, run a full upgrade and install packages you like or need (a set of helpful packages is given as an example):

sudo apt-get update 
sudo apt-get upgrade
sudo apt-get install screen mc vim git htop

Raspbian in the latest full versions already includes the required Oracle Java 8. If you are using “Raspbian Lite” you need to install it:

sudo apt-get install oracle-java8-jdk

Step 2: Package Repository Installation

Installation through a package repository is the recommended choice on Debian/Ubuntu derivatives. Alternatively resort to the manual installation approach.

Choose between the latest Beta release or a Snapshot with all incoming contributions, rebuild on every change. As openHAB 2 is still in an evolving state, the snapshot may be the preferred choice.

The repository URLs will be stored in the file /etc/apt/sources.list.d/openhab2.list. Be careful to not have conflicting repositories in your sources list.

Decide between two options: (We are proceeding with Snapshot instead of Beta)

Snapshot Release

Add the openHAB 2 Snapshot repositories to your systems apt sources list (will overwrite your existing openhab2.list):

**Updated 11-27-16** Thanks webcompanion

echo 'deb https://openhab.ci.cloudbees.com/job/openHAB-Distribution/ws/distributions/openhab-offline/target/apt-repo/ /' | sudo tee /etc/apt/sources.list.d/openhab2.list
echo 'deb https://openhab.ci.cloudbees.com/job/openHAB-Distribution/ws/distributions/openhab-online/target/apt-repo/ /' | sudo tee --append /etc/apt/sources.list.d/openhab2.list

Additionally, you need to add the openHAB 2 Snapshots repository key to your package manager:

wget -qO - 'http://www.openhab.org/keys/public-key-snapshots.asc' | sudo apt-key add -

Note: CloudBees provides the openHAB 2 repositories through HTTPS. If your system fails at the next step, install the missing dependency:

sudo apt-get install apt-transport-https

**Updated 11-27-16** Some are reporting an error after the command above; however, it appears to work after the second attempt.

*Added 11-27-16** Scan the newly added repository and resynchronize the package index:

sudo apt-get update

Finally install openHAB 2 as either offline or online distribution. The offline distribution is full blown and comes with all add-ons, the online distribution will install additional add-ons on request from the internet. We are going with offline here.

sudo apt-get install openhab2-offline

If everything went well, start openHAB and register it to be automatically executed at system startup: Linux init systems based on sysVinit (e.g. Debian 7 / Ubuntu 14.x and earlier):

sudo /etc/init.d/openhab2 start
sudo /etc/init.d/openhab2 status
sudo update-rc.d openhab2 defaults

The first start may take up to 15 minutes, this is a good time to reward yourself with hot coffee or a freshly brewed tea!

Step 3: OpenHab First Run Test

Picture of OpenHab First Run Test

You should be able to reach the openHAB 2 portal at http://openhab-device-ip:8080 at this point.

To get the openhab-device-ip type this command

ifconfig

You could also capture the openhab-device-ip from the IP given as you SSH into the Raspberry PI at first login of Putty. In my case the IP is 10.104.10.109, therefore I will check to see if openHAB is running by going to

http://10.104.10.109:8080 in my favorite browser.

Step 4: OpenHAB As a Service

In my case the openHAB did not setup as a service which allows openHAB to auto-start as the Raspberry Pi boots up. Here are the steps if you experience the same issue.

The following instructions are intended for a Linux init system based on systemd (e.g. Debian 8 / Ubuntu 15.x and newer). This will allow you to register openHAB as a service, so that it runs at startup and automatically restarts if openHAB crashes. The service will be running with the privileges of the user “openhab” and expects the openHAB files under /usr/share/openhab2.

Check to make sure the file /lib/systemd/system/openhab2.service exists

sudo nano ./usr/lib/systemd/system/openhab2.service

If not, create the file /lib/systemd/system/openhab2.service with the following content:

[Unit]
Description=The openHAB 2 Home Automation Bus Solution
Documentation=http://docs.openhab.org
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=openhab
Group=openhab
GuessMainPID=yes
WorkingDirectory=/usr/share/openhab2
#EnvironmentFile=/etc/default/openhab2
ExecStart=/usr/share/openhab2/start.sh server
ExecStop=/bin/kill -SIGINT $MAINPID
Restart=on-failure

[Install]
WantedBy=multi-user.target

Next, enable the service to be executed on system startup, start the service and retrieve status information:

# initialize the new service (execute only once)

sudo systemctl daemon-reload 
sudo systemctl enable openhab2.service

#start and retrieve status

sudo systemctl start openhab2.service
sudo systemctl status openhab2.service

The output of status after a successful execution should be similar to:

openhab2.service - The openHAB 2 Home Automation Bus Solution Loaded:
loaded (/lib/systemd/system/openhab2.service; enabled)
Active: active (running) since Thu 2016-08-14 01:16:00 GMT; 18h ago
Docs: http://docs.openhab.org

Step 5: Playing With Demo (To Get That Instant Gratifcation for All Your Hard Work)

This tutorial will stop at this step..... for now.

I'll add more as John and I progress through this project.

The demo package consists of example configuration files and samples of add-ons and UIs. In order to install the demo, you must edit the file ‘/etc/openhab2/services/addons.cfg’. Uncomment the line package= and set it to demo as shown below:

 sudo nano /etc/openhab2/services/addons.cfg
# The base installation package of this openHAB instance (default is "standard") 
# Valid options:
# - minimal : Installation only with dashboard, but no UIs or other addons
# - standard : Typical installation with all standards UIs
# - demo : A demo setup which includes UIs, a few bindings, config files etc.
#package = standard
package = demo
...

Step 6: Watch the Video.

Comments

JackT23 made it! (author)2017-10-16

Sweet all works great using the iPhone app together with the web interface running on my mac and it works a treat in the demo version, changes are almost instant appearing on both platforms.

Thanks for the Tutorial.

instrbles37568 (author)2016-11-27

I've updated the tutorial based on your comments. Thank you for taking your time to post this.

Hi, thanks for the intractable but again the package openhab offline is not available:

Unable to locate package openhab2-offline

Can you update your procedure?

Thank you

rkeith3 (author)2017-02-12

Yes, it looks like things have moved on recently. I used:

echo 'deb http://dl.bintray.com/openhab/apt-repo2 stable main' | sudo tee /etc/apt/sources.list.d/openhab2.list

to use the current stable release of openHab2. Then:

sudo apt-get update

They have also changed online/offline. For on- or off-line, use the following:

sudo apt-get install openhab2

For an offline installation, also do this, to download all the add-ons upfront:

sudo apt-get install openhab2-addons

Found this info here: http://docs.openhab.org/installation/linux.html#package-repository-installation

snacktastic (author)2017-01-19

Apparently, the files have been moved from cloudbee to bintray

I was getting W: Failed to fetch https://openhab.ci.cloudbees.com/job/openHAB-Dist... HttpError404

I found the updated path at

https://github.com/openhab/openhab-distro/issues/3...

echo 'deb http://dl.bintray.com/openhab/apt-repo2 unstable main' | sudo tee /etc/apt/sources.list.d/openhab2.list
wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=openhab' | sudo apt-key add -
sudo apt-get update

then to offline install...

rbhautom (author)2017-01-01

After the following line:

wget -qO - 'http://www.openhab.org/keys/public-key-snapshots.asc' | sudo apt-key add

I get the following error:

gpg: no valid OpenPGP data found

Please help

CaptBornel (author)2016-12-19

Every thing worked perfectly. I am up and running in demo mode. I can't wait for the second part of the video. Well done. I finally figured out how to cut and paste the command lines and that made all the difference in the world.

jamesdelelio (author)2016-11-23

Hi,

I ran into the following error (on a freshly installed raspberry 4.1.19-v7+) when following your instructions:

pi@raspberry:~$ sudo apt-get install apt-transport-https
E: Malformed entry 1 in list file /etc/apt/sources.list.d/openhab2.list (URI parse)
E: The list of sources could not be read.
E: Malformed entry 1 in list file /etc/apt/sources.list.d/openhab2.list (URI parse)
E: The list of sources could not be read.

Can you please tell me what is going wrong and maybe update your instructions?

kind regards

I experienced the same error as you jamesdelelio. What I did to fix it was a little weird, I just put the same command into the console, "sudo apt-get install apt-transport-https" and then for some reason the command works the second time. And actually the system (I'm using a Pi3) reports that nothing is upgraded or installed, it's just checking to upgrade and nothing is actually done.

So now I edit the openhab2.list file manually using "sudo nano /etc/apt/sources.list.d/openhab2.list"

I edit the lines of code to look like this:


deb https://openhab.ci.cloudbees.com/job/openHAB-Distribution/ws/distributions/openhab-offline/target/apt-repo/ /

deb https://openhab.ci.cloudbees.com/job/openHAB-Distribution/ws/distributions/openhab-online/target/apt-repo/ /

Save and close.  Retry command "sudo apt-get install openhab2-offline".  Error says Unable to locate package openhab2-offline.

For kicks, doing a "sudo apt-get update" and then "sudo apt-get upgrade".  Looks like it is going to to check cloudbees during the update command.  Nothing changes for "upgrade".  Reboot.

Now after reboot, issue the command "sudo apt-get install openhab2-offline".  It works!!!!!!

Post updated.. Thanks

About This Instructable

18,627views

57favorites

License:

More by instrbles37568:Quick and Easy ESP8266 Plug Via OpenHABIntro - Creating a PCB board for the Moteino (design, etching, and soldering)Installing openHAB2 on Raspberry Pi
Add instructable to: