Cannot get Docker containered Home-Assistant to see the USB z-wave stick

I am setting up my Home Assistant in Docker on a Lubuntu mini-PC. I just got tired of the Raspberry Pi (with HASSIO) in terms of it taking forever to restart after config changes. After a break-down, where I could not even restart Hassio anymore, I decided to run it in Docker on a more powerful machine. And indeed, HASS becomes supersnappy in the Docker setup, and I made some good progress thanks to the Home Assistant / Docker videos on the BurnsHA YouTube-channel. Currently, I got Home Assistant, InfluxDB and Mosquitto running very smoothly in Docker.

However, I have spent a lot of hours and a lot of different guides from the Internet trying to get my Z-wave working. I had it running in Raspberry fine - with an Aeotec Z-wave stick, Aeotec three 6-in-1 sensors and eight Eurotronic Spirit radiator thermostats.

It appears that Home-Assistant cannot “see” the stick. Of course, Home-Assistant needs to be able to communicate with the USB port and z-wave stick on my Lubuntu host machine - from within its Docker container.

So, I found a number of forum posts and other, with people having similar problems. Mainly around making the USB port with the z-wave stick available to the Docker container in which HASS runs.

A first step is to identify the USB port in which the z-wave controller is. I found some information on how to do this and identified the port as:
/dev/ttyACM0. So far, so good.

I found some posts on how to spin up a container with the USB port mapped to the container. Suggested adding the “–privileged” part to the “-v /dev…” mapping. So - full command:

sudo docker run -d \--name="home-assistant" \--restart on-failure \--privileged -v /dev/ttyACM0:/dev/ttyACM0 \--label=com.centurylinklabs.watchtower.enable=false \-v /Users/demelo/HASS/hass_config:/config \-e "TZ=Europe/Copenhagen" \-p 8123:8123 \homeassistant/home-assistant

My configuration.yaml said:
zwave:
usb_path: /dev/ttyACM0

But, I read that since one of the recent Home Assistant versions, there is no longer need for this in, and I took it out.

But - no success. I get this in the OZW_Log.txt:
2018-12-23 12:14:32.295 Always, OpenZwave Version 1.4.3254 Starting Up
2018-12-23 12:14:33.026 Info, Setting Up Provided Network Key for Secure Communications
2018-12-23 12:14:33.026 Warning, Failed - Network Key Not Set
2018-12-23 12:14:33.026 Info, mgr,     Added driver for controller /dev/tty
2018-12-23 12:14:33.027 Info,   Opening controller /dev/tty
2018-12-23 12:14:33.027 Info, Trying to open serial port /dev/tty (attempt 1)
2018-12-23 12:14:33.027 Error, ERROR: Cannot open serial port /dev/tty. Error code 6
2018-12-23 12:14:33.027 Error, ERROR: Failed to open serial port /dev/tty
2018-12-23 12:14:33.027 Warning, WARNING: Failed to init the controller (attempt 0)
2018-12-23 12:14:38.027 Info,   Opening controller /dev/tty
2018-12-23 12:14:38.028 Info, Trying to open serial port /dev/tty (attempt 1)
2018-12-23 12:14:38.028 Error, ERROR: Cannot open serial port /dev/tty. Error code 6
2018-12-23 12:14:38.028 Error, ERROR: Failed to open serial port /dev/tty
2018-12-23 12:14:38.028 Warning, WARNING: Failed to init the controller (attempt 1)
2018-12-23 12:14:43.028 Info,   Opening controller /dev/tty
2018-12-23 12:14:43.028 Info, Trying to open serial port /dev/tty (attempt 1)
2018-12-23 12:14:43.028 Error, ERROR: Cannot open serial port /dev/tty. Error code 6
2018-12-23 12:14:43.028 Error, ERROR: Failed to open serial port /dev/tty
2018-12-23 12:14:43.028 Warning, WARNING: Failed to init the controller (attempt 2)
2018-12-23 12:14:48.029 Info,   Opening controller /dev/tty
2018-12-23 12:14:48.029 Info, Trying to open serial port /dev/tty (attempt 1)
2018-12-23 12:14:48.029 Error, ERROR: Cannot open serial port /dev/tty. Error code 6
2018-12-23 12:14:48.029 Error, ERROR: Failed to open serial port /dev/tty
2018-12-23 12:14:48.029 Warning, WARNING: Failed to init the controller (attempt 3)
2018-12-23 12:14:53.029 Info,   Opening controller /dev/tty
2018-12-23 12:14:53.029 Info, Trying to open serial port /dev/tty (attempt 1)
2018-12-23 12:14:53.029 Error, ERROR: Cannot open serial port /dev/tty. Error code 6
2018-12-23 12:14:53.029 Error, ERROR: Failed to open serial port /dev/tty
2018-12-23 12:14:53.029 Warning, WARNING: Failed to init the controller (attempt 4)
2018-12-23 12:14:53.029 Detail, contrlr, Notification: DriverFailed

So - I am confused that Home Assistant tries /dev/tty and not /dev/ttyACM0. But cannot figure out why.

I found something here: https://github.com/OctoPrint/docker/issues/7 (see post by JMERICH April 13) - I followed JMERICH’s post, but I still get:
2018-12-24 10:48:24.235 Always, OpenZwave Version 1.4.3254 Starting Up
2018-12-24 10:48:24.922 Info, Setting Up Provided Network Key for Secure Communications
2018-12-24 10:48:24.922 Warning, Failed - Network Key Not Set
2018-12-24 10:48:24.923 Info, mgr, Added driver for controller /dev/tty
2018-12-24 10:48:24.923 Info, Opening controller /dev/tty
2018-12-24 10:48:24.923 Info, Trying to open serial port /dev/tty (attempt 1)
2018-12-24 10:48:24.923 Error, ERROR: Cannot open serial port /dev/tty. Error code 6
2018-12-24 10:48:24.923 Error, ERROR: Failed to open serial port /dev/tty
2018-12-24 10:48:24.923 Warning, WARNING: Failed to init the controller (attempt 0)
… (continues for a number of attempts)…

So - I am really lost here.

Any ideas? next steps?

1 Like

You don’t add access to a device by making a -v mount. You need to use “–device”.

Here is my HA docker run command:

sudo docker run -d --name="home-assistant" --restart=unless-stopped -v /home/finity/docker/hass-config:/config -v /etc/localtime:/etc/localtime:ro -v /home/finity/docker/sshkey/.ssh:/root/.ssh --device /dev/zigbee:/dev/zigbee --device /dev/ttyUSB-ZStick-5G:/dev/ttyUSB-ZStick-5G --net=host homeassistant/home-assistant

I’ve persisted my USB names in udev rules so that’s why they are not consistent with standard naming but you can just replace them with you correct USB device names.

Thanks, @finity - I changed the “-v” to “- -device”. Restarted the whole thing. No success. Would you mind sharing your rules-file content? and do you have anything in your configuration.yaml?

I still get this:
2018-12-25 10:59:01.565 Always, OpenZwave Version 1.4.3254 Starting Up
2018-12-25 10:59:02.141 Info, Setting Up Provided Network Key for Secure Communications
2018-12-25 10:59:02.141 Warning, Failed - Network Key Not Set
2018-12-25 10:59:02.142 Info, mgr, Added driver for controller /dev/tty
2018-12-25 10:59:02.142 Info, Opening controller /dev/tty
2018-12-25 10:59:02.142 Info, Trying to open serial port /dev/tty (attempt 1)
2018-12-25 10:59:02.142 Error, ERROR: Cannot open serial port /dev/tty. Error code 6
2018-12-25 10:59:02.142 Error, ERROR: Failed to open serial port /dev/tty
2018-12-25 10:59:02.142 Warning, WARNING: Failed to init the controller (attempt 0)
2018-12-25 10:59:07.142 Info, Opening controller /dev/tty
2018-12-25 10:59:07.142 Info, Trying to open serial port /dev/tty (attempt 1)
2018-12-25 10:59:07.142 Error, ERROR: Cannot open serial port /dev/tty. Error code 6
2018-12-25 10:59:07.142 Error, ERROR: Failed to open serial port /dev/tty
2018-12-25 10:59:07.142 Warning, WARNING: Failed to init the controller (attempt 1)
2018-12-25 10:59:12.142 Info, Opening controller /dev/tty
2018-12-25 10:59:12.142 Info, Trying to open serial port /dev/tty (attempt 1)
2018-12-25 10:59:12.142 Error, ERROR: Cannot open serial port /dev/tty. Error code 6
2018-12-25 10:59:12.142 Error, ERROR: Failed to open serial port /dev/tty
2018-12-25 10:59:12.142 Warning, WARNING: Failed to init the controller (attempt 2)

you need to add the stick to the same docker user group.
the command is
sudo usermod -G dialout “youruser”

I added the following to theend of /etc/udev/rules.d/99-com.rules:

SUBSYSTEM=="tty", ATTRS{idVendor}=="0658", ATTRS{idProduct}=="0200", SYMLINK+="ttyUSB-ZStick-5G"

then in config I have:

zwave:
  usb_path: /dev/ttyUSB-ZStick-5G

But to reiterate what juan said, you also need to add your docker user to the “dialout” group too.

thanks @juan11perez and @finity

not quite there yet. I think I need to state where I am:

  1. I have used finity’s settings for configuration.yaml, and for the 99-com.rules file, ie using the “USB-ZStick-5G” string.
  2. I spin up a Home Assistant container using:
    sudo docker run -d --name=“home-assistant” --restart on-failure --device /dev/ttyUSB-ZStick-5G:/dev/ttyUSB-ZStick-5G–label=com.centurylinklabs.watchtower.enable=false -v /Users/demelo/HASS/hass_config:/config -e “TZ=Europe/Copenhagen” -p 8123:8123 \homeassistant/home-assistant
  3. when I run ls /dev/tty* in a terminal, with and without the stick in the port, I get a bunch of “tty”, but only these two appear only when the stick is in: “/dev/ttyACM0” and “/dev/ttyUSB-ZStick-5G” - leading me to believe that the physical port is ACM0 and now “mapped” to /dev/ttyUSB-ZStick-5G" correctly.

So, the part about adding the docker user to dialout, I think I did. When I run “groups”, I get:
“demelo adm dialout cdrom sudo dip plugdev lpadmin sambashare”. The “demelo” is my own admin user/group - it is how I log into Lubuntu. When I first ran “grep dialout /etc/group”, to see who is in the dialout group, I got “dialout:x:20:demelo”. Now, assuming that the Docker user is root, I ran “sudo usermod -G dialout root”. After that the output of checking who is in the dialout group is “dialout:x:20:demelo,root”.

I have stopped the containers, stopped Docker. Rebooted my box, and brougth Docker back up. I still get:
2018-12-25 19:28:31.106 Always, OpenZwave Version 1.4.3254 Starting Up
2018-12-25 19:28:31.782 Info, Setting Up Provided Network Key for Secure Communications
2018-12-25 19:28:31.782 Warning, Failed - Network Key Not Set
2018-12-25 19:28:31.782 Info, mgr, Added driver for controller /dev/tty
2018-12-25 19:28:31.782 Info, Opening controller /dev/tty
2018-12-25 19:28:31.782 Info, Trying to open serial port /dev/tty (attempt 1)
2018-12-25 19:28:31.782 Error, ERROR: Cannot open serial port /dev/tty. Error code 6
2018-12-25 19:28:31.782 Error, ERROR: Failed to open serial port /dev/tty

Am I mistaken in adding “root” to the dialout group? If so, how do I find the name of the user needed?? Is it the Docker user or the user of the Home-Assistant container?

my stick is on /dev/ttyACM0”

2 Likes

I think your description of what you are doing generally looks correct to me.

There is something strange in your OZW log tho. Here is the beginning of my log:

2018-12-25 09:17:53.737 Always, OpenZwave Version 1.4.3254 Starting Up
2018-12-25 09:18:06.345 Info, Setting Up Provided Network Key for Secure Communications
2018-12-25 09:18:06.346 Info, mgr,     Added driver for controller /dev/ttyUSB-ZStick-5G
2018-12-25 09:18:06.346 Info,   Opening controller /dev/ttyUSB-ZStick-5G
2018-12-25 09:18:06.346 Info, Trying to open serial port /dev/ttyUSB-ZStick-5G (attempt 1)
2018-12-25 09:18:06.346 Info, Serial port /dev/ttyUSB-ZStick-5G opened (attempt 1)

As you can see it’s referencing the entire “/dev/ttyUSB-ZStick-5G” string where yours is trying to open the “/dev/tty” device. I don’t know enough at this point to know why that would be.

The next issue I noticed is that the docker run command has a strange look to it at the “-label” location. It doesn’t look like there is a space between the “5G” and “-label”. And the dash in front of label looks like it’s a long dash instead of two short dashes. I’m not sure if it’s supposed to be a single or double dash but either way it looks weird. I’ve had a word processor reformat two dashes into a single long one before and it caused issues copying & pasting the command instead of just typing it in manually. If that is actually the command you used then it might be causing issues with the mapping of the z stick inside the container which might explain your weird log.

As far as the user, which user did you use to install docker? That’s the user you need to add to the dialout group.

If you check those things and it still won’t work then I’m really not sure where to go from there.

@finity - you are right about the dashes…good spotting! It was wrong and did create a mix of the “5G” and “label” part. However, I fixed it and spun up a new home-assistant container.

After that, I thought I would shell into the container. I did this with “sudo docker exec -it home-assistant /bin/bash”. Once inside, the prompt says “root@d21efd71326e:/usr/src/app#” and I run this command;: “ls -ltr /dev/tty*” to see what is there, and I get this output:

crw-rw---- 1 root dialout 166, 0 Dec 25 19:59 /dev/ttyUSB-ZStick-5G
crw-rw-rw- 1 root root      5, 0 Dec 25 19:59 /dev/tty

So - not really sure what to make of this. But the second line has the “/dev/tty”-only line - that appears in the OZW log. As you point out, it looks strange that the log only has the “/dev/tty” part…

  1. Does the above output from within the container give you any clue? Maybe I did something wrong somewhere in the process causing this?

  2. is there an openzwave config file somewhere?

  3. I am pretty sure I was “root” or “demelo” when creating the docker file. I have no other users. So, when asking who is in the dialout group, this output (that I get) should be right: “dialout:x:20:demelo,root”.

Again - thanks for helping out. I really appreciate that.

just a crazy thought? Am I missing anything related to Open Z-Wave on Lubuntu - that I need to install? or is that built into Home Assistant? - seing that Lubuntu is a stripped down version of Ubuntu…

inside my Home-Assistant log, I get this “Z-Wave Notification DriverFailed : {‘notificationType’: ‘DriverFailed’, ‘homeId’: 0, ‘nodeId’: 255}”

1 Like

You don’t install ANYTHING for Home Assistant on the host OS if you are running in Docker. There are NO dependencies. As long as the Host OS can see it and you can map it through to your container, it should work.

Make sure the host os isn’t accessing the device for anything (did you try to install Open ZWave on the host?)

1 Like

The next thing to look at…

With the new device registry that tries to automatically integrate the zwave component there is achance that the /dev/tty got stuck in there somehow.

Look in the “/.storage/core.config_entries” in you config folder and see if the reference to the “/dev/tty” is in there. If it is then manually edit the file to remove it, making a backup and stopping HA first, tho.

As Moe said, the container itself has no dependencies on the outside OS aside from what you tell it so it shouldn’t intrinsically know that a /dev/tty even exists. So it has to be getting that information from somewhere else. I think…

And when you remove the HA container and re-run it are you removing everything related to the container? I’m not sure what the command line is for that because I use Portainer for container management and it always asks if I want to also remove non-persistent data. I always tell it to do that since the only stuff I care to keep I’ve already persisted in the “run” command. If you aren’t doing that it MIGHT be causing some weird retained data from a previous failed attempt. Just another thought to consider…

@finity - I owe you a beer - this was indeed the problem!! - Now, I see my z-wave stick and other z-wave entities in there. I am sooooo happy!

Greetings from Denmark - You rock, finity! (many thanks for other contributions also)

1 Like