home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
70.16k stars 29.19k forks source link

ZHA crashes when mapping /dev/ttyACM0 in docker-compose.yml #44242

Closed malfroid closed 3 years ago

malfroid commented 3 years ago

The problem

ZHA crashes.

Environment

Problem-relevant configuration.yaml


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

light:
  - platform: group
    name: Kitchen
    entities:
      - light.light_kitchen_ceiling_level_light_color_on_off
      - light.light_kitchen_counter_level_on_off
  - platform: group
    name: Living Room
    entities:
      - light.light_living_room_ceiling_couch_level_light_color_on_off
      - light.light_living_room_ceiling_table_level_light_color_on_off

Traceback/Error logs

2020-12-15 00:51:46 ERROR (MainThread) [zigpy.application] Couldn't start application
2020-12-15 00:51:46 ERROR (MainThread) [homeassistant.components.zha.core.gateway] Couldn't start deCONZ = dresden elektronik deCONZ protocol: ConBee I/II, RaspBee I/II coordinator
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/serial/serialposix.py", line 265, 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-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2214836-if00'

Additional information

Original docker-compose.yml contained:

  homeassistant:
    container_name: home-assistant
    image: homeassistant/raspberrypi4-homeassistant:stable
    network_mode: host
    restart: always
    volumes:
      - /opt/home-assistant:/config
    devices:
      - /dev/ttyACM0:/dev/ttyACM0
    environment:
      - TZ=Europe/Berlin 

Changing the device mapping to by id fixed the problem:

  homeassistant:
    container_name: home-assistant
    image: homeassistant/raspberrypi4-homeassistant:stable
    network_mode: host
    restart: always
    volumes:
      - /opt/home-assistant:/config
    devices:
      - /dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2214836-if00:/dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2214836-if00
    environment:
      - TZ=Europe/Berlin 

Why does the mapping using /dev/ttyACM0 no longer works?

probot-home-assistant[bot] commented 3 years ago

Hey there @dmulcahey, @adminiuga, mind taking a look at this issue as its been labeled with an integration (zha) you are listed as a codeowner for? Thanks! (message by CodeOwnersMention)

Adminiuga commented 3 years ago

This is not a ZHA problem. error says:

File "/usr/local/lib/python3.8/site-packages/serial/serialposix.py", line 265, 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-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2214836-if00'

It can't open /dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2214836-if00 If the serial device is not available (by that exact name) then it cannot open it.

ZHA has no ideas what device being passed to Docker and/or if it was changed. It always would use the same device it was originally configured with.

malfroid commented 3 years ago

When I created the ZHA integration, I believe that I configured the device /dev/ttyACM0 . I never told ZHA to look for the device by ID ( /dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2214836-if00 ) .

Adminiuga commented 3 years ago

Then my only guess, in the original configuration you exposed both acm0 and serial by Id. When both are available, zha prefers (and store) the serial by Id port, as those are assumed to be persistent.