Monday, December 5, 2022

Install OpenHAB 2.4.x on Raspberry Pi (on Debian 9 – Stretch)

Abstract: In this short HowTo we will explain how you can install OpenHAB 2.4.x on a Raspberry PI

This HowTo didn´t covered security topics e.g. using SSL or setting up a user and password for the remote access!

This HowTo prefers config files and console commands and less GUI actions, so its maybe not for starters.

1.) Install Raspberry OS (Stretch light / Debian 9) as written here. Then connect to it via SSH.

I use a Transcend SDHC Ultimate 8GB, UHS-I/Class 10 (TS8GSDHC10U1) SD card here

If this is a new Raspberry OS installation you can put a file names “SSH” on the SD card to enable SSH as written here.

2.) Update environment

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

3.) Configure Raspberry Pi OS

3a.) Make sure here you use the correct date, time and timezone. Change that via:

sudo dpkg-reconfigure tzdata

3b.) run the config

sudo raspi-config

and then change the hostname and in the advanced options “Expand Disk” to the maximum via “Expand Filesystem”. Under “Boot Options” change “B1 – Desktop/CLI” to Console as we do not need an XServer or Desktop.

3c.) then Reboot the OS.

4.) Once rebooted we need to install java (Oracle JDK)

4a.) switch to root via

sudo -s

4b.) Install dirmngr for managing and downloading certificate revocation lists (CRLs) for X.509 certificates and for downloading the certificates themselves via:

apt-get install dirmngr

Note: dirmngr is deprecated, however currently its the only way to add keys to the OS

4c.) Install Zulu JVM.To install the JVM we can use Webupd repository which is made for Ubuntu, but it also works for Raspbian (which is based on Debian). To install the JVM run the following commands (line by line):

sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv-keys 0x219BD9C9
echo ‘deb http://repos.azulsystems.com/debian stable main’ | sudo tee /etc/apt/sources.list.d/zulu.list
apt-get update
sudo apt install zulu-embedded-8

4d.) Once installed you can check it via:

java -version

5.) Install OpenHAB (at the moment version 2.4.0) as mentioned here via the following steps:

5a.) make sure that wget & encrypted transport plugins is installed via:

apt-get install wget apt-transport-https

5b.) Install the pgp key

wget -qO – ‘https://bintray.com/user/downloadSubjectPublicKey?username=openhab’ | apt-key add –

5c.) Add OpenHAB to our repository list

echo “deb https://dl.bintray.com/openhab/apt-repo2 stable main” > /etc/apt/sources.list.d/openhab2.list

5d.) now we update our package DB via:

apt-get update

5e.) Install OpenHAB

sudo apt-get install openhab2

This will install OpenHAB in “/usr/share/openhab2”. This caused the following:

– configuration will be in “/etc/openhab2”

– the logfiles will be in “/var/log/openhab2”

– sitemaps will be in “/etc/openhab2/sitemaps” ($OPENHAB_CONF/sitemaps)

– items will be in “/etc/openhab2/items” ($OPENHAB_CONF/items)

– things will be in “/etc/openhab2/things” ($OPENHAB_CONF/things)

We can start it now via:

sudo /bin/systemctl start openhab2.service

This can take some minutes depending on the hardware

5f.) The next commands will configure OpenHAB so that is runs during startup

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable openhab2.service

6.) If we open now the website OpenHAB documentation recommend a click on the “Standard” package. This will install the “Paper UI” (here you can install add-ons, discover and configure things etc), the “Basic UI” (here you can have a look at your created sitemaps – we’ll get back to this later), and the Habpanel (here you can create dynamic dashboards for your things). Once you clicked on “Standard”, openHAB will install the packages and afterwards take you to the start page.

7.) Now we can install some bindings. To do that perform the following steps:

7a.) Login on the pi

7b.) As openHAB2 uses Apache Karaf (more infos here) we need to connect to the console via:

ssh -p 8101 openhab@localhost

As this should be the first time if the howto is followed the following prompt will come up:

The authenticity of host ‘[localhost]:8101 ([127.0.0.1]:8101)’ can’t be established.
RSA key fingerprint is 77:77:77:77:77:77:77:77:77:77:77:77:77:77:77:77.
Are you sure you want to continue connecting (yes/no)?

Enter yes to proceed and then you should get the following

Warning: Permanently added ‘[localhost]:8101’ (RSA) to the list of known hosts.
Password authentication
Password:

The default username/password is openhab:habopen, so enter habopen at the password prompt to login

After successful connection and authentication, the console will appear:

                          __  _____    ____
  ____  ____  ___  ____  / / / /   |  / __ )
 / __ \/ __ \/ _ \/ __ \/ /_/ / /| | / __  |
/ /_/ / /_/ /  __/ / / / __  / ___ |/ /_/ /
\____/ .___/\___/_/ /_/_/ /_/_/  |_/_____/
    /_/                        2.4.0
                               Release Build

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown openHAB.

openhab>

7c.) To find out what features are already installed and which one can be installed, you can use the following (more infos here):

feature:list

or

bundle:list -s

7d.)

With the following command you can install some features (here are some example I use):

Astro Binding:
feature:install openhab-binding-astro

Exec Binding:
feature:install openhab-binding-exec

JDBC Persistence MySQL:
feature:install openhab-persistence-jdbc-mysql

NTP Binding:
feature:install openhab-binding-ntp

8.) Now you can start building your configuration.

It might now a good idea to start creating a backup from the whole configuration now. To perform that power off the PI and create a backup from the SDCard.

Notes:

Here are some commands which might be usefull:

Check the openHAB 2 Service:
sudo systemctl status openhab2.service

Start / Restart the OpenHAB2 Service:
sudo systemctl restart openhab2.service

Stop the OpenHAB2 Service:
sudo systemctl stop openhab2.service

Show logfile from last start:
sudo journalctl -u openhab2.service -b

To check if OpenHAB is listening on the OS you can use the following:

netstat -nlp | grep 8080

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Stay Connected

24FollowersFollow
- Advertisement -

Latest Articles