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.
1 Like