Set up OpenHAB and Development in Docker

OpenHAB is an open source home automation system. It's vendor and technology agnostic and extensible. Every device is supported and communicated through corresponding addons and plugins. In theory, it supports most smart devices no matter whether its protocol is z-wave or ZigBee, etc. It's now in 2.0 beta 4 which is based on Eclipse SmartHome which makes it easier to create new plugin and add new devices.

I like to use Docker too. It's easier to manage production and development environment. As long as I create the Dockerfile, I can rapidly set up the exact same environment to run my OpenHAB. I don't need to worry about differences on the OS, and the configuration is the same.

The official docker image for OpenHAB is based on Ubuntu and it always gets the latest successfully built OpenHAB snapshot which means it may change nightly. Whenever you run the command to create such a container, the OpenHAB version may be different. Besides, I prefer CentOS to Ubuntu. So I decide to create a new Dockerfile for myself. First, it's based on CentOS. second, it always installs the same OpenHAB version unless you change that. It's straightforward to create a new Dockerfile for OpenHAB since I could copy most from the current official docker image. But I did find some nuances that broke the whole things. Below are the changes I made and the workarounds to the problems.

  1. Download OpenHAB 2.0 beta 4.
    • You can find the download link for the version from here.
  2. Install Oracle Java
      • I don't find Oracle Java in CentOS repository and I cannot use yum to install it. Fortunately, I found this Stack Overflow question and used wget to download the rpm from Oracle Java website. Here's the command to download 8u102:
        wget --no-cookies --no-check-certificate --header "Cookie:; oraclelicense=accept-securebackup-cookie" ""
  3. Problems in setting up the user and permissions.
    • The official docker image creates a few groups and the user openhab. It's running the daemon as the user openhab. First, some gids of the new groups in the official docker image conflicts the built-in groups in CentOS. Second, For some reason, it seems to me running as the user openhab doesn't have access to /dev/ttyACM0 which is the z-wave device. Even though I set the right groups and permissions in the docker and the permissions in the host. I ended up running everything as root in docker. It's a potential security issue. The process running on docker is running on the host as root too.
  4. Setting up Eclipse in Docker. This is to allow you to develop on the docker image.
    • Eclipse is a GUI. How to work with the GUI? One way of doing it is to pass $DISPLAY to the container and run "xhost +" on the host. This will allow the docker to use the host x server. But doing that is a security concern since you open up your host.
  5. Install maven and ant.
    • Don't install them via yum. That'll pull in OpenJDK. Remember we need Oracle Java to run. So I download the tar files from the websites and set up the $PATH.
  6. Run it.
      • If you don't need to do development, you can keep the command from the original Dockerfile. That is,
        ENTRYPOINT ["/openhab/"]
        CMD ["server"]

    Otherwise, you can just comment out ENTRYPOINT and CMD and start shell from the docker image. Remember, to expose all the ports from your docker container via the option "-P" when you start your container.

That's how I set up the docker image. It took a few trial and error. Most were spent on setting up the user and permissions. It's mysterious to me. I think I already set up the permissions right but I still ended up using root. But it works fine in that approach. Development is fine. I hope you can explore OpenHAB world and enjoy it.


Join the Conversation

1 Comment

Leave a comment

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