Not able to configure zwave (HA, ubuntu, docker-compose)

I’m trying to get aeotec gen5 zwave stick to work with homeassistant running on ubuntu/docker-compose. It was previously attached to hassbian installation running on pi3 and worked perfectly. I’m moving my services now to PC running ubuntu.

Docker-compose file (HA part). Running in privileged mode to be sure devices are exposed.

version: '3'
services:
  homeassistant:
    container_name: home-assistant
    image: homeassistant/home-assistant
    volumes:
      - /home/juha/homeassistant/conf:/config
      - /etc/localtime:/etc/localtime:ro
#    devices:
#      - /dev/serial/by-id/usb-0658_0200-if00:/dev/ttyAMA0
    privileged: true
    restart: always
    network_mode: host
    depends_on:
      - "mqtt"
      - "nodered"
    user: 1000:1000

The problem is that homeassistant is not accepting the stick.

I can see the stick on the ubuntu machine (removed non relevant):

$ lsusb
Bus 002 Device 004: ID 0658:0200 Sigma Designs, Inc.

The following command to see device and serial

$ ls -1tr /dev/tty*|tail -n 1
/dev/ttyACM0
$ ls -ltr /dev/tty*|tail -n 1
crw-rw---- 1 root dialout 166,  0 maali 23 18:13 /dev/ttyACM0
$ ls -lA /dev/serial/by-id
total 0
lrwxrwxrwx 1 root root 13 maali 23 18:12 usb-0658_0200-if00 -> ../../ttyACM0


I have tried to put in the zwave integrations page:
/dev/serial/by-id/usb-0658_0200-if00
/dev/ttyACM0

Did not work. Then I tried creating a symlink for /zwaveusbstick with UDEV rules, didn’t work either.

This is the list I see in the container

$ docker-compose exec homeassistant sh
$ cd /dev
$ ls
autofs           i2c-3         loop23              rfkill    tty17  tty39  tty60    ttyS23     vcs2
bsg              i2c-4         loop3               rtc0      tty18  tty4   tty61    ttyS24     vcs3
btrfs-control    i2c-5         loop4               sda       tty19  tty40  tty62    ttyS25     vcs4
bus              i2c-6         loop5               sda1      tty2   tty41  tty63    ttyS26     vcs5
core             input         loop6               sg0       tty20  tty42  tty7     ttyS27     vcs6
cpu              kmsg          loop7               sg1       tty21  tty43  tty8     ttyS28     vcsa
cpu_dma_latency  lightnvm      loop8               shm       tty22  tty44  tty9     ttyS29     vcsa1
cuse             loop-control  loop9               snapshot  tty23  tty45  ttyACM0  ttyS3      vcsa2
dri              loop0         mapper              snd       tty24  tty46  ttyS0    ttyS30     vcsa3
drm_dp_aux0      loop1         mcelog              sr0       tty25  tty47  ttyS1    ttyS31     vcsa4
ecryptfs         loop10        mei0                stderr    tty26  tty48  ttyS10   ttyS4      vcsa5
fb0              loop11        mem                 stdin     tty27  tty49  ttyS11   ttyS5      vcsa6
fd               loop12        memory_bandwidth    stdout    tty28  tty5   ttyS12   ttyS6      vfio
full             loop13        mqueue              tpm0      tty29  tty50  ttyS13   ttyS7      vga_arbiter
fuse             loop14        net                 tty       tty3   tty51  ttyS14   ttyS8      vhci
gpiochip0        loop15        network_latency     tty0      tty30  tty52  ttyS15   ttyS9      vhost-net
hidraw0          loop16        network_throughput  tty1      tty31  tty53  ttyS16   ttyprintk  vhost-vsock
hidraw1          loop17        null                tty10     tty32  tty54  ttyS17   uhid       zero
hidraw2          loop18        port                tty11     tty33  tty55  ttyS18   uinput
hpet             loop19        ppp                 tty12     tty34  tty56  ttyS19   urandom
hwrng            loop2         psaux               tty13     tty35  tty57  ttyS2    usb
i2c-0            loop20        ptmx                tty14     tty36  tty58  ttyS20   userio
i2c-1            loop21        pts                 tty15     tty37  tty59  ttyS21   vcs
i2c-2            loop22        random              tty16     tty38  tty6   ttyS22   vcs1

The integration page is only displaying:

Z-Wave validation failed. Is the path to the USB stick correct?

No errors are produced to log. If I add it manually to configuration.yaml I get this. (tried with all as above)

Error setting up entry Z-Wave (import from configuration.yaml) for zwave
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/openzwave/option.py", line 75, in __init__
    raise ZWaveException(u"Can't write to device %s : %s" % (device, traceback.format_exception(*sys.exc_info())))
openzwave.object.ZWaveException: "Zwave Generic Exception : Can't write to device /dev/ttyACM0 : ['NoneType: None\\n']"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/app/homeassistant/config_entries.py", line 302, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/usr/src/app/homeassistant/components/zwave/__init__.py", line 278, in async_setup_entry
    config_path=config.get(CONF_CONFIG_PATH))
  File "/usr/local/lib/python3.7/site-packages/openzwave/option.py", line 81, in __init__
    raise ZWaveException(u"Error when retrieving device %s : %s" % (device, traceback.format_exception(*sys.exc_info())))
openzwave.object.ZWaveException: 'Zwave Generic Exception : Error when retrieving device /dev/ttyACM0 : [\'Traceback (most recent call last):\\n\', \'  File "/usr/local/lib/python3.7/site-packages/openzwave/option.py", line 75, in __init__\\n    raise ZWaveException(u"Can\\\'t write to device %s : %s" % (device, traceback.format_exception(*sys.exc_info())))\\n\', \'openzwave.object.ZWaveException: "Zwave Generic Exception : Can\\\'t write to device /dev/ttyACM0 : [\\\'NoneType: None\\\\\\\\n\\\']"\\n\']'

It implies docker cannot write to the USB device?
I tried running following. I have user: 1000:1000 in the docker-compose so I suppose docker is trying to write with account “juha”? Did not work. Same error.

$ sudo usermod -aG dialout juha

Then I tried to setup HA in virtual environvent without docker stuff. Installed OK, but was not able to create user. Just prompted to login. So I ditched that. Then I tried running HA without docker-compose in “normal” docker with the commands from the HA installation page. Adding the device parameter to pass the stick to container. No luck.

I’m lost. I read similiar posts on the forum but I can’t find any solutions. Hopefully someone knows what my error is?

Need to mount /dev/ttyACM0 as a volume
I believe read only mount is all needed

That must not be true as it is a device, not a volume.

But turns out commenting out my user makes this work.
But then the docker will again create files that are not editable by my user.

version: '3'
services:
  homeassistant:
    container_name: home-assistant
    image: homeassistant/home-assistant
    volumes:
      - /home/juha/homeassistant/conf:/config
      - /etc/localtime:/etc/localtime:ro
    devices:
      - /dev/serial/by-id/usb-0658_0200-if00:/dev/ttyACM0
   # privileged: true
    restart: always
    network_mode: host
    depends_on:
      - "mqtt"
      - "nodered"
#    user: 1000:1000

I’m lost again about the correct way of configuring.

mount as device, sorry about that. your recent post has this correct but I think you have wrong device listed. should be /dev/ttyACM0 or something similar.

Your original post had device commented out and also had ttyACM0 as ttyAMA0
I would imagine this may have caused error if your HA config file had ttyACM0

I think you have the device identified wrong and that is causing all your problems.

version: '3'
services:
  homeassistant:
    container_name: home-assistant
    image: homeassistant/home-assistant
    volumes:
      - /home/juha/homeassistant/conf:/config
      - /etc/localtime:/etc/localtime:ro
    devices:
      - /dev/ttyACM0:/dev/ttyACM0
   # privileged: true
    restart: always
    network_mode: host
    depends_on:
      - "mqtt"
      - "nodered"
#    user: 1000:1000

Yeah I experimented with ttyAMA0, ttyACM0…

It is now mounted based on the serial number to ttyACM0 and is working. But only if I comment out the user: 1000:1000 part.

If the user is included I get write error to the stick. I believe this goes to group/user permissions, file owner etc. of which I don’t have clear understanding.

I have mine set using udev rules in Debian and I run HA (not hassio) in docker. Here is my 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

and in my config file I have this:

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

Also you need to make sure that with all of the experimenting you have done that the information in your .storage/core.device_registry isn’t preventing the correct path from being picked up by HA. If the info in there is different than the info in your config then you will get errors.

It’s possible it was not mounting to same location after host reboots

Usually best to symlink device in udev rules

@taikapanu were you able to figure out how to resolve the “Zwave Generic Exception : Can’t write to device” error?

I have the exact same setup - HomeAssistant installed via docker on a mini computer and trying to setup an AeoTec ZWave Gen 5. Went through all the same steps as well with the same result.

  • Confirmed the user running the docker container is in the dialout group.
  • Created a udev rule to handle the case where the device path changes.

The only way I can get this to work is to remove the user setting in my docker-compose.yml file as you mentioned - which is not what I want to do.

No, I still run it as root.

My experience was the following. I started as root so I couldn’t edit my files witout sudo. Then I set it up with my user ID. I was then able to edit files and all seemed good. Then I put the zwave to the system and it didn’t work. Then it seemed to work when I remove user but I didn’t want to use sudo to edit my config.

The files are created with my user but I run the docker still as root.

I have no idea how to fix it.

@ taikapanu after a lot more testing (including upgrading to Ubuntu 19.04 and trying the latest versions of docker unsuccessfully) and a fair amount of online research, I was actually able to get this to work by slightly modifying the udev rule specified in the documentation.

Everything I was reading was confirming that I had my docker-compose.yml and configuration.yml files setup correctly.

version: '3.7'
services:
  homeassistant:
    container_name: home-assistant
    image: homeassistant/home-assistant
    volumes:
      - /configuration:/config
      - /etc/localtime:/etc/localtime:ro
    restart: always
    network_mode: host
    user: "1000:1000"
    devices:
      - /dev/zwave:/dev/zwave

I verified that my user that was specified in the docker-compose.yml file to run docker was indeed added to the dialout group (non-relevant groups removed).

$ id
uid=1000 gid=1000 groups=1000,20(dialout),998(docker)

When viewing the permissions for the zwave usb stick on my machine I would get the following as expected.

$ ls -al /dev/zwave
 lrwxrwxrwx 1 root root 7 Apr 21 20:39 /dev/zwave -> ttyACM0

$ ls -al /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 Apr 21 20:39 /dev/ttyACM0

Then jumping into the docker container (docker-compose exec homeassistant sh) and running the same command gave the following, again as expected.

$ ls -al /dev/zwave
crw-rw---- 1 root dialout 166, 0 Apr 21 20:42 /dev/zwave

What finally worked for me was modifying the previously mentioned udev rule by adding the MODE property and setting it accordingly.

MODE="0666", SUBSYSTEM=="tty", ATTRS{idVendor}=="0658", ATTRS{idProduct}=="0200", SYMLINK+="zwave"

What this confirms is that it is indeed a permission related issue. The downside of this is that MODE="0666" basically allows any user to read/write to the device.

I tried to restrict this a little by setting MODE="0660" and specifying the property GROUP="dialout" but that didn’t work. More testing and discovered that if I set the GROUP to my specific user’s group, it works. So my final udev rule is below (my actual group name removed).

MODE="0660", GROUP="my-group", SUBSYSTEM=="tty", ATTRS{idVendor}=="0658", ATTRS{idProduct}=="0200", SYMLINK+="zwave"

So I am not sure why setting the GROUP property to my user group works but setting it to the dialout group (to which my user belongs) does not.

2 Likes

Thanks @jkuhlz!
I’ll put that to a test in few days!

I tried following your udev rule and other points. Ended up losing access to front end. Other vise HA seemed to be running fine.

I gave up with the whole thing :smiley:
I’ll just use the sudo :smiley: