I recently migrated my Home Assistant setup from running Home Assistant Operating System on a Hardkernel C2 , to running in containers on my NAS

The process was reasonably straight-forward, but finding up-to-date documentation and examples online are always a challenge when the platform moves fast

My Home Assistant needs are covered by just three services; home-assistant , deconz and node-red . I use deconz because I have a ConBee II as my ZigBee gateway

For home-assistant and deconz, the images from docker hub are ready to use. For node-red, some additional packages are required

node-red

A custom node-red image is needed to bake in a number of node-red addons. The required package is node-red-contrib-home-assistant-websocket , and the other two are ones I find practical

You can find more at flows.nodered.org

FROM nodered/node-red:latest-10

RUN npm install \
    node-red-contrib-home-assistant-websocket \
    node-red-contrib-time-range-switch \
    node-red-contrib-cron-plus

Save this in a Dockerfile and place it in a folder named node-red-image next to the docker-compose.yml file

docker-compose

Docker-compose makes it easy to run the three required services. The full docker-compose.yml file is as follows:

version: '3'
services:
  homeassistant:
    container_name: home-assistant
    image: homeassistant/home-assistant:stable
    restart: always
    ports: 
      - 8123:8123
    environment:
      - TZ=${TZ}
    volumes:
      - ${DATA_DIR}/home-assistant:/config
      - /etc/localtime:/etc/localtime:ro
    depends_on:
      - deconz

  deconz:
    container_name: deconz
    image: deconzcommunity/deconz:stable
    restart: always
    ports: 
      - 8080:8080
      - 8088:8088
    environment:
      - TZ=${TZ}
      - DECONZ_WEB_PORT=8080
      - DECONZ_WS_PORT=8088
      - DECONZ_VNC_MODE=0
      - DECONZ_DEVICE=${CONBEE_DEVICE}
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ${DATA_DIR}/deconz:/opt/deCONZ
    devices:
      - ${CONBEE_DEVICE}:${CONBEE_DEVICE}

  nodered:
    container_name: node-red
    build: ./node-red-image
    restart: always
    user: "1000:1000"
    environment:
      - TZ=${TZ}
    ports:
      - 1880:1880
    volumes:
      - ${DATA_DIR}/node-red:/data
    depends_on:
      - homeassistant

The DATA_DIR environment variable should be set to the directory where the data should be saved, and the TZ environment variable should be set to the timezone of the system

This can be done by placing a .env file next to the docker-compose.yml file with the content:

DATA_DIR=/path/to/data
TZ=Europe/Copenhagen
CONBEE_DEVICE=/dev/ttyACM0

Finally, run docker-compose up -d to start the containers.

Configuration

deconz

deconz is automatically discovered by Home Assistant, and can simply be enabled through Configuration -> Devices & Services in the Home Assistant interface

node-red

Configuring node-red requires you to add a home assistant node to a flow, double-click it and press the Server input box

Enter http://home-assistant:8123 as the Base URL, and insert a Long-Lived Access Token as the Access Token. The Long-Lived Access Token is created through the account page in the Home Assistant interface

After this, node-red should be able to successfully connect to Home Assistant using a websocket connection