A Dreamer's Lair

How to add the correct Timezone to OpenHAB2 running in a docker container on a Synology NAS

Recently I decided to take the plunge in upgrading my running OpenHAB version 1.x system to the latest version 2.1. I also wanted to take this opportunity to let OpenHAB run in a Docker container since the Synology NAS I bought a while back supports Docker.

I won’t go into the details of upgrading OpenHAB release 1.x to 2.1 in this post, since the OpenHAB site itself has enough documentation on that subject.

However I found out that there are some difficulties in using OpenHAB2 running in a Docker container on a Synology NAS. On the Docker page of OpenHAB it seems easy enough to create an OpenHAB container using the given statement:

docker run \
        --name openhab \
        --net=host \
        -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 \
        --user=<uid> \
        --restart=always \

The first difficulty, with my limited knowledge of Synology/Linux, was creating a user for OpenHAB and passing it on to the container (with –user=) in the above example. Then I discovered that when I did pass this user the container couldn’t be created because there was need for some SU access. So I skipped the user altogether which makes it easier to use anyway. Downside is that the container runs on elevated security.

I did not solve that problem, but since I also don’t have the need for any UPNP autodiscovery in OpenHAB2 (since all communication in my domotica system goes through the use of MQTT messages), I could omit –net=host.

Now I have a container which is secure enough for me.

The next problem, and the subject of this post, was that my OpenHAB2 container was running in the Zulu ‘Timezone’ so time was two hours ‘off’. This is not very pleasant when you have rules which are time based (e.g. sunset etc). I searched a hole in the ground for a solution and tried all sorts of things, but I finally found the answer on a website (unfortunately forgot which one) and wanted it to share for those who are also trying to use OpenHAB2 in a Docker container on a Synology NAS.

The Timezone should be correct because you use -v /etc/localtime:/etc/localtime:ro and -v /etc/timezone:/etc/timezone:ro but it wasn’t. There is also the possibility of setting the timezone in OpenHAB itself using an NTP thing. But that also didn’t work.

Finally I found out that one has to use an extra JAVA_OPT environment variable passed to the container. And that did work!

So what I eventually did to make things work was:

-Create a folder on my NAS to hold the OpenHAB data let’s say with the name ‘folder’
-Create the necessary subfolders, in this case addons, conf and userdata

And then lastly I could create and start the container through the following command line (in Synology SSH shell)

sudo docker run \
        --name openhab \
        --tty \
        -p 8080:8080 \
        -v /etc/localtime:/etc/localtime:ro \
        -v /etc/TZ:/etc/timezone:ro \
        -v /volume1/folder/addons:/openhab/addons \
        -v /volume1/folder/conf:/openhab/conf \
        -v /volume1/folder/userdata:/openhab/userdata \
        -e EXTRA_JAVA_OPTS="-Duser.timezone=Europe/Amsterdam" \
        -d \
        --restart=always \

The trick here is to use

        -e EXTRA_JAVA_OPTS="-Duser.timezone=Europe/Amsterdam" \

to pass the wanted Timezone to OpenHAB. Now the container runs smoothly and with the correct time 🙂

Home Automation

    Your email address will not be published. Required fields are marked *


    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>