ESPHome docker setup

I’m trying to setup esphome with docker. I figure I might as well document the process for future reference.

I have the following in my docker-compose file:

esphome:
    container_name: esphome
    image: esphome/esphome
    privileged: true
    ports:
      - 6052:6052
    volumes:
      - ${USERDIR}/stacks/homeautomation/esphome:/config:rw
    network_mode: host
    restart: unless-stopped

I’m able to start the container and used the wizard to create a node. However, I’m getting when trying to upload (via USB).

INFO Reading configuration...
INFO Generating C++ source...
INFO Compiling app...
INFO Running:  platformio run -d /config/mbabme280
Processing mbabme280 (platform: [email protected]; framework: arduino; board: d1_mini)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/d1_mini.html
PLATFORM: Espressif 8266 > WeMos D1 R2 & mini
HARDWARE: ESP8266 80MHz 80KB RAM (4MB Flash)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 27 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <ESP8266WiFi> 1.0
|-- <ESP8266mDNS>
|   |-- <ESP8266WiFi> 1.0
|-- <ESPAsyncTCP> 1.2.0
|   |-- <ESP8266WiFi> 1.0
|-- <Hash> 1.0
|-- <esphome-core> 1.12.2
|   |-- <ArduinoJson-esphomelib> 5.13.3
|   |-- <ESP8266WiFi> 1.0
|   |-- <ESP8266mDNS>
|   |   |-- <ESP8266WiFi> 1.0
|   |-- <ESPAsyncTCP> 1.2.0
|   |   |-- <ESP8266WiFi> 1.0
Retrieving maximum program size .pioenvs/mbabme280/firmware.elf
Checking size .pioenvs/mbabme280/firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [====      ]  37.9% (used 31076 bytes from 81920 bytes)
PROGRAM: [===       ]  30.8% (used 321492 bytes from 1044464 bytes)
========================= [SUCCESS] Took 7.18 seconds =========================
INFO Successfully compiled program.
INFO Running:  esptool.py --before default_reset --after hard_reset --chip esp8266 --port /dev/ttyACM0 write_flash 0x0 /config/mbabme280/.pioenvs/mbabme280/firmware.bin
esptool.py v2.6
Serial port /dev/ttyACM0
Connecting........_____....._____....._____....._____....._____....._____....._____

A fatal error occurred: Failed to connect to ESP8266: Timed out waiting for packet header

Found the problem. I’m using VirtualBox and I had to enable USB passthrough and select the new USB device, and use that for the upload.

2 Likes

I’ve personally never used the esphome usb upload function. A always used espflashtool from espeasy when switching from tasmota to esphome.

And now I use the esphome OTA uploader now that everything is switched.

Glad you got it sorted out.

Setting ports to passthrough is redundant when setting network mode as host. FYI.

Anyone know the path for properly referencing the secrets.yaml?
I’m taking existing yaml from within the HA version into a separate Docker instance of ESPHome. Got it up and running and all is ok apart from nearly all of my nodes have !secrets references and therefore fail to validate.
I know where the secrets file is in HA, but with this running in it’s own docker I’m not sure how to map it?

Doesn’t ESPHome use it’s own secrets.yaml file? Mine does and it’s located in the configured data directory where the rest of the yaml files are located.

What @finity said… If I remember right you can link that file to the one in the HA directory which allows you to use the same secret file for both.

You are correct and when ESPHome is used as an integration in HA it works fine, I solved the problem by removing the !include reference within the ESPHome’s secrets file. Now that ESPHome is in a separate docker, keeping the include back to HA’s secrets was a problem as they are separate machines and isolated docker instances. Once I’d copied across the relevant secret items from the HA secrets files to the new ESPHome secrets file, all was well…

1 Like