Using ZHA and Home Assistant in a Docker container, file not found/no such file or directory for USB stick in /dev

I just decided to try migrating from the python venv install method to the Docker container on the same host. I stopped the python venv, fired up the Docker container and everything worked seamlessly except ZHA. I receive the error

FileNotFoundError: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-Silicon_Labs_HubZ_Smart_Home_Controller_61201CF7-if01-port0'

My user running HA is in the dialout group, and I mapped both /dev/ttyUSB1 and /dev/serial/by-id/usb-Silicon_Labs_HubZ_Smart_Home_Controller_61201CF7-if01-port0 into the container in the docker-compose.yaml file. The stick is the Nortek HUSBZB-1. I’ll probably bail to zigbee2mqtt but I’m waiting on the arrival of a supported Zigbee USB stick. I’d like to figure out what the story is here in the meantime.

TIA!

Isn’t that a symlink?

Yes, the by-id file is just a symlink to /dev/ttyUSB1. My config started with just /dev/ttyUSB1 being mapped through to the container but the error I received then referred only to /dev/serial/by-id/usb-Silicon_Labs_HubZ_Smart_Home_Controller_61201CF7-if01-port0. Any combination of mappings for /dev/ttyUSB1 and /dev/serial/by-id/usb-Silicon_Labs_HubZ_Smart_Home_Controller_61201CF7-if01-port0 in the docker-compose.yaml file produce the same results. /dev/serial/by-id/usb-Silicon_Labs_HubZ_Smart_Home_Controller_61201CF7-if01-port0 is the only device ever mentioned in the error logs.

Here is the complete log from the HA GUI

Logger: homeassistant.components.zha.core.gateway
Source: components/zha/core/gateway.py:152
Integration: Zigbee Home Automation (documentation, issues)
First occurred: 11:51:11 AM (1 occurrences)
Last logged: 11:51:11 AM

Couldn't start EZSP = Silicon Labs EmberZNet protocol: Elelabs, HUSBZB-1, Telegesis coordinator
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/serial/serialposix.py", line 322, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-Silicon_Labs_HubZ_Smart_Home_Controller_61201CF7-if01-port0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/zha/core/gateway.py", line 152, in async_initialize
    self.application_controller = await app_controller_cls.new(
  File "/usr/local/lib/python3.9/site-packages/zigpy/application.py", line 74, in new
    await app.startup(auto_form)
  File "/usr/local/lib/python3.9/site-packages/bellows/zigbee/application.py", line 109, in startup
    self._ezsp = await bellows.ezsp.EZSP.initialize(self.config)
  File "/usr/local/lib/python3.9/site-packages/bellows/ezsp/__init__.py", line 78, in initialize
    await ezsp.connect()
  File "/usr/local/lib/python3.9/site-packages/bellows/ezsp/__init__.py", line 88, in connect
    self._gw = await bellows.uart.connect(self._config, self)
  File "/usr/local/lib/python3.9/site-packages/bellows/uart.py", line 363, in connect
    protocol, connection_done = await thread.run_coroutine_threadsafe(
  File "/usr/local/lib/python3.9/site-packages/bellows/uart.py", line 340, in _connect
    transport, protocol = await serial_asyncio.create_serial_connection(
  File "/usr/local/lib/python3.9/site-packages/serial_asyncio/__init__.py", line 445, in create_serial_connection
    serial_instance = serial.serial_for_url(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/serial/__init__.py", line 90, in serial_for_url
    instance.open()
  File "/usr/local/lib/python3.9/site-packages/serial/serialposix.py", line 325, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port /dev/serial/by-id/usb-Silicon_Labs_HubZ_Smart_Home_Controller_61201CF7-if01-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-Silicon_Labs_HubZ_Smart_Home_Controller_61201CF7-if01-port0'

I was able to workaround the issue by creating the /dev/serial/by-id/usb-Silicon_Labs_HubZ_Smart_Home_Controller_61201CF7-if01-port0 symlink by hand inside the running container. That won’t survive a reboot, so now I’m not sure if this is a Zigbee issue or a container issue.

That’s a docker thing. The symlink is not propagated to the container.

Edit /config/.storage/core.config_entries and replace /dev/serial/by-id/usb-Silicon_Labs_HubZ_Smart_Home_Controller_61201CF7-if01-port0 by /dev/ttyUSB1 in the ZHA configuration, then restart the container.

Adding the symlink to the docker-compose.yaml file like this:

    volumes:
      - /home/homeassistant/.homeassistant:/config
      - /etc/localtime:/etc/localtime:ro
      - /dev/serial/by-id//usb-Silicon_Labs_HubZ_Smart_Home_Controller_61201CF7-if01-port0:/dev/serial/by-id/usb-Silicon_Labs_HubZ_Smart_Home_Controller_61201CF7-if01-port0

Allows the symlink to appear in the container and ZHA works correctly. Is there any reason to do things differently?