Shelly Gen 3 OTA Conversion Keeping OTA Capabilities

I was looking for how to convert my Shelly 1 PM Mini Gen 3 and Shelly PM Mini Gen 3’s to ESPHome but I didn’t find a lot of information except for some posts that made it seem like you’d lose OTA functionality by doing it. So I used the information I could find and put this together for anyone else who’s trying to do the same. I successfully flashed 1x Shelly 1 PM Mini Gen 3 and 2x Shelly PM Mini Gen 3 and am able to push OTA updates from ESPHome so it seems like they’re working just fine.
Disclaimer, I only tried this on the 2 devices I listed above so I’m not 100% sure how it will be for other Shelly devices. I also bricked a PM Mini trying to do this because I messed up the partition table update. So be careful and double check what you’re doing.

Here’s where I collected information from, I couldn’t have done it without these posts:
https:// community.home-assistant .io/t/shelly-esphome-ota-conversion-guide/794350
https:// github .com/esphome/esphome/pull/5535#issuecomment-2801352955
https:// github .com/esphome/esphome/pull/5535#issuecomment-2801352955
https:// www.cellos .blog/fixing-connection-issues-by-flashing-esphome-on-shellys-ota/

(I’m only allowed to post 2 links so I had to break those up like that.)

Overview
Basically we’re setting up a fork of ESPHome to be able to update the partition table OTA. Then we’re flashing Shelly convert to Tasmota, GitHub - tasmota/mgos32-to-tasmota32: ESP32 Mongoose OS to Tasmota32 OTA updates for Shelly, updating the partition layout, flashing a basic ESPHome bin file that we create with the fork, updating the partitions again, and then flashing our final ESPHome bin file that will let us use it with your regular ESPHome.

Configure the ESPHome branch

  1. All of the below is done from a linux computer
  2. git clone https://github.com/angelnu/esphome-1.git --branch=extend_ota
  3. cd esphome-1
  4. pipenv install
  5. pipenv shell
  6. cd esphome-1
  7. python3 -m pip install --upgrade pip
  8. python3 -m pip install -r requirements.txt
  9. python3 setup.py install
  10. In the esphome-1 folder create test.yaml
  11. Example for Shelly 1 PM Mini Gen 3:
esphome:
  name: test
  platformio_options:
    board_build.flash_mode: dio
esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: esp-idf
    platform_version: 6.4.0
    version: 5.1.1
  variant: esp32c3
wifi:
  networks:
  - ssid: "NETWORK"
    password: "PASSWORD"
ota:
  password: "OTAPASSWORD"
  unprotected_writes: True
logger:
  hardware_uart: USB_SERIAL_JTAG
web_server:
button:
- platform: restart
  name: Restart
  1. Just create something for your OTA Password, it can be anything
  2. Make sure to set your network ssid and password
  3. Edit your hosts file, /etc/hosts, and set the IP for your Shelly to be test.local
  4. python -m esphome compile test.yaml
  5. Make sure it compiles without issue
  6. Keep this terminal window open, we’ll be using it later.

Flash the Shelly with Tasmota

  1. Download the appropriate release from Releases · tasmota/mgos32-to-tasmota32 · GitHub
  2. Go to the Shelly’s webpage and flash the file downloaded above
  3. Once flashed, connect to the Tasmota AP and add to your wifi
  4. Once on the network, go to its webpage from your computer
  5. Click on Configuration > Auto-configuration, and select the model you’re flashing, then hit apply
  6. Once it reboots go to Consoles > Partition Wizard and click Start migration
  7. Once it reboots go to Tools > Partition Wizard and click Resize FS to max
  8. Once it reboots go to Tools > Console > type SetOption78 1 and press enter
  9. You should see RESULT = {"SetOption78":"ON"}
  10. Go to Firmware Upgrade > Choose file, and browse to the esphome bin we created earlier, it’s under the esphome-1 directory and then .esphome/build/test/.pioenvs/test/firmware.bin
  11. Select and then Start upgrade
  12. You should see Upload Successful and then the page will refresh and you’ll see the esphome webpage
  13. In the terminal we used earlier run python -m esphome -v upload-factory-ota test.yaml

Home Assistant ESPHome Config

  1. Look up the ESPHome config template for your device and use that to create a minimal config in your ESPHome
  2. Just keep the basics for now, esphome, esp32, api, ota, wifi, captive_portal, we’ll add the rest later
  3. Install > Manual download > OTA format (Previously Legacy)
  4. Move the downloaded file to your esphome-1 folder
  5. In the same terminal as before run: python -m esphome -v upload test.yaml --file “new esphome”.bin
  6. If all was successful if should be discovered by Home Assistant and it will show online in ESPHome so you can now update the config and push an OTA update.
3 Likes

Good job!

Nice guide, thanks. But, is this whole (quite complex) process possible to bypass with simply opening device and flash it via UART first time? I mean - so far i always converted all my shellies that way: i open it, solder needed connections and flash it. Yes, i know, it needs opening device (possibly warranty void?) and precise work…

Problem with Gen3’s is, they’re too darn small to solder…

This is how I’ve flashed 20 ish mini gen3’s.:+1:
(they’re great as bluetooth proxies!)

Yeah, agreed. Not for me, though…i have a microscope, so it’s not a problem, that’s why i’d like to know if this is the “bypass” way…

Thanks for the tutorial!

I was able to recover my “OTA-bricked” shelly mini - used Windows with WSL.

My shelly 1 mini gen3 has Shelly’s firmware 1.6.2 installed (with an option to update to 1.7.0). Has anyone managed to convert from that state to ESPHome using the instructions above?

I have tried Shelly Plus 1 with 1.4.x firmware, flashed Tasmota successfully, first ESPHome OTA was successful, but command python -m esphome -v upload-factory-ota failed with:

DEBUG Auth: Result is 8c40dc0d29fdfeac9d9d3ace7d425c41
INFO Uploading .esphome/build/peak-light-switch/.pioenvs/peak-light-switch/partitions.bin (3072 bytes)
DEBUG Partition info: [1, 3, 0, 0, 12, 0, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
DEBUG MD5 of upload is e5b569933677bc0b3debb254e74eb9bf
Uploading: [============================================================] 100% Done...

INFO Upload took 0.00 seconds, waiting for result...
INFO OTA successful
INFO Connecting to 192.168.130.89
DEBUG Features: [2, 3, 4, 5]
DEBUG Auth: Nonce is c034415b0cb7340fe792df73303b7100
DEBUG Auth: CNonce is bad3b6c6d065affc2606cd191a8cdced
DEBUG Auth: Result is 90a59771edaec996d528a49ab109dfa3
INFO Uploading .esphome/build/peak-light-switch/.pioenvs/peak-light-switch/firmware.bin (823504 bytes)
DEBUG Partition info: [1, 4, 0, 12, 144, 208, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 97, 112, 112, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
ERROR Error binary size: Error: device aborted flash that would have overriden running partition. Check your device log for more information.
INFO Trying to restore the partition table backup ...
INFO Connecting to 192.168.130.89
DEBUG Features: [2, 3, 4, 5]
DEBUG Auth: Nonce is 407e236350ab3d496df90f3c47ceed5f
DEBUG Auth: CNonce is b5f7dfdfec312770df6774723b2abcd2
DEBUG Auth: Result is 78dc6586651ea0f752b1c4bf710933d4
INFO Uploading /tmp/tmpv4rr__wf (4096 bytes)
DEBUG Partition info: [1, 3, 0, 0, 16, 0, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
DEBUG MD5 of upload is f912f704f0d827af8a9d88dee9a468df
Uploading: [============================================================] 100% Done...

INFO Upload took 0.00 seconds, waiting for result...
INFO OTA successful

Device itself says:

16:14:07	[I]	[ota:464]	

OTA type is 4 and size is 823504 bytes

16:14:07	[E]	[ota:110]	

Aborting to avoid overriding running partition

16:14:07	[E]	[ota:112]	

New partition - addr: 0x0e0000; size: 0x2b0000

16:14:07	[E]	[ota:114]	

Running partition - addr: 0x0e0000; size: 0x2b0000

Have you had any luck with a serial flash recently?
I’ve got a batch of Gen 3 Shelly 1 (the standard blue version, not the PM Shelly 1 Gen3) and just can’t get the flash to fully comelete and work following a reboot. I’ve successfully connected following the method I’ve used for years (lots of shelly one, shelly 2.5, dimmers, RGB etc etc mostly gen 1 and gen 2 devices), this is connecting UART via the exposed pin headers and using ESPflasher or Tasmotizer to deliver the package.

For some reason with these new Gen 3 devices I’ve had no success. I’ve tried the Tasmota lite version, tried the BIN files, and tried the GZ files but not luck.

Anyone know what specific tasmota version is needed for the initial flash on these devices?

does this method work with the bl0942? I’m getting junk from and a lot of errors for the energy monitoring

[16:48:34.973][W][bl0942:082]: BL0942 invalid checksum! 0x52 != 0x00
[16:48:35.184][W][bl0942:058]: Junk on wire. Throwing away partial message (1 bytes)