ESPHome Docker ttyUSB0 port does not exist?

I’m hoping someone can help me as this problem is driving me nuts.

I’m running an ubuntu 22.04 server and have installed esphome using the docker image with the following compose file

version: "3"
name: home
services:
  homeassistant:
    image: lscr.io/linuxserver/homeassistant:latest
    container_name: homeassistant
    network_mode: host
    environment:
      - PUID=1010 # homeassistant
      - PGID=1010 # homeassistant
      - TZ=Australia/Sydney
    volumes:
      - /opt/docker/appdata/home-assistant:/config
    devices:
      - /dev/ttyUSB0:/dev/ttyUSB0 #optional
    restart: unless-stopped

  esphome:
    image: ghcr.io/esphome/esphome
    container_name: esphome
    network_mode: host
    user: 1011:1011 # esphome
    environment:
      PLATFORMIO_CORE_DIR: .plattformio
      PLATFORMIO_GLOBALLIB_DIR: .plattformioLibs
    volumes:
      - /opt/docker/appdata/esphome:/config
      - /etc/localtime:/etc/localtime:ro
    devices:
      - /dev/ttyUSB0:/dev/ttyUSB0
    restart: unless-stopped

After running the compose file I am able to login to the web interface of esphome without issue. I am not setting up an HTTPS connection so I have connected my device to my home server via usb. I add new device, enter a name, and then select the option to ‘plug into the computer running the ESPHome dashboard. I see a USB Serial /dev/ttyUSB0 option and click on it. It then goes through the installation and compiling process then I get the following:

========================= [SUCCESS] Took 28.44 seconds =========================
INFO Successfully compiled program.
esptool.py v4.6.2
Serial port /dev/ttyUSB0
ERROR Running command failed: Could not open /dev/ttyUSB0, the port doesn't exist
ERROR Please try running esptool.py --before default_reset --after hard_reset --baud 460800 --port /dev/ttyUSB0 --chip esp8266 write_flash -z --flash_size detect 0x0 /config/.esphome/build/ag-pro/.pioenvs/ag-pro/firmware.bin locally.
INFO Upload with baud rate 460800 failed. Trying again with baud rate 115200.
esptool.py v4.6.2
Serial port /dev/ttyUSB0
ERROR Running command failed: Could not open /dev/ttyUSB0, the port doesn't exist
ERROR Please try running esptool.py --before default_reset --after hard_reset --baud 115200 --port /dev/ttyUSB0 --chip esp8266 write_flash -z --flash_size detect 0x0 /config/.esphome/build/ag-pro/.pioenvs/ag-pro/firmware.bin locally.

So far I have tried adding the esphome used to the dialout group and rebooted the system with no luck.

I’m also confident that the device is on ttyUSB0 since the ESPHome docker container won’t be created properly unless the device is attached at the time.

Any help would be great. I’m really a noob with all this.

Don’t be confident, test!

ls -l /dev/ttyUSB0

Output:

crw-rw---- 1 root dialout 188, 0 Dec 24 17:07 /dev/ttyUSB0
1 Like

Can the esphome user access the device. If not add it to dialout group. But not sure this is the problem, reading the error message…

I have added the esphome user to the dialout group and rebooted the system but it didn’t solve the issue.

Within the esphome container, can you see the USB device, and what ownership and permissions does it show.

You got it.

I went in the container’s shell and it had no user name. So I changed the docker compose file to the following and the problem was solved.

esphome:
    image: ghcr.io/esphome/esphome
    container_name: esphome
    network_mode: host
    environment:
      - PUID=1011
      - PGID=1011
    volumes:
      - /opt/docker/appdata/esphome:/config
      - /etc/localtime:/etc/localtime:ro
    devices:
      - /dev/ttyUSB0:/dev/ttyUSB0
    restart: unless-stopped
    

Wherever I got the original code from was somewhat incorrect. Rookie mistake I guess.

Thanks

1 Like

Don’t forget to mark nicks post as the solution in case others need to find it.