Home Assistant

Customizing entities - Home Assistant Home Assistant is free and open-source software for home automation designed to be a central control system for smart home devices with a focus on local control and privacy. It can be accessed through a web-based user interface by using companion apps for Android and iOS, or by voice commands .
Jeedom Plugin JeeRhasspy | Jeedom by KiboOst Rhasspy is an open source, fully offline set of voice assistant services for many human languages that works well with: Hermes protocol compatible services (Snips.AI) Home Assistant and Hass.io.
Resources : Node-RED Node-RED is a flow-based development tool for visual programming developed originally by IBM for wiring together hardware devices, APIs and online services as part of the Internet of Things.
Z-Wave JS · GitHub Z-Wave JS is a full-Featured Z-Wave to MQTT Gateway.
Watchtower Watchtower is an application that will monitor your running Docker containers and watch for changes to the images that those containers were originally started from. If watchtower detects that an image has changed, it will automatically restart the container using the new image.

Step 1: Reference

This post will describe a large Home Assistant deployment and configuration on Docker with the following integration components:

  • Home Assistant : Core Home Automation system
  • Mosquitto: Message Broker
  • Z-Wave JS: Instance that manages Z-Wave devices
  • Rhasspy: Voice Control System
  • Node-RED: Workflow system

Step 2: High Level Overview

Following picture provides overview of integration and communication between components:

Step 3: Install Docker

This post will primarily focus on Home Assistant (non-supervised) deployment. This requires a Docker deployment. Currently I run all the containers as root, this is for easy of deployment/configuration, will update this blog in the future to run under non-root user.

# curl -fsSL get.docker.com | sh

Step 4: Create Docker (App) Directories

Each application will need some dedicated (persistent) storage for configuration or data files.

# mkdir -p /opt/homeassistant/config
# mkdir -p /opt/mosquitto/config
# mkdir -p /opt/mosquitto/data
# mkdir -p /opt/mosquitto/log
# mkdir -p /opt/nodered/data
# mkdir -p /opt/rhasspy
# mkdir -p /opt/zwavejs

Node-Red runs the container under user 1000:1000 so if you don’t have this user, create it and chown its directory properly:.

# chown 1000:1000 /opt/nodered/data

Step 5: Deploy Watchtower

In a specific directory e.g. /root/dockers create a new docker composer configuration file which contains the entire configuration required with dependencies /root/dockers/homeassistant/docker-composer.yml Watchtower will be defined as a service:

version: '3'
services:
  watchtower:
     container_name: watchtower
     image: containrrr/watchtower:latest
     volumes:
       - /var/run/docker.sock:/var/run/docker.sock
       - /etc/localtime:/etc/localtime:ro
     restart: 'no'
     environment:
       - WATCHTOWER_CLEANUP=true
       - WATCHTOWER_NO_STARTUP_MESSAGE=true
       - WATCHTOWER_NOTIFICATIONS_LEVEL=info
       - WATCHTOWER_INCLUDE_STOPPED=true
       - WATCHTOWER_NOTIFICATIONS=email
       - WATCHTOWER_NOTIFICATION_EMAIL_FROM=home@mydomain.local
       - WATCHTOWER_NOTIFICATION_EMAIL_TO=zathur@mydomain.local
       - WATCHTOWER_NOTIFICATION_EMAIL_SERVER=smtpserver.mydomain.local
       - WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT=25
       - WATCHTOWER_NOTIFICATION_EMAIL_DELAY=2
       - WATCHTOWER_NOTIFICATION_EMAIL_SUBJECTTAG=HSUpdate
     command: --interval 500

Deploy the container

# cd /root/dockers/homeassistant
# docker-compose up -d

Check docker deployment

# docker ps
CONTAINER ID   IMAGE                                          COMMAND                  CREATED         STATUS                  PORTS                                                                 NAMES
517f788b4522   containrrr/watchtower:latest                   "/watchtower --inter…"   4 seconds ago   Up 3 seconds            8080/tcp                                                              watchtower

Check the log files

# docker logs 517f788b4522
time="2023-01-07T21:37:46+01:00" level=info msg="Watchtower 1.5.1" notify=no
time="2023-01-07T21:37:46+01:00" level=info msg="Using notifications: smtp" notify=no
time="2023-01-07T21:37:46+01:00" level=info msg="Checking all containers (except explicitly disabled with label)" notify=no
time="2023-01-07T21:37:46+01:00" level=info msg="Scheduling first run: 2023-01-07 21:46:06 +0100 CET" notify=no
time="2023-01-07T21:37:46+01:00" level=info msg="Note that the first check will be performed in 8 minutes, 19 seconds" notify=no

Step 6: Deploy Mosquitto

In a specific directory e.g. /root/dockers create a new docker composer configuration file which contains the entire configuration required with dependencies /root/dockers/homeassistant/docker-composer.yml Mosquitto will be defined as a service:

version: '3'
services:
  mosquitto:
    container_name: mosquitto
    image: eclipse-mosquitto
    restart: unless-stopped
    ports:
      - "1883:1883/tcp"
    environment:
      - TZ=Europe/Amsterdam
    volumes:
      - /opt/mosquitto/config:/mosquitto/config
      - /opt/mosquitto/data:/mosquitto/data
      - /opt/mosquitto/log:/mosquitto/log
    stdin_open: true
    tty: true

Create a Mosquitto configuration file /opt/mosquitto/config/mosquitto.conf:

# Listen on port 1883 on all IPv4 interfaces
listener 1883
socket_domain ipv4
# save the in-memory database to disk
persistence true
persistence_location /mosquitto/data/
# Log to stderr and logfile
log_dest stderr
log_dest file /mosquitto/log/mosquitto.log
# Require authentication
allow_anonymous false
password_file /mosquitto/config/mqttuser

Create an empty password file (will define users after mosquitto starts up):

# touch /opt/mosquitto/config/mqttuser

Deploy the container

# cd /root/dockers/homeassistant
# docker-compose up -d

Check docker deployment

# docker ps
CONTAINER ID   IMAGE                                          COMMAND                  CREATED         STATUS                  PORTS                                                                 NAMES
517f788b4522   containrrr/watchtower:latest                   "/watchtower --inter…"   4 seconds ago   Up 3 seconds            8080/tcp                                                              watchtower
25ca17ccb63b   eclipse-mosquitto                              "/docker-entrypoint.…"   15 hours ago    Up 15 hours             0.0.0.0:1883->1883/tcp, :::1883->1883/tcp                             mosquitto

Check the log files

# docker logs 25ca17ccb63b
1673069227: mosquitto version 2.0.15 starting
1673069227: Config loaded from /mosquitto/config/mosquitto.conf.
1673069227: Opening ipv4 listen socket on port 1883.
1673069227: mosquitto version 2.0.15 running

Create users needed for interconnectivity, a dedicated user per connection:

# docker exec -it mosquitto mosquitto_passwd /mosquitto/config/mqttuser homeassistant
Password:
# docker exec -it mosquitto mosquitto_passwd /mosquitto/config/mqttuser zwavejs
Password:
# docker exec -it mosquitto mosquitto_passwd /mosquitto/config/mqttuser nodered
Password:
# docker exec -it mosquitto mosquitto_passwd /mosquitto/config/mqttuser rhasspy
Password:

Restart the container to make sure the new users are loaded:

#  docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
25ca17ccb63b eclipse-mosquitto "/docker-entrypoint.…" 12 hours ago Up 12 hours 0.0.0.0:1883->1883/tcp, :::1883->1883/tcp mosquitto
# docker restart 25ca17ccb63b

Step 7: Deploy Z-Wave JS

Official documentation and reference details can be found at: https://www.home-assistant.io/integrations/zwave_js/#advanced-installation-instructions

Make sure the Z-Wave USB dongle is connected to the server. You can find out the actual path by performing the following command::

# ls -l /dev/serial/by-id/
total 0
lrwxrwxrwx 1 root root 13 jan  6 12:30 usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0 -> ../../ttyUSB0

Edit  /root/dockers/homeassistant/docker-composer.yml and add Z-Wave JS as a service (if you need z-wave connectivity). Define your dongle as the appropriate serial device to pass through:

version: '3'
services:
  <--- 
           previous added Mosquitto Service section 
  --->
  zwave-js-ui:
    container_name: zwave-js-ui
    image: zwavejs/zwave-js-ui:latest
    labels:
      com.centurylinklabs.watchtower.monitor-only: "true"
    restart: always
    tty: true
    environment:
      - SESSION_SECRET=mysupersecretkey
      - ZWAVEJS_EXTERNAL_CONFIG=/usr/src/app/store/.config-db
      - TZ=Europe/Amsterdam
    devices:
      # Do not use /dev/ttyUSBX serial devices, as those mappings can change over time.
      # Instead, use the /dev/serial/by-id/X serial device for your Z-Wave stick.
      - '/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0:/dev/zwave'
    volumes:
      - /opt/zwavejs:/usr/src/app/store
    ports:
      - '8091:8091' # port for web interface
      - '127.0.0.1:3000:3000' # port for Z-Wave JS websocket server

Deploy the container

# cd /root/dockers/homeassistant
# docker-compose up -d

Check docker deployment

# docker ps
CONTAINER ID   IMAGE                                          COMMAND                  CREATED        STATUS                  PORTS                                                                 NAMES
517f788b4522    containrrr/watchtower:latest                  "/watchtower --inter…"   4 seconds ago  Up 3 seconds            8080/tcp                                                              watchtower
25ca17ccb63b   eclipse-mosquitto                              "/docker-entrypoint.…"   12 hours ago   Up 12 hours             0.0.0.0:1883->1883/tcp, :::1883->1883/tcp                             mosquitto
eab0a341624e   zwavejs/zwave-js-ui:latest                     "docker-entrypoint.s…"   13 hours ago   Up 13 hours             127.0.0.1:3000->3000/tcp, 0.0.0.0:8091->8091/tcp, :::8091->8091/tcp   zwave-js-ui

Check the log files

# docker logs eab0a341624e
2023-01-07 05:59:47.266 INFO APP: Version: 8.6.2.faa2543
2023-01-07 05:59:47.268 INFO APP: Application path:/usr/src/app
  ______  __          __                      _  _____     _    _ _____
 |___  /  \ \        / /                     | |/ ____|   | |  | |_   _|
    / /____\ \  /\  / /_ ___   _____         | | (___     | |  | | | |
   / /______\ \/  \/ / _' \ \ / / _ \    _   | |\___ \    | |  | | | |
  / /__      \  /\  / (_| |\ V /  __/   | |__| |____) |   | |__| |_| |_
 /_____|      \/  \/ \__,_| \_/ \___|    \____/|_____/     \____/|_____|

2023-01-07 05:59:47.292 WARN STORE: scenes.json not found
2023-01-07 05:59:47.326 INFO APP: Listening on port 8091 host 0.0.0.0 protocol HTTP
2023-01-07 05:59:47.351 INFO MQTT: Connecting to mqtt://home.internal.cyberfront.org:1883
2023-01-07 05:59:47.419 INFO BACKUP: Backup job started with cron: 0 0 * * *. Next run: 1/8/2023, 12:00:00 AM
2023-01-07 05:59:47.420 WARN BACKUP: Nvm backup is disabled
2023-01-07 05:59:47.442 INFO Z-WAVE: Connecting to /dev/zwave
Logging to file:
        /usr/src/app/store/logs/zwavejs_2023-01-07.log

Visit the Z-Wave JS UI by visiting http://<server-url>:8091, there are a few actions to perform there.

  1. In the general section enable authentication and define a password
  2. Define a MQTT server in the configuration section:
    • Define MQTT fqdn
    • Define MQTT username: zwavejs
    • Define MQTT password: password you defined in previous Mosquitto deployment

The blog will skip the discovery of actual Z-Wave devices. Visit the Z-Wave JS site for more information. Once your dongle discover devices they will be visible and manageable via this portal.

Check the log files you should see Z-Wave JS logging into Mosquitto

# docker logs 25ca17ccb63b
1673069229: New client connected from 172.19.0.1:47800 as ZWAVE_GATEWAY-zwave-js-ui (p2, c1, k60, u'zwavejs').

Step 8: Deploy Home Assistant

Edit  /root/dockers/homeassistant/docker-composer.yml and add Home Assistant as a service:

version: '3'
services:
  <--- 
           previous added Mosquitto / Z-Wave JS Service sections 
  --->
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    labels:
      com.centurylinklabs.watchtower.monitor-only: "true"
    volumes:
      - /opt/homeassistant/config:/config
      - /etc/localtime:/etc/localtime:ro
      - /run/dbus:/run/dbus:ro
    environment:
      - TZ=Europe/Amsterdam
    restart: unless-stopped
    privileged: true
    network_mode: host
    depends_on:
      mosquitto:
        condition: service_started
      zwave-js-ui:
        condition: service_started

Deploy the container

# cd /root/dockers/homeassistant
# docker-compose up -d

Check docker deployment

# docker ps
CONTAINER ID   IMAGE                                          COMMAND                  CREATED        STATUS                  PORTS                                                                 NAMES
517f788b4522   containrrr/watchtower:latest                   "/watchtower --inter…"   4 seconds ago  Up 3 seconds            8080/tcp                                                              watchtower
25ca17ccb63b   eclipse-mosquitto                              "/docker-entrypoint.…"   13 hours ago   Up 13 hours             0.0.0.0:1883->1883/tcp, :::1883->1883/tcp                             mosquitto
16bfc1370c7e   ghcr.io/home-assistant/home-assistant:stable   "/init"                  13 hours ago   Up 12 hours                                                                                   homeassistant
eab0a341624e   zwavejs/zwave-js-ui:latest                     "docker-entrypoint.s…"   13 hours ago   Up 13 hours             127.0.0.1:3000->3000/tcp, 0.0.0.0:8091->8091/tcp, :::8091->8091/tcp   zwave-js-ui

Check the log files

# docker logs 16bfc1370c7e
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun home-assistant (no readiness notification)
s6-rc: info: service legacy-services successfully started

Visit the Home Assistant UI by visiting http://<your server>:8123. There are a few actions to perform:

  1. Define your username/password as administrator
  2. Under Settings -> Devices & Services -> (Bottom right) Add Integration
    • Z-Wave -> select “ws://localhost:3000”
    • MQTT -> MQTT
      • Broker : FQDN of MQTT server
      • Port: 1833
      • username: homeassistant
      • password: password you defined in previous section

Check the log files you should see Z-Wave JS logging into Mosquitto

# docker logs 25ca17ccb63b
1673069626: New client connected from 192.168.1.30:42937 as 4cNxVdIoaOQzDYNlBCBXVq (p2, c1, k60, u'ho

Step 9: Deploy Node-RED

Edit  /root/dockers/homeassistant/docker-composer.yml and add Node-RED as a service:

version: '3'
services:
  <--- 
           previous added Mosquitto / Z-Wave JS / Home Assistant Service sections 
  --->
  nodered:
    container_name: nodered
    image: nodered/node-red
    ports:
      - "1880:1880"
    volumes:
      - /opt/nodered/data:/data
    depends_on:
      - homeassistant
    environment:
      TZ: "Europe/Amsterdam"
    restart: unless-stopped

Deploy the container

# cd /root/dockers/homeassistant
# docker-compose up -d

Check docker deployment

# docker ps
CONTAINER ID   IMAGE                                          COMMAND                  CREATED        STATUS                  PORTS                                                                 NAMES
517f788b4522   containrrr/watchtower:latest                    "/watchtower --inter…"  4 seconds ago  Up 3 seconds            8080/tcp                                                              watchtower
25ca17ccb63b   eclipse-mosquitto                              "/docker-entrypoint.…"   13 hours ago   Up 13 hours             0.0.0.0:1883->1883/tcp, :::1883->1883/tcp                             mosquitto
16bfc1370c7e   ghcr.io/home-assistant/home-assistant:stable   "/init"                  13 hours ago   Up 13 hours                                                                                   homeassistant
eab0a341624e   zwavejs/zwave-js-ui:latest                     "docker-entrypoint.s…"   13 hours ago   Up 13 hours             127.0.0.1:3000->3000/tcp, 0.0.0.0:8091->8091/tcp, :::8091->8091/tcp   zwave-js-ui
0722f9051100   nodered/node-red                               "./entrypoint.sh"        15 hours ago   Up 15 hours (healthy)   0.0.0.0:1880->1880/tcp, :::1880->1880/tcp                             nodered

Check the log files

# docker logs 0722f9051100
Welcome to Node-RED
===================

7 Jan 04:44:41 - [info] Node-RED version: v3.0.2
7 Jan 04:44:41 - [info] Node.js  version: v16.16.0
7 Jan 04:44:41 - [info] Linux 5.19.0-28-generic x64 LE
7 Jan 04:44:42 - [info] Loading palette nodes
7 Jan 04:44:42 - [info] Settings file  : /data/settings.js
7 Jan 04:44:42 - [info] Context store  : 'default' [module=memory]
7 Jan 04:44:42 - [info] User directory : /data
7 Jan 04:44:42 - [warn] Projects disabled : editorTheme.projects.enabled=false
7 Jan 04:44:42 - [info] Flows file     : /data/flows.json
7 Jan 04:44:42 - [info] Creating new flow file
7 Jan 04:44:42 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

7 Jan 04:44:42 - [info] Server now running at http://127.0.0.1:1880/
7 Jan 04:44:42 - [warn] Encrypted credentials not found
7 Jan 04:44:42 - [info] Starting flows
7 Jan 04:44:42 - [info] Started flows

Edit  /opt/homeassistant/config/configuration.yaml and add Node RED as an iPanel so that Home Assistant administrators can manage it:

<--- 
     Other Home Assistant Data
--->
panel_iframe:
   nodered:
    title: Node-RED
    icon: mdi:lan
    url: http://<node-red-fqdn>:1880/
    require_admin: true

Edit  /opt/homeassistant/config/configuration.yaml and add intent section:

<--- 
     Other Home Assistant Data
--->
intent:

Create additional users and generate an long-lived  API token for them. The steps are as follows:

  • Login to Home Assistant as Administrator
  • Create another ‘person’, change that person so that it has login permissions, define a password
  • Login with that user, select your profile settings and at the bottom you can generate a long-lived API token.
  • Create a new user for the following:
    • rhasspy -> new user and long-lived API token
    • nodered -> new user and long-lived API token

Step 10: Deploy Rhasspy

Currently using a Anker PowerConf S330 with USB to connect to Rhasspy, providing both a microphone and speaker. Make sure this device is updated to the latest firmware using the AnkerWorks app. Once completed connect to your server and lookup its usb interfaces:

# ls -l /dev/serial/by-id/
total 0
lrwxrwxrwx 1 root root 13 jan  6 12:30 lnlsnlslnslnslnlslns -> ../../ttyUSB1

Edit  /root/dockers/homeassistant/docker-composer.yml and add Home Assistant as a service:

version: '3'
services:
  <--- 
           previous added Mosquitto / Z-Wave JS / Home Assistant / Node RED Service sections 
  --->
  rhasspy:
    image: "rhasspy/rhasspy"
    container_name: rhasspy
    restart: unless-stopped
    volumes:
        - "/opt/rhasspy/profiles:/profiles"
        - "/etc/localtime:/etc/localtime:ro"
    ports:
        - "12101:12101"
    devices:
        - "/dev/snd:/dev/snd"
    command: --user-profiles /profiles --profile en
    depends_on:
      mosquitto:
          condition: service_started
      homeassistant:
        condition: service_started

Deploy the container

# cd /root/dockers/homeassistant
# docker-compose up -d

Check docker deployment

# docker ps
CONTAINER ID   IMAGE                                          COMMAND                  CREATED        STATUS                  PORTS                                                                 NAMES
517f788b4522   containrrr/watchtower:latest                   "/watchtower --inter…"   4 seconds ago  Up 3 seconds            8080/tcp                                                              watchtower
25ca17ccb63b   eclipse-mosquitto                              "/docker-entrypoint.…"   13 hours ago   Up 13 hours             0.0.0.0:1883->1883/tcp, :::1883->1883/tcp                             mosquitto
0d336aef64e7   rhasspy/rhasspy                                "bash /usr/lib/rhass…"   13 hours ago   Up 13 hours             0.0.0.0:12101->12101/tcp, :::12101->12101/tcp                         rhasspy
16bfc1370c7e   ghcr.io/home-assistant/home-assistant:stable   "/init"                  13 hours ago   Up 13 hours                                                                                   homeassistant
eab0a341624e   zwavejs/zwave-js-ui:latest                     "docker-entrypoint.s…"   14 hours ago   Up 14 hours             127.0.0.1:3000->3000/tcp, 0.0.0.0:8091->8091/tcp, :::8091->8091/tcp   zwave-js-ui
0722f9051100   nodered/node-red                               "./entrypoint.sh"        15 hours ago   Up 15 hours (healthy)   0.0.0.0:1880->1880/tcp, :::1880->1880/tcp                             nodered

Check the log files

# docker logs 0d336aef64e7 
[INFO:2023-01-07 06:11:37,938] rhasspyserver_hermes: Started
[DEBUG:2023-01-07 06:11:37,939] rhasspyserver_hermes: Starting web server at http://0.0.0.0:12101
Running on 0.0.0.0:12101 over http (CTRL + C to quit)

Visit the Rhasspy administration url by visiting http://<yourserver>:12101 and change the following settings:

  1. Define your username/password as administrator
  2. Change siteId
  3. Under Settings -> Change the following:
    •  MQTT
      • Set to External
      • Host: MQTT FQDN
      • Port: 1833
      • Username: rhasspy
      • Password: Password defined in previous section
    • Wakeword
      • set to porcupine (recommended)
    • Speech to Text:
      • set to Kaldi (recommended
    • Intent Recognito
      • set to Fsticuffs (recommended)
    • Intent Handling
      • set to Home Assistant
      • Hass URL: http://<homeseer fqdn>:8123
      • Access Token: access login token generated in previous section for user rhasspy
      • Send intents to Home Assistant (/api/intent/handle)

Step 11: Deploy HACS

Following the HACS deployment procedures defined in https://hacs.xyz/docs/setup/download/. Make sure you have a functional github account and deploy HACS for some extra integration and frontend support options (beta):

# docker exec -it homeassistant bash
bash-5.1# wget -O - https://get.hacs.xyz | bash -

Once this is completed, restart Home Assistant docker container. Under device and integration section you will be able to add HACS as a new integration. Once you complete this, you will get a code you need to enable in Github, once this is completed restart Docker Container again.