Skip to content

Flashing ESPHome via OTA

Charles Powell edited this page Mar 20, 2022 · 3 revisions

Guide

There's an excellent overall guide on the Tuya-Convert OTA process that was at ESPHome-configs.io (site appears to be dead, so I'm pointing to the Web Archive for now).

This guide uses the Docker image and a docker-compose file to avoid needing to permanently install all the required dependencies. The non-Docker approach is very similar if you prefer that route.

Requirements

You'll need the following:

  • Linux computer with a wifi adapter. A RaspberryPi with a wifi dongle works fine, although for simplicity you'll want to either use it connected to a monitor, or have it connected to the network via ethernet. The Wifi adapter will act as a temporary access point, so you can't use it for primary connectivity.
  • Secondary wifi device, such as a smartphone. You'll use this to connect to the temporary Wifi network, and it's necessary for the Tuya-Convert process!
  • Docker installed
  • docker-compose installed

1. Clone Tuya-Convert

git clone https://github.com/ct-Open-Source/tuya-convert
cd tuya-convert

2. Build the Docker image and prepare compose file

Essentially we'll be following the Tuya-Convert Docker process. Building may take some time, depending on your system.

docker build -t tuya:latest .

Below is a modified docker-compose.yml file from the one provided in the Tuya-Convert repo. This compose file adds single-file volumes for the .log files, and for a so you can easily get the output if needed.

NOTE: You may need to chance the WLAN=wlan0 line of the configuration, if your Wifi device has a different name!

Save this file as docker-compose.yml in the tuya-convert folder:

version: '3'
services:
  tuya:
    image: tuya:latest
    privileged: true
    network_mode: "host"
    environment:
      - WLAN=wlan0  # Change if needed!
      - AP=vtrust-flash
      - GATEWAY=10.42.42.1
    volumes:
      # Default volume, to store backups of original firmware and logs
      - ./data/backups:/usr/bin/tuya-convert/backups
      # Single-file volume to pass in a compiled ESPHome binary placed in the /files folder
      - ${PWD}/files/esphome.bin:/usr/bin/tuya-convert/files/esphome.bin

3. Compile & locate your ESPHome binary

[To be expanded] For now, reference the old ESPHome-configs.io instructions for this step.

⚠️ BE CAREFUL: You'll be flashing this binary to your device, so you should make sure values like Wifi names and passwords are correct! You may want to leave the ota: and ap: (fallback hotspot) keys in your ESPHome config, until you're sure everything is working right.

After compiling, copy the firmware named firmware.bin in the ESPHome build folder into the files subfolder of your tuya-convert folder, and rename it to esphome.bin (so the docker-compose file above can find it).

4. Start Tuya-Convert

If not already in the directory, cd into the root of your tuya-convert folder, and then run the following:

docker-compose up -d
docker-compose exec tuya start

5. Tuya-Convert Process

  1. At the prompt, confirm you want to continue (if you so choose).
  2. Tuya-Convert starts the various subprocesses.
  3. At the next prompt, Tuya-Convert notes to connect some other wireless device (phone, tablet, etc., type shouldn't matter) to the vtrust-flash Wifi network that should now be available.
  4. Plug in the smart plug you want to convert, and put it in "pairing" mode per the appropriate method (usually holding a button for ~5 seconds).
  5. Hit ENTER. Tuya-Convert will begin to try and flash your compatible device.
  6. You should hopefully see progress, as Tuya-Convert flashes your device with an intermediate firmware.
  7. Upon an initial flash success, Tuya-Convert will ask what actual firmware you would like to flash to the device. Assuming you placed the ESPHome firmware in the /files folder, you should get three options: (0) return to stock, (1) flash esphome.bin, (2) flash espurna.bin, or (3) flash tasmota.bin. Type 1 to select your ESPHome binary.
  8. Tuya-Convert should proceed to flash your ESPHome compiled binary to your device! Assuming everything went correctly, it should reboot after the flash and attempt to connect as you specified.