Flashing ESPHome from Tasmota on ESP32
When I buy “smart” hardware, I try to make sure it is compatible with Home Assistant. For power sockets, I am using the cheap Nous brand for years. In the early years you had to use Tuya Convert to flash them with Tasmota, then convert them to ESPHome. But nowadays they are sold with Tasmota preinstalled, which makes things even easier.
So when I recently bought a Nous A6T outdoor socket, I assumed I could simply flash ESPHome and be done. Until I read this line in the official migration guide:
WARNING! Migrating via OTA on ESP32, from Tasmota v12 (with boot partition) and up is currently not possible! Trying it could soft-brick your device!
Well, my sockets came with Tasmota v14 and use an ESP32 .
The official recommendation is to open the device and flash via serial. But these outdoor plugs can not be opened (I assume for water resistance). So I needed to find a different way.
Luckily there is an open pull request that allows writing the bootloader and changing partitions over the air. Unfortunately this PR is now about 2 years old and hasn't been merged, yet. It took me quite a while to figure out how to use it anyway.
The basic approach is this:
- install the patched (and quite outdated) version of ESPHome
- use it to create a minimal ESPHome image
- flash that image using Tasmota's Firmware Upgrade mechanism
- run the `upload-factory-ota` to repartition the device over the air
- finally install your real ESPHome image
To make the steps 1 to 4 a bit easier, I prepared a Docker image you can use with docker compose.
Clone the repo:
git clone https://github.com/splitbrain/esphome-ota-extend-docker.git cd esphome-ota-extend-docker
Copy the example.yaml.dist and edit it.
cp config/example.yaml.dist config/mydevice.yaml vim config/mydevice.yaml
Make sure it uses the right board configuration and that your network is configured correctly. I would recommend setting the same OTA password that you also use on your real ESPHome setup. Also make sure to configure a fixed IP for now.
Once the config is ready, run the image:
docker compose run --rm esphome ./run.sh
The compose command will build the image for you (step 1) and will run a simple script with which you can do steps 2 and 4. The firmware file for step 3 will be dropped into the config
volume.
Once the procedure is finished, you can go to your real ESPHome instance and create a new config there and update the device as usual. For the first install configure a fixed IP address as well. Once that image is installed, you can remove the IP as mDNS should start working as usual then.