Hassio-zigbee2mqtt: Enable access to host's /dev/serial/by-id devices

Created on 5 Sep 2018  Â·  20Comments  Â·  Source: danielwelch/hassio-zigbee2mqtt

When one has more than one USB dongle, hassio will randonmly assign the physical devices to the ttyACM* interfaces. Systems with more than 1 dongle may render usless when they are rebooted by accident. At the moment, the container can't access the serial/by-id devices

~ # docker ps -a
CONTAINER ID        IMAGE                                         COMMAND                  CREATED             STATUS                     PORTS                                                                NAMES
2f0ef30d2662        homeassistant/raspberrypi3-64-homeassistant   "/bin/entry.sh pytho…"   6 days ago          Up 6 days                                                                                       homeassistant
4fa118bce970        homeassistant/aarch64-hassio-supervisor       "python3 -m hassio"      7 days ago          Up 7 days                                                                                       hassos_supervisor
ea5c97a93ad2        dwelch2101/zigbee2mqtt-aarch64                "./run.sh"               9 days ago          Up 9 days                                                                                       addon_7ad98f9c_zigbee2mqtt
253df2a3f200        homeassistant/aarch64-addon-ssh               "/run.sh"                9 days ago          Up 9 days                  0.0.0.0:22->22/tcp                                                   addon_core_ssh
3df813ed1720        homeassistant/aarch64-addon-mariadb           "/usr/bin/entry.sh /…"   9 days ago          Up 9 days                  0.0.0.0:3306->3306/tcp                                               addon_core_mariadb
f62f1df2829d        homeassistant/aarch64-addon-mosquitto         "/run.sh"                9 days ago          Up 9 days                  0.0.0.0:1883-1884->1883-1884/tcp, 0.0.0.0:8883-8884->8883-8884/tcp   addon_core_mosquitto
a6647fd3fc70        homeassistant/aarch64-addon-letsencrypt       "/usr/bin/entry.sh /…"   12 days ago         Exited (1) 12 days ago                                                                          addon_core_letsencrypt
fc8c23a4890b        hassioaddons/node-red-aarch64                 "/init"                  2 weeks ago         Exited (129) 2 weeks ago                                                                        addon_a0d7b954_nodered
~ # docker exec -it ea5c97a93ad2 /bin/ls -l /dev/
total 466
lrwxrwxrwx    1 root     root            13 Aug 27 21:47 fd -> /proc/self/fd
crw-rw-rw-    1 root     root        1,   7 Aug 27 21:47 full
-rwxr-xr-x    1 root     root        476800 Jul 16 00:55 init
drwxrwxrwt    2 root     root            40 Aug 27 21:47 mqueue
crw-rw-rw-    1 root     root        1,   3 Aug 27 21:47 null
lrwxrwxrwx    1 root     root             8 Aug 27 21:47 ptmx -> pts/ptmx
drwxr-xr-x    2 root     root             0 Aug 27 21:47 pts
crw-rw-rw-    1 root     root        1,   8 Aug 27 21:47 random
drwxrwxrwt    2 root     root            40 Aug 27 21:47 shm
lrwxrwxrwx    1 root     root            15 Aug 27 21:47 stderr -> /proc/self/fd/2
lrwxrwxrwx    1 root     root            15 Aug 27 21:47 stdin -> /proc/self/fd/0
lrwxrwxrwx    1 root     root            15 Aug 27 21:47 stdout -> /proc/self/fd/1
crw-rw-rw-    1 root     root        5,   0 Aug 27 21:47 tty
crw-rw----    1 root     audio     166,   0 Aug 27 21:47 ttyACM0
crw-rw----    1 root     audio     166,   1 Sep  5 22:29 ttyACM1
crw-rw----    1 root     audio     204,  64 Aug 27 21:47 ttyAMA0
crw-rw-rw-    1 root     root        1,   9 Aug 27 21:47 urandom
crw-rw-rw-    1 root     root        1,   5 Aug 27 21:47 zero

enabling access to serial/by-id devices would help workaround this undesired behaviour by hardcoding the interface

enhancement

All 20 comments

Do we know if this is supported for hassio addons? After poking around a few issues, it’s not clear to me, and the dev docs don’t help much. Currently, I’m using the auto_uart option, which is supposed to automatically map all serial devices but doesn’t offer any specifics, and clearly isn’t covering this use case. I may have to look into the hassio source code to see how this is handled and if it’s possible. Any help is appreciated.

@danielwelch unfortunally not, I'm not very knowledgeable in hassio :( I really thank you for your work here and hope you can find a way to address this. May I help somehow?

@marcgarciamarti

Until this is sorted out, maybe it would be possible to parse the output from https://github.com/home-assistant/hassio/blob/dev/API.md#hardware on startup of the add-on, identify the port of interest, and set the configuration accordingly.

We could add an optional configuration option with a device name to check for.

Hello @danielwelch is there anything I can do to help?

Hey, I hit a roadblock on this. Turns out, as far as I can tell, that the Hassio api doesn’t give additional information other than what serials are available. So that doesn’t really help identify the one of interest if you have more than one.

Looks like some progress has been made on this in HassOS 1.12 with static/persistent udev rules. I haven’t looked closely but it’s mentioned in the release notes

Many thanks @danielwelch! I hope that opens the door for refining the configuration :)

Hello @danielwelch any update on this? I'm wondering if there is anything I can do to contribute here. Many thanks again!

I'm having this same problem. I thought it might have to do with the 'protection mode' feature that was recently introduced, but it still can't access it even with that feature off. That said, with Hass.io, isn't Home Assistant also run in a docker container, just like the add-ons? Because I know that HA can directly access the /dev/serial/by-id/* devices.

EDIT: I also found this comment on a post about a similar issue a while back with HA on hass.io.
https://github.com/home-assistant/hassio/issues/485#issuecomment-394298723

He says adding this to the dockerfile fixed it for him:

devices:

  • /dev/ttyUSB0:/dev/ttyUSB0
  • /dev/serial/by-id/usb-FTDI_P1_Converter_Cable_P11RSL4D-if00-port0

That said, with Hass.io, isn't Home Assistant also run in a docker container, just like the add-ons? Because I know that HA can directly access the /dev/serial/by-id/* devices.

that is correct. I think this is a result of hassio running home assistant in a privileged container.
https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities
at least it was like this in the past. I think, if you also can start the addon with this mode enabled, all devices should be accessible. However I don't know if this is possible.

@deisi from the hass.io dev docs, it looks like the full_access option might be what we need. I'll try enabling this in the edge version soon.

There's also the devicetree option which I think is fairly new.

Hello. Any progress with this enhancement? I use 3 usb to serial in one machine. So every reboot I have new ttyACM* numbers. Two works with serial/by-id/.

Happens on restart as well using Hassio; any update on this?

Would love to see this added.

would also love to specify the usb by id; at the moment while addtionally using a zwave GEN5 stick the dev id's get mixed up on each reboot and that is why zigbee2mqtt at the moment for me on hassio docker does not work. thanks for your support

Any progress?

Not in hassos but in Ubuntu which is what I am running it on. It did not work. The addon could not access the udev based device name.

It seems to work now. I'm running Home Assistant 0.97.0 with zigbee2mqtt 1.5.1.2. Look up the required id unter Hass.io/System/Hardware.

Can this be closed? I see latest HassOS & Supervisor (HassIO) show named devices. I get

- serial:
     - /dev/ttyACM0
     - /dev/ttyAMA0
     - /dev/serial/by-id/usb-Texas_Instruments_TI_CC2531_USB_CDC___0X00124B0012022452-if00
Was this page helpful?
0 / 5 - 0 ratings