openHAB 2 and 3 Installation - Start to Finish

Hello openHAB community.

During my time implementing my Raspberry Pi based home automation system I had to re-install openHAB and various related software and bindings numerous times.

Since I’m not a Linux expert (more the windows type of guy) I found it very hard to remember all the steps neccessary in that process hence, to speed up the re-installation process, I’ve created a guide outlining all steps neccessary starting from preparing the SD-card (or SSD) holding the operating system for the raspberry Pi thru installation and configuration of openHAB 2 and now 3, including the MySensors Binding (also for OH3), frontail LogViewer, Samba file sharing, remote desktop client, InfluxDB and Grafana and some more.

I thought it might be useful for some of you if I’d share this guide with the community which over the years helped me overcome so many challenges on the way to my now well working home automation system comprising of by now hundreds of items controling self-built mySensors devices as well as many purchased devices.

The guide focuses on the installation of the openHAB system and related software, it does not describe the configuration of my specific home automation system such as rules, items or things.

OpenHAB 2 and 3 Installation Guide for Raspberry-Pi

Hands-on step by step guide - including MySensors Binding, Frontail, InfluxDB, Grafana, Samba and Remote Desktop Client and Visual Studio Code (for Raspberry Pi)

Introduction

This document outlines the installation and (basic) configuration of the following software components:

  • Raspian operating system (Version 10 = Buster)
  • SSH access activation
  • OpenHab (Version 2.5 or 3.0)
    • Openhabian-config Tool
    • mySensors Binding for MySensors Ethernet Gateway (Version 2.5.0 oder 3.1.0)
  • Samba
  • Remote Desktop Client
  • InfluxDB
  • Grafana
  • Visual Studio Code for Raspberry Pi

Hardware

I used the following hardware:

  • Raspberry Pi 4 4GB
  • 64GB SD-Card SanDisk Extreme Pro

As additional tools I used a Windows 10 PC:

SD card preparation

The following perparation steps I performed on my Windows PC:

Download Raspbian Image

https://www.raspberrypi.org/software/operating-systems/#raspberry-pi-os-32-bit

I used verion „Raspberry Pi OS with desktop and recommended software“.

For non-Linux geegs such as I am I recommended using a version including a graphical user interface since it easily allows connecting via a remote desktop session later.

I did not try version „Raspberry Pi OS Lite“ yet.

Download „Raspbian Imager“ tool

This tool will (later) be used to write the Image onto the SD-card (or SSD)
https://www.raspberrypi.org/software/
Danach Imager Tool installieren

Raspbian Image auf SD-Karte schreiben

Start “Raspbian Pi Imager” tool.

As operating system choose: „use custom“.

Choose the downloaded image file downloaded (from the previous step) and pick the target SD-card (or SSD).

Starting the Raspberry-Pi and updating the OS software

Prepare the hardware

  • insert the SD card (or connect SSD) to the Raspberry Pi
  • connect a keyboard
  • connect a mouse
  • connect network cable (optional in case WLAN is available)
  • connect monitor

First time starting the Pi

Siwtch on the Pi by plugging in the power supply

(in case you see a blitzard icon in the top right corner of the screen your power supply is no good - you may be able to proceed but it’s recommended to replace the power supply by a different/better device)

Apply initial setting for the operating system

The operating system is booting and will ask for some initial settings such as country, language, keyboard layout, graphical user interface and wireless network connection as well as a new password for the default user “pi”.
Remember the password you set for user pi!

Initial updating of the operating system

Next the system download updates from the internet and applies those - this process may take quite a while (approx. 15 minutes in my case).

After applying all updates I recommend rebooting the Raspberry Pi.

Activating the SSH access

Prior to being able to access the Raspberry Shell e.g. via putty from a different computer the SSH access needs to be activated.

Therefore start a Terminal session on your raspberry an enter the following commands:

sudo systemctl enable ssh

sudo systemctl start ssh

Installing OpenHAB

The steps outlined in this chapter basically follow those described here:

https://www.openhab.org/docs/installation/rasppi.html

I’ve entered all commands directely in the “Terminal” on the Raspberry Pi, alternatively it’s possible to do the same via an SSH-connection from a different computer to the Raspberry Pi.

Preparation

Installing some tools

sudo apt-get install screen mc vim git htop

Java

Attention:
Checking or replacing the java version (as described in this paragraph and its sub chapters) was necessary in some of my earlier installation attemps (end of 2018/beginning of 2019).
Since approx. mid 2020 I did not experience any issues with the installed java version and did not perform the steps described here anylonger - instead proceed to chapter “OpenHAB installation” below!

Checking the java version

java -version

Sample output for a installed Java version 11:
openjdk version „11.0.7“ 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Raspbian-3deb10u1)
OpenJDK Server VM (build 11.0.7+10-post-Raspbian-3deb10u1, mixed mode)

Sample output for no Java version installed:

Bash: /usr/bin/java: No such file or directory

Installing Java

OpenHAB 2.x requires Java 8 revision 161 or higher.

I’ve installed Java distribution openjdk Version 8 (I never successfully managed to install Zulu or Oracle Java):

sudo nano /etc/apt/sources.list

Add at the end of each line:

deb Index of /debian buster main

then

sudo apt-get update

Error handling

Should you run into the following error…

“The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 04EE7237B7D453EC NO_PUBKEY 648ACFD622F3D138 NO_PUBKEY DCC9EFBF77E11517”

…you’ll have to execute the following command for each PUBKEY mentioned in the error message. On each command replace the key with one of the key reffered in the error message – as for the case shown above this would be:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138

and

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DCC9EFBF77E11517

(The output of the command should look somewhat like this:

Executing: /tmp/apt-key-gpghome.jnpR0ilh2z/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC

gpg: key E0B11894F66AEC98: public key “Debian Archive Automatic Signing Key (9/stretch) <ftpmaster@debian.org>” imported

gpg: Total number processed: 1

gpg: imported: 1

)

Initiate Java installation

Update August-10, 2020: Since recently openHAB can run on Java 11, an downgrade from Java 11 to Java 8 is therefore no longer required!

sudo apt-get install openjdk-11-jdk

Specify default Java version

sudo update-alternatives --config java

Choose openjdk 11

Uninstall old Java version

Update August-10, 2020: Since recently openHAB can run on Java 11, an downgrade from Java 11 to Java 8 is therefore no longer required!

OpenHAB installation

wget -qO - ‘https://openhab.jfrog.io/artifactory/api/gpg/key/public’ | sudo apt-key add -

sudo apt-get install apt-transport-https

For openHAB version 2.x:

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

For openHAB version 3.x:

echo ‘deb JFrog stable main’ | sudo tee /etc/apt/sources.list.d/openhab.list

sudo apt-get update

In case you get the following error message

The following signatures couldn’t be verified because the public key is not available: BO_PUBKEY

execute the following command for each key mentioned:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys

and then again

sudo apt-get update

For openHAB version 2.x:

sudo apt-get install openhab2

sudo apt-get install openhab2-addons

Für openHAB version 3.x:

sudo apt-get install openhab

sudo apt-get install openhab-addons

Start openHAB services

For openHAB version 2.x:

sudo systemctl start openhab2.service

Check service status:

sudo systemctl status openhab2.service

For openHAB version 3.x:

sudo systemctl start openhab.service

Check service status:

sudo systemctl status openhab.service

Configure services to start automatically at reboot

sudo systemctl daemon-reload

For openHAB version 2.x:

sudo systemctl enable openhab2.service

For openHAB version 3.x:

sudo systemctl enable openhab.service

Finish/test installation

After installing openHAB it may take up to 45 minutes for the openHAB user interface to become available in a web browser!

Open the openHAB web site in a browser on the raspberry pi itself:

http://localhost:8080

Hit the “expert” button

Openhabian-config Tool

Installation

sudo git clone GitHub - openhab/openhabian: openHABian - empowering the smart home, for Raspberry Pi and Debian systems /opt/openhabian

sudo ln -s
/opt/openhabian/openhabian-setup.sh /usr/local/bin/openhabian-config

Start

sudo openhabian-config

Frontail (Log Viewer) Installation

Openhabian Config Tool starten:

sudo openhabian-config

Im openhabian-config Tool die Frontail-Installation über folgende Menüpunkte starten:

20 | Optional Components Choose from a set of optional software components

and then

21 | Log Viewer openHAB Log Viewer webapp (frontail)

Leave the openhabian-too after the frontail installation.

MySensors Binding

Many thanks to @TimO for the cool MySensors binding and its recent update for OH3!!!
You find more details on the MySensors Binding for OH3 here:

MySensors binding installation

The guide outlined here basically corresponds to the one published on Home · tobof/openhab-addons Wiki · GitHub. I added some additional details and some steps for the installtion on openHAB version 3.

Download the binding file from:

For openHAB Version 2.x:

http://www.oberfoell.com/openhab2/org.openhab.binding.mysensors-2.5.0-SNAPSHOT.jar

for openHAB Version 3.x:

http://www.oberfoell.com/openhab3/org.openhab.binding.mysensors-3.1.0.jar

(Default-Download-Ordner von Browser Chromium auf Raspberry Pi ist:
/home/pi/Downloads/)

Move the binding fatei to the AddOns folder:

For openHAB Version 2.x:

sudo mv /home/pi/Downloads/* /usr/share/openhab2/addons

For openHAB Version 3.x:

sudo mv /home/pi/Downloads/* /usr/share/openhab/addons

Start the OpenHab/Karaf console

ssh -p 8101 openhab@localhost

Default-Passwort: habopen

Install features

feature:install openhab-transport-serial

feature:install openhab-core-io-transport-mqtt

Check installation

Start the openHab/Karaf console (if not still open from previous step)

ssh -p 8101 openhab@localhost

Default-Passwort: habopen

List all installed addOn’s

bundle:list

If you see the item "MySensors Binding " and "nrjavaserial "the binding is installed properly.

Remote Desktop Client

Installation

sudo apt-get install xrdp

Grant authorization for openHAB files:

For openhab 2.x:

sudo chmod -R 777 /etc/openhab2

For openhab 3.x:

sudo chmod -R 777 /etc/openhab

Samba

Installation

Start the installation

sudo apt-get install samba samba-common-bin

Add Samba user

sudo smbpasswd -a openhab

optionallly:

sudo smbpasswd -a pi

Configuration

Setup OpenHab Samba shares

sudo nano /etc/samba/smb.conf

Append the following config at the end of the file:

Für OpenHAB Version 2.x:

[openHAB2-userdata]
comment=openHAB2 userdata
path=/var/lib/openhab2
browseable=Yes
writeable=Yes
only guest=no
public=no
create mask=0777
directory mask=0777

[openHAB2-conf]
comment=openHAB2 site configuration
path=/etc/openhab2
browseable=Yes
writeable=Yes
only guest=no
public=no
create mask=0777
directory mask=0777

[openHAB2-logs]
comment=openHAB2 logs
path=/var/log/openhab2
browseable=Yes
writeable=Yes
only guest=no
public=no
create mask=0777
directory mask=0777

For OpenHAB Version 3.x:

[openHAB-userdata]
comment=openHAB userdata
path=/var/lib/openhab
browseable=Yes
writeable=Yes
only guest=no
public=no
create mask=0777
directory mask=0777

[openHAB-conf]
comment=openHAB site configuration
path=/etc/openhab
browseable=Yes
writeable=Yes
only guest=no
public=no
create mask=0777
directory mask=0777

[openHAB-logs]
comment=openHAB logs
path=/var/log/openhab
browseable=Yes
writeable=Yes
only guest=no
public=no
create mask=0777
directory mask=0777

Restart Samba service

sudo service smbd restart

Access Samba shares from Windows

You can now acces the shares from e.g. file explorer on a windows PC
(User: openhab, Default Password: habopen):

For openHAB Version 2.x:

\\openHAB2-userdata
\\openHAB2-conf
\\openHAB2-log

For openHAB Version 3.x:

\\openHAB-userdata
\\openHAB-conf
\\openHAB-log

Influx DB

Installation

curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -

source /etc/os-release

echo ‘deb InfluxData - Package Repository buster stable’ | sudo tee /etc/apt/sources.list.d/influxdb.list

sudo apt-get update && sudo apt-get install influxdb

sudo service influxdb start

Starting the Influx Shell

At first start:

influx

Later, after setting up users:

influx -username admin -password SuperSecretPassword123+ -host localhost

Creating the Influx database and setting up users

Enter the following command in the Influx Shell:

CREATE DATABASE openhab_db

CREATE USER admin WITH PASSWORD ‘SuperSecretPassword123+’ WITH ALL PRIVILEGES

CREATE USER openhab WITH PASSWORD ‘AnotherSuperbPassword456-’

CREATE USER grafana WITH PASSWORD ‘PleaseLetMeRead789?’

GRANT ALL ON openhab_db TO openhab

GRANT READ ON openhab_db TO grafana

exit

Configuration of the InfluxDB service

Edit file /etc/influxdb/influxdb.conf as shown below:

sudo nano /etc/influxdb/influxdb.conf

Search for the passages in the file and adjust them as shown:

...
[http]
enabled = true
bind-address = ":8086" # change to a specific interface if needed
auth-enabled = true # will enforce authentication
...

Restarting the Influx service

sudo systemctl restart influxdb.service

Grafana

Installation

Add Deb package to sources:

echo ‘deb https://packages.grafana.com/oss/deb stable main’ | sudo tee /etc/apt/sources.list.d/grafana.list

Add Apt-Key for Grafana

wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -

Update Debian Buster package sources for Grafana:

sudo apt-get update

Update Debian Buster system:

sudo apt-get upgrade

Install Transport package for HTTPS support:

sudo apt-get install apt-transport-https

Install Grafana now with the following command:

sudo apt-get install grafana

Start Grafana-Server:

sudo service grafana-server start

Configure autostart for service at reboot:

sudo update-rc.d grafana-server defaults

Reload system manager configuration:

sudo systemctl daemon-reload

Restart Grafana server:

sudo systemctl start grafana-server

Check status of the Grafana-Server:

sudo systemctl status grafana-server

Configure autostart for service at reboot:

sudo systemctl enable grafana-server

Configuring the Grafana service

Disable user signup and enable anonymous access (for later image export) in the configuration 540 file /etc/grafana/grafana.ini :

> ...
[users]
# disable user signup / registration
allow_sign_up = false
...
[auth.anonymous]
# enable anonymous access
enabled = true
...
[security]
# for allowing to embed Grafana graphs in e.g. HabPanels
allow_embedding = true

Change Grafana admin password

Open port 3000 in a Webbrowser under the IP address of the Raspberry-PI Grafana Server (e.g. http://10.0.0.10:3000).

Logon with User: admin and default password: admin

Change the admin password as requested!

Connect Grafana to InfluxDB

Open Grafana UI in a Webbrowser on port 3000 (e.g. http://10.0.0.10:3000).

Logged in to the Grafana dashboard, go to “Data Sources” and create a new source pointing to your InfluxDB database, providing the credentials you chose earlier. Example:

B

Connect openHAB to influxDB

If everything is set up right and you were able to inject the sine wave into your database, it is time to do the same from within openHAB. You need to first install the InfluxDB persistence service 3.8k (via apt, PaperUI or addons.cfg - depending on your system and preferences).

Next, add your InfluxDB connection details to the persistence service config file /etc/openhab2/services/influxdb.cfg :

*# The database URL, e.g. http://127.0.0.1:8086 or https://127.0.0.1:8084 .*
*# Defaults to: http://127.0.0.1:8086*
url=http://192.168.0.2:8086

*# The name of the database user, e.g. openhab.*
*# Defaults to: openhab*
user=openhab

*# The password of the database user.*
password=AnotherSuperbPassword456-

*# The name of the database, e.g. openhab.*
*# Defaults to: openhab*
db=openhab_db

*# The retention policy to be used, needs to configured in InfluxDB*
*# Till v0.13: 'default', since v1.0: 'autogen'*
retentionPolicy=autogen

caldav Binding

Not available for OpenHAB 3!

Caldav config entfernen

In Karaf console:

config:delete org.openhab.caldavio

Visual Studio Code

Installation:

sudo apt install code

Starting:

You can now start coding to heart’s desire on the Raspberry Pi. You should realize quickly why Visual Studio Code has become a favorite amongst many avid programmers.

3 Likes

All of the image/ssl/samba/repository related stuff is already taken care of in the ooenHABian images. So If you are putting an new image to a as card, wyh not directly taking the ooenHABian images?

Just some little tips:

  1. Add “German” to the title of this thread so everybody knows its not englisch from the beginning.
  2. You started to use englisch for the “Grafana”, “InfluxDB” and “VSCOde” paragraphs. I guess you did not notice you changed language there. I know that feeling. :grinning_face_with_smiling_eyes:
    Anyway, I suggest you stay with one language.
  3. Use a code block or quotation just before “Java Installation initiieren”.

Sadly, because this is an international forum the rules are English only for posts. There are a pair of German forums: http://knx-user-forum.de/forum/supportforen/openhab (official german forum) and https://openhabforum.de/

No problem - I’ve translated it into english language now…

For some reason I felt more comfortable using the Image published on the Rasperry forum - I guess I can’t really tell why. Maybe just because it worked w/o any problems, don’t know.
Honestly I’ve never tried the openHABian images.

openHABian would also take care about Influx (iirc including the creating of database) & Grafana which then (besides creating the charts) is a one-click solution
User management (shares and permissions) and you can rely that the command “fix permissions” will then work after something went wrong

So it takes a lot of the stuff you’ve described from the need to be configured plus:

  • comes with ZRAM for as less SD wear as possible
  • Installs MQTT broker
  • AMANDA Backup + imaging to an external SD
  • a lot of other stuff. Especially you can rely that the menu options are working. It can happen that openhabian-config in a self configured environment not works as you would expect it

The only thing it doesn’t install is a X environment, so it runs complete headless

Being an old Microsoft guy I like (or better need :wink: the graphical user interface (X environment) a lot.
Be it for things as simple as locating files via file explorer, thru configuring network setting thru GUI to starting/running Visual Studio Code on the Raspberry - sure, that’s probably all possible w/o the X environment, too but I personally feel it’s so much more handy in the GUI.

Does anyone know the reason for OH to take so long after the install? Is there any chance to speed this up? I experience the same when trying to install OH ‘automatically’ (using some bash scripts). The logs are empty for, say, 40 minutes - and then the openhab.log finally shows messages like 'Rule engine started." and ‘Started HABPanel at /habpanel’. Before that, also ssh is not possible and returns a ‘Connection refused’.
(I am using the ‘standard’ package and would like to keep it as I need to use the UI every now and then.)

echo should be with single quotes

Thanks - I’ve changed the text accordingly…

Let me be the first to say, well done with this, I’m sure it required a lot of work to put all this together and I’m sure it will be useful to many. :clap:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.