OpenHAB 3 Home Automation in Docker

Mike Polinowski
INSTAR MQTT
Firmware Update
Full HD Series
INSTAR Deutschland GmbH
INSTAR MQTT

Make your camera the heart of your smart home

INSTAR MQTT

Using the MQTT interface of your INSTAR Full HD cameras you can connect them to an existing smarthome system (Home Assistant, OpenHAB, Node-RED, Athom Homey, Homematic, ioBroker, Loxone, homee) can be added. Or even make it the main broker for your MQTT sensors. MQTT allows you to automate ALL functions of your camera and link them to other services in your smarthome.

Mike Polinowski
IFTTT Applets
Firmware Update
Full HD Series
INSTAR Cloud
INSTAR Deutschland GmbH
INSTAR IFTTT Applets

Control your camera via the IFTTT online service

INSTAR IFTTT

On the IFTTT platform, we provided a service called INSTAR. The INSTAR applets provide you with the ability to control some settings of your INSTAR camera or INSTAR Cloud with IFTTT. You can connect INSTAR with triggers for location (Geo Location) and date & time, send notifications and much more. For example, you can connect INSTAR applets to the IFTTT location service and automatically disable the alarm when you arrive home. You can also use the INSTAR applets to create your own automation and connect them to other third-party applets.

Pulling the Docker Image

The OpenHAB 3 image is available on Docker Hub:

docker pull openhab/openhab:3.1.0-snapshot-alpine

Preparing the System

groupadd -g 9001 openhab
useradd -g 9001 openhab
usermod -a -G openhab myownuser
mkdir -p /opt/openhab/{openhab_addons,openhab_conf,openhab_userdata}
chmod -R 775 /opt/openhab

Running the Container

From your commandline:

docker run \
        --name openhab \
        --net=host \
        --privileged \
         --rm \
        -v /etc/localtime:/etc/localtime:ro \
        -v /opt/openhab/openhab_addons:/openhab/addons \
        -v /opt/openhab/openhab_conf:/openhab/conf \
        -v /opt/openhab/openhab_userdata:/openhab/userdata \
        -d \
        openhab/openhab:3.1.0-snapshot-alpine

In docker-compose:

version: "3.8"

services:
  openhab:
    image: "openhab/openhab:3.1.0-snapshot-alpine"
    restart: always
    network_mode: host
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/etc/timezone:/etc/timezone:ro"
      - "/opt/openhab/openhab_addons:/openhab/addons"
      - "/opt/openhab/openhab_conf:/openhab/conf"
      - "/opt/openhab/openhab_userdata:/openhab/userdata"
    environment:
      OPENHAB_HTTP_PORT: "8181"
      OPENHAB_HTTPS_PORT: "8443"
      EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Berlin"

I changed the HTTP port to 8181 - as I am already using the default port 8080 for a different service. Make sure the port is accessible from your LAN: ufw allow 8181/tcp

Automating Docker setup using Ansible

You can test it by running:

ansible-playbook -i mycontainerhost, -t openhab run-containers.yml
- name: OpenHAB v3 Container
  hosts: test
  gather_facts: no
  
  tasks:

  - name: Run OpenHab Container
    tags: openhab
    docker_container:
      name: openhab
      image: openhab/openhab:3.1.0-snapshot-alpine
      state: started
      detach: yes
      interactive: yes
      tty: yes
      ports:
        - 8181:8080
        - 8101:8101
        - 5007:5007
      volumes:
        - /etc/localtime:/etc/localtime:ro
        - /etc/timezone:/etc/timezone:ro
        - /opt/openhab/addons:/openhab/addons
        - /opt/openhab/conf:/openhab/conf
        - /opt/openhab/userdata:/openhab/userdata
      keep_volumes: yes
      hostname: openhab.localnet
      memory: 512m
      pull: true
      restart_policy: unless-stopped
      env:
        EXTRA_JAVA_OPTS="-Duser.timezone=Europe/Berlin"

Run the playbook and visit the IP address of your server on port 8181:

Trying out OpenHAB 3 in Docker

Choose the bindings that you will need to be installed:

Trying out OpenHAB 3 in Docker

Maintenance

Clean Up when things go wrong

Delete the contents of /opt/openhab/userdata/cache and /opt/openhab/userdata/tmp

rm -rf /opt/openhab/userdata/cache
rm -rf /opt/openhab/userdata/tmp

OpenHAB CLI

Access the OpenHAB command line tool inside the Docker container from your host system:

docker exec -it openhab /openhab/runtime/bin/client

Logging in as openhab
Password:  PASSWORD IS habopen

                           _   _     _     ____  
   ___   ___   ___   ___  | | | |   / \   | __ ) 
  / _ \ / _ \ / _ \ / _ \ | |_| |  / _ \  |  _ \ 
 | (_) | (_) |  __/| | | ||  _  | / ___ \ | |_) )
  \___/|  __/ \___/|_| |_||_| |_|/_/   \_\|____/ 
       |_|       3.1.0-SNAPSHOT - Build #2099

Use '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
To exit, use '<ctrl-d>' or 'logout'.

openhab> 

Accessing the OpenHab logs from the CLI:

openhab> log:tail