Smarthome introduction

Setup openHAB with docker

Reading time: 3 min

openHAB offers many possibilities to make full use of your own smarthome. However, this requires an installation of openHAB first. There are different approaches to do this – I always prefer a solution with Docker. This is because an installation with Docker is easy to use in both the initial setup and in later updates. Which installation you prefer is of course up to you – but I would often choose the Docker variant. So I’ll take a look at how to set up openHAB with Docker on this page and focus on the duo Docker and openHAB in the rest of the blog.

Why openHAB with Docker?

openHAB offers almost unlimited possibilities, as many devices from different manufacturers can be centrally managed and controlled. In terms of control, many scenarios can be mapped using the rules of openHAB. This could be a fairly simple heating control during presence/holidays or a music control that follows someone via the loudspeakers in all individual rooms. This flexibility has many advantages and openHAB can be used to reveal its full potential with Docker:

  • Easy setup and management through docker
  • Possibility to test and use different openHAB versions
  • Use of different modules within the same system

However, you should understand that the operation does not only have advantages – even if, in my opinion, they outweigh them.

Requirements for operation

To run openHAB with Docker, you will of course need Docker on your environment (QNAP, Synology, RaspberryPI or whatever you use). Since I don’t focus on installing Docker here, I just ask you to search for it with Google or something similar. On my QNAP server the setup is very easy, because the containerization and thus the virtualization with Docker is already included and can be used easily – after a one-time activation.

Setup of openHAB

The openHAB installation is done inside Docker in the /openhab folder. The basis for openHAB is a minimal installation of Linux.

Pulling the openHAB image from Docker Hub
To set up openHAB, the first thing you need to do is download the image from the official Docker Hub page.
You can achieve this in the container station by a simple click under Images or with the following command:
docker pull openhab/openhab

Setting up folders
To be able to store your data outside Docker, you first need to create the following folders and subfolders on your system
openhab
openhab/addons
openhab/conf
openhab/userdata

Creating the openHAB container
Then you can start the container using the container station or the correct docker commands.
It is important that you set the correct timezone for the installation and take over the remaining necessary parameters:


-v /etc/localtime:/etc/localtime:ro \
-v /etc/timezone:/etc/timezone:ro \
-v /opt/openhab/conf:/openhab/conf \
-v /opt/openhab/userdata:/openhab/userdata \
-v /opt/openhab/addons:/openhab/addons \
-d \
-e USER_ID= \
-e GROUP_ID= \
--restart=always \

More environment variables as well as details about the necessary commands can be found on the official openHAB page for installation with Docker: To openHAB

Further outlook

Afterwards, you can use your own openHAB instance and build your own smarthome according to your individual ideas. Within this blog you will find more ideas and suggestions for the realization of your smart home. Therefore, I recommend the following articles, which deal with some basic possibilities of openHAB:
InfluxDB for openHAB

A simple example for the control of light scenes based on movement, time and the status of devices can be realized with the following code:


rule "Motion detection in office and regulation of light scene"
when
  Item Hue_Office_Presence changed to ON
then
  var illuminance = Hue_Office_Illuminance.state as Number
  if (illuminance < 15.0) {
    if (Shelly_Office_Light_Power.state == OFF && Network_Matthias_PCOnline.state == OFF) {
      switch Time_Of_Day.state {
        case "NIGHT": Shelly_Office_Light_Brightness.sendCommand(60.0)
        case "BED": Shelly_Office_Light_Brightness.sendCommand(15.0)
        default: Shelly_Office_Light_Brightness.sendCommand(45.0)}}}
end

I hope you continue to enjoy reading!
Matthias


Persönliches Foto

Matthias Suttner

As a smarthome enthusiast, I am happy to present you some interesting possibilities on my blog.