Initial Setup of OH3 with Docker/Portainer, InfluxDB, Grafana and NodeRed

Hello,
after being on OpenHAB for 3 years and having received lots and lots of help in this community - I thought I could also share some of my learnings - maybe this could be of help for someone trying to get started?!

I will go through my Setup and how I installed it - not saying this is how it should be done or that this is the only way, but it works for me slight :slight_smile:

My setup:

  • a RaspBerryPi 4 with 8GBRAM and 64GB SD Card
  • Raspbian on the PI
  • Docker

In the Docker I run:

  • Portainer as graphical UI to help me with some of the configuration
  • OpenHAB 3.0.0
  • NodeRed
  • Grafana
  • InfluxDB

In the following I’ll try to walk you through How to achieve this setup so lets get started:

Install RaspBian:
I followed the official RaspBerry Setup Guide Raspberry Setup Guide
After the Install you need to activate SSH by logging in to your freshly installed Raspberry and activate SSH:

Install a SSH Client
in order to proceed you’ll need to SSH into your Raspberry with something like Putty or - I use SmartTTY

Install Docker:
I found a very good help at the “Homenetwork Guy” from which I extracted the below parts for docker and portainer install Link

SSH into your Raspberry and execute the following command:
curl -sSL https://get.docker.com | sh
f you wish to run docker without running the command with “sudo” then you can add the default Raspberry Pi user “pi” to the “docker” group:
sudo gpasswd -a pi docker
You will need to log out and back in or reboot your Raspberry Pi in order for the group change to occur.
sudo reboot

Install Portainer
First create a volume for the Portainer (this is your first docker container)
sudo docker volume create portainer_data

Then run the following command to install the docker container “Portainer”:
docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:linux-arm

f your Raspberry Pi is located at 192.168.1.6, for instance, then go to http://192.168.1.6:9000 to go to the Portainer web administration page. The first time you open portainer you will need to set up an admin user:

After you log in, you will need to select “Local” and click “Connect” since you are connecting to the local Docker installation:

Then click on the “containers” and you’ll see an overview of your containers - currently only the “portainer”

Installing OpenHAB3 in docker/portainer:
I documented the installation with a series of screenshots:
For the NAME you can choose whatever you like - this will be the Name of your OpenHAB docker container later




For the host name you can also choose whatever you like

Then you need to find out your UserID and GroupID and enter them in the Environment variables:
go back to your terminal / ssh and enter id pi
image
then enter Environment Variables with the Numbers (here it’s 1000) in the ENV Tab of Portainer:

then click on deploy the container
image

and wait until the container is deployed - this might take 5minutes…

Then you should be able to login to your openhab with YourIP:8080

Install Samba to get access to your conf folder (from Windows)
Install samba on your Raspberry:
sudo apt-get install samba samba-common smbclient
this might take a little…

Check if samba is running
sudo service smbd status
sudo service nmbd status
It should tell you that the services “smbd” and “nmbd” are running

Since the default conf file is rather large - I backed up the current one and made a very simple basis conf file:
sudo mv /etc/samba/smb.conf /etc/samba/smb.conf_alt
sudo nano /etc/samba/smb.conf

Then enter the following:

[global]
workgroup = WORKGROUP
security = user
encrypt passwords = yes
client min protocol = SMB2
client max protocol = SMB3

to save and close:

Crtl+ O

Return

Crtl+ X

Then test the configuration with Testparm

Hope no error came up?!
After every change you need to restart the samba services:
sudo service smbd restart
sudo service nmbd restart

Samba is now running - but we need to give now permission to the config folder and the pi user. I am giving ownership to the pi user for the Homefolder of pi:
sudo chown -R pi:pi /home/pi
sudo chmod -R 700 /home/pi

Then I add the path and name to the conf file to be found later when connecting via Win-Explorer:
sudo nano /etc/samba/smb.conf

[SambaPiHome]
comment = Samba-Pi-Home
path = /home/pi
read only = no
to save and close:

Crtl+ O

Return

Crtl+ X

Then test the configuration with Testparm

Hope no error came up?!
After every change you need to restart the samba services:
sudo service smbd restart
sudo service nmbd restart

With this the folder should be visible in the network - but you do not yet have access. You need to generate the passwords for the user:
sudo smbpasswd -a pi
after entering the password you need to enter this a second time to confirm
to deactivate the user use:
sudo smbpasswd -d pi
to activate the user:
sudo smbpasswd -e pi

now you should be able to map the above path as drive into your MS Explorer

Install NodeRed:
mkdir node_red_data
sudo chown -R 1000:1000 node_red_data
docker run -it -p 1880:1880 -v /home/pi/node_red_data:/data --name NodeRed -e TZ=Europe/Berlin nodered/node-red

Install Grafana:
Grafana I installed again using portainer.
Note: the default admin user and password for Grafana is: user: admin pwd: admin



with the following Environment variables you allow to pullup Grafana (e.g. from Openhab) without the need of a login.

And… as always “Deploy the container”

Attention: now you can open Grafana - yet you will not be able to do anything unless you sign in as admin - so first sign out then back in!
image

Then you can access Grafana with "YourIP":3000

Yet - in order to display anything you’ll need a database first - so lets:

Install InfluxDB:
again I used Portainer to install InfluxDB:



With the following Environment Variables you:

  • Create a default Database with the name: OpenHAB3_DB
  • Ensure that you need to authenticate
  • Create the admin user & password
  • Create read user - grafana for grafana to be able to read the data
  • Create write user - openhab for openhab to be able to write the data
  • (maybe you want to select better passwords than I did in my screenshot)



And… as always “Deploy the container”

Now you should be able to go back to Grafana and setup the connection to your “OpenHAB3_DB”

Hope this tutorial helps to get started…

9 Likes

Fantastic guide. I’m currently running a raspberry pi3 with openhabian. I will have a raspberry pi4 in a couple of days and thinking of going down this route to install the newest openahab3 I’ve never used docker so I’ve got a few questions if you don’t mind?

  1. You state in part of your guide that you will now need to use ssh. Can the steps you are relating to not be done on the command line of the gui?

  2. If you restart you raspberry pi, does docker/portainer automatically restart openhab in its container? If not could you give me a brief overview of what would need to happen.

  3. With openhabian when you log in via console you can control the openhab config and the general raspian environment. How would like would on your type of install?

Every comment will be much appreciated :grinning:

Hello,

happy that you like the tutorial (was my first) - I would really recommend you do start with docker really makes setups and tests of new installations a lot easier!!

As for your questions:

  1. There is a solution - place a file called ssh in the boot partition of your SD Card. Just an empty file with no extension

  2. Yes the open hab docker is restarted automatically if you set the Restart Policy (in the portainer) to unless-stopped I think I missed that in my screenshots.

  3. I know what you mean with this yet running openHAB in the docker I never missed these config steps - do you have something special in mind?

Hope I could help - have fun experimenting with Docker :grinning:

I have been using openhab2 now for about 4 years. At the start my config was very basic but now I’ve got more complex items and config files I need to start using persistence hence stumbling across you guide whilst searching for infuxdb. I keep coming across docker and I’m really excited to start using it. Thank you for your replies to questions 1 and 2.

Regarding question 3 I don’t think I explained myself very well.

For example currently when I ssh into my raspberry I login with openhabian and my password. If I then Sudo nano etc/openhab2/items/home.items for instance I can access my openhab items config file. My question was if you use docker and ssh in and want to manually change the config files rather than visual studio on a windows pc for instance, would the openhabian user be available to do this or if this would even work the same?

As you can tell I’m very new to all this docker and Linux as a whole really. I’ve always used pre compiled packages like Openhabian so lack on the Linux side. But very willing to learn!

Well - I am not sure if I get you right- sorry if not. I guess I was at the very same point as you are right now a year ago or so…
I use VSCode on a Win PC to access the config files. Therefore I needed to install SAMBA to access the files on the raspPi.
As a user I use my PI as described above - works flawless… (I am not so good with Nano)

hope that helps

Thank you for you advice. I’m sure I’ll be in touch if I get stuck!

So ive got my new raspberrypi, followed your tutorial to a t and its worked a treat!
only issue i have is setting up grafana, in the volume section on the grafana container im not sure where to map the volume to as mine only says [portainer_data] in the drop down box. so i went over to create a new volume called grafana_local but im not sure what the new volume configuration should be?

Hello,
did you follwo the screenshot (see above) - and also ensure that the buttons on the right (Volume vs. Bind / Writable vs. Readonly) are set accordingly?!
then this should work?!

Yes but when I click drop down box to select the volume I don’t have grafana-storage as an option just portainer_data. Do I need to create a volume called grafana-storage first? If so could you share you config on this please.

I found this guide but not sure if it wants to be a standard local volume or NFS/CIFS and if there is any driver options I need to add.

Hello,
ah… ok I guess you’re looking in the wrong place. In you Portainer - Grafana Setup go to the Volumes as in my screenshot and click “mapp additional volume” and then you should be able to continue from there

Hello,

how is the backup/restore concept under docker? And how the openhab update (e.g. 3.1) is working under docker?

Nice tutorial!
I made the step to migrate from OH 2.5 native (openHABIAN) to OH 3 docker.
With 1 thing in mind, to easy backup (to answer you question @dimes)

Instead of using portainer I use docker-compose so all my docker container configuration is in one place.

I’ll share you my docker-compose file. All I did was place this in one folder (eg /opt/smarthome) and run docker-compose up -d. To back up, stop it and backup all your file in that folder.
Updating is easy, stop it and run docker-compose pull and you’ll have everything up to date

Here is my compose file:

version: "2"

services:

  deconz:
#    image: marthoc/deconz:armhf-2.05.79
    image: marthoc/deconz:stable
    restart: always
    volumes:
      - ./data/deconz:/root/.local/share/dresden-elektronik/deCONZ
      - /etc/localtime:/etc/localtime:ro
    devices:
      - /dev/ttyS0
    environment:
      - DECONZ_DEVICE=/dev/ttyS0
      - TZ=Europe/Amsterdam
      - DECONZ_VNC_MODE=1
      - DECONZ_VNC_PASSWORD=#######
    ports:
      - 8083:80
      - 5900:5900
    networks:
      - network

  broadlink-mqtt-bridge:
    image: ljsquare/broadlink-mqtt-bridge
    restart: always
    network_mode: host
    volumes:
      - ./data/broadlink/config:/config
      - ./data/broadlink/commands:/commands
    depends_on:
      - mqtt-broker

  openhab:
    network_mode: host
    ports:
      - 8080:8080
    volumes:
      - ./data/openhab/addons:/openhab/addons
      - ./data/openhab/conf:/openhab/conf
      - ./data/openhab/userdata:/openhab/userdata
      - /var/log/openhab:/openhab/userdata/logs
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
#    image: openhab/openhab:latest
    image: openhab/openhab:milestone
    environment:
      - EXTRA_JAVA_OPTS=-Duser.timezone=Europe/Amsterdam
      - USER_ID=109
      - GROUP_ID=113
      - CRYPTO_POLICY=unlimited
    devices:
      - /dev/ttyUSB-ZStick-5G
      - /dev/ttyUSB-P1
    depends_on:
      - deconz
      - broadlink-mqtt-bridge
    restart: always

  mqtt-broker:
    ports:
      - 1883:1883
      - 9001:9001
    image: eclipse-mosquitto
    networks:
      - network
    restart: always
    volumes:
       - ./data/mosquitto:/mosquitto


networks:
  network:

If you have any questions, feel free to ask :slightly_smiling_face:

Hi @ljsquare ,

but this easy backup works for file based configuration only, correct?

I want to start my 2.x -> 3.x migration on a green field approach. I have a raspberry pi 4 with ssd + docker (no openhabian). I decided to use Portainer because I prefer a no code/ low code customizing. So I want to go away from my file based configuration in OH2 to purely databased configuration (Main UI) for my bindings/things/channel/items/rules/pages.
But before I start, I wanted to clearify the backup question… So if I understood right, all configurations in MainUI are save in OH3 in the predefined database rrd4j. Or I am wrong?
So I would not find any files in the openhab folder (userdata, conf, addons,…).

So, how can I backup and restore the MainUI configuration? With a script/command like here or do I have also a backup possibility with docker/Portainer?

Hi, all config is stored in the jsondb file. As far as I know it can be copied/back-upped and restore with a stopped container. The rrd4j is the default persistent manager in OH3, it stores the values of the items by default.

The script can work, but also copying the userdata/jsondb in cause of back-upping the MainUI config.

Are there instructions somewhere on connecting Grafana to InfluxDB? I must be missing something - just getting a “Bad Request” error… nothing I’ve found seems to get me past this bump

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