How to update OpenHab(ian) in a safe way

Published by Oliver on

One of the easiest ways to use OpenHab is to install OpenHabian on a Raspberry Pi. Cheap, effective and quickly done. Now some time has passed and you want to update OpenHab(ian) to the newest version in a reliable way? Or enable some experimental features by switching to an experimental branch? This is how to do it.

I recently wanted to update OpenHab from a 2.5 milestone version to the final 2.5 version – updating and going back to the stable channel. It is not a super complex process but I have seen some questions, so I will document a safe way here (also doing some good for my future self ;-)).

Make sure you are ready

Before you start any update you should make sure you have a backup. The most time intensive but also safest way is to completely copy your SD card, make a copy of your VM or otherwise get a full copy of your system.

There are more targeted ways though. I am configuring OpenHab via config files as much as possible. Setting up git for config folder (usually “/etc/openhab2/“) is an obvious choice if you do that. It allows you to keep track of all your changes (and quickly revert them) but it also makes backups super simple. Just push to GitHub or some other git repository. Just make sure to use a private repository if your config files contain sensible data like passwords or names.

If you are actually using OpenHabian there is also a nice builtin backup method. Before you run it consider updating though.

sudo openhab-cli backup
// Which places a file in /var/lib/openhab2/backups, which can then be restored using:

sudo openhab-cli restore /var/lib/openhab2/backups/

I have also installed influxDB together with Grafana to save and visualize my data. That is not included in the backups, so I ran these commands to create one.

// create influxdb backup folder and dump the openhab database and general settings into it
mkdir influxDbBackup
sudo cp -arv "/etc/influxdb/influxdb.conf" ./influxDbBackup/influxDB.conf
sudo influxd backup ./influxDbBackup/
mkdir influxDbBackup/db
sudo influxd backup -database openhab_db influxDbBackup/db/

// create grafana backup folder and dump the database and settings
mkdir grafanaBackup
sudo cp -arv /etc/grafana/grafana.ini ./grafanaBackup/grafana.ini
sudo cp -arv /var/lib/grafana/grafana.db ./grafanaBackup/grafana.db

Now you just need to copy those folders to some safe backup space. While you are at it of course also copy the backup file created by the openhab-cli.

Now we are ready to actually update the system.

Update OpenHab

Start the openhabian menu by using

sudo openhabian-config

and wait for it to finish updating. Now just go through the first three options one by one. 01 will update the config tool you are using right now. This should be done already but better safe than sorry. 02 will update all software packages on your system (basically calling apt update && apt upgrade). This will include OpenHab!

openhabian config menu used to update and configure OpenHab
The openHabian config tool – use 01-03 to update your system and openHab version

03 will finally allow you to change your actual OpenHab release branch. Before you start that consider what version of OpenHab you actually want to use. There are 3 possible branches right now

  • OpenHab release uses well tested major version builds (2.3, 2.4, 2.5)
  • OpenHab testing used milestone builds that should be fine but are not tested as much (2.5 M1, 2.5 M2)
  • OpenHab snapshot just uses the latest OpenHab builds available

Normally you should stick with the release builds to be safe, but sometimes you need new features early. I wanted to use the new MQTT binding before the final version of 2.5 was released, so I switched to the testing channel and used 2.5 M2 for some time. Now lets go back to the release channel though and install the final version of 2.5 by checking option “41 openHab release” under the “openHab related” settings.

openHabian config menu with release channels
openHab related settings allowing you to switch between different release channels

Whether you click the upgrade from the main menu or the release from this one, it will start the upgrade process. This might, again, take a while.

During the update process the installer will try to update some config files. You might have changes important settings here so make sure to check the changes by pressing “D”. In my case it was trying to overwrite changes to the logging configuration. As I want to keep those I pressed “N”. If you are fine with the changes select “Y”.

Check if everything works

That’s it, the update is done. Now go and check if everything is still working. Using your ip-adress or name of the server you can open http://servername:9001 to see logs from your OpenHab instance. Also check http://servername/start/index to see a dashboard with all available UIs. Be patient, the startup might take a while as some updates are still installed.

Once that is done try to test at least one device of each type and most of your rules.

Fix problems

Sometimes important bindings have changed. That should be in the release notes and now is a good time to update your configurations accordingly.

Also custom bindings you might have installed as jar files get deleted during the update. Add those back if you still need them.

In my case some items seemed to not have been loaded properly, causing a lot of rules to fail. Simply going into all items files and saving them (that triggers a reload) fixed the problem though. In general just check the logs for errors.

I also had to delete and re-add all my device in Alexa as the hue emulation binding was updated and I played with those settings before. It is working perfectly nice now though.

That is it. Updating OpenHab is really easy with OpenHabian. If you are looking for another project now, how about synchronizing your lights with your alarm via OpenHab?

Update: User lutiana on reddit pointed out that there is also a nice looking general backup solution for the Raspberry Pi: raspiBackup. This seems to make a full copy though, needing more storage space.

Categories: Openhab