Flashing a Sonoff Mini to ESPHome – as of 2021-01

Web sites used:

- Essential
  - Chrome extension for RESTer
  - [https://tasmota.github.io/docs/Sonoff-DIY/](https://tasmota.github.io/docs/Sonoff-DIY/) - Most of the process, but doesn&#39;t tell how to actually flash OTA
  - [https://blog.lukaskukacka.com/smarthome/2020/09/09/sonoff-mini-firmware-3.6-flashing-tasmota.html](https://blog.lukaskukacka.com/smarthome/2020/09/09/sonoff-mini-firmware-3.6-flashing-tasmota.html) - Does tell how to actually flash OTA
  - [https://esphome.io/devices/sonoff.html](https://esphome.io/devices/sonoff.html) - YAML for ESPHome
- Nice to know
  - [https://github.com/itead/Sonoff\_Devices\_DIY\_Tools/blob/master/SONOFF%20DIY%20MODE%20Protocol%20Doc%20v2.0%20Doc.pdf](https://github.com/itead/Sonoff_Devices_DIY_Tools/blob/master/SONOFF%20DIY%20MODE%20Protocol%20Doc%20v2.0%20Doc.pdf) - Documents API (I found later)
  - [https://notenoughtech.com/home-automation/sonoff-r3-diy-mode/](https://notenoughtech.com/home-automation/sonoff-r3-diy-mode/) - ota\_unlock
  - [https://notenoughtech.com/home-automation/is-sonoff-diy-2-0-better/](https://notenoughtech.com/home-automation/is-sonoff-diy-2-0-better/) - DIY in general
- Not used but read
  - [https://www.reddit.com/r/homeassistant/comments/di4mrk/guide\_howto\_flash\_the\_sonoff\_mini\_with\_tasmota/](https://www.reddit.com/r/homeassistant/comments/di4mrk/guide_howto_flash_the_sonoff_mini_with_tasmota/) (Old way)
  - [http://dl.itead.cc/mini/C\_Instructions/MINIR2\_V1.1\_User\_manual\_20201218.pdf](http://dl.itead.cc/mini/C_Instructions/MINIR2_V1.1_User_manual_20201218.pdf) - Mini user manual (Not needed)
  - [http://developers.sonoff.tech/sonoff-diy-mode-api-protocol.html](http://developers.sonoff.tech/sonoff-diy-mode-api-protocol.html) - Mini DIY mode (not really needed)
  - [http://developers.sonoff.tech/sonoff-diy-mode-api-protocol.html](http://developers.sonoff.tech/sonoff-diy-mode-api-protocol.html) - Old and not applicable

Disclaimer: I don&#39;t take any responsibility for any damages or other harm caused by anything in this article. Please make sure you know what you are doing and stay safe. You are working with electric device.

Process used:

1. Create and serve your new firmware:
  1. Create the firmware:
    1. Method 1: Download a generic Tasmota image. You can use this to get your device flashed, and then later flash your ESPHome image OTA using the Tasmota interface
    2. Method 2: Go directly to ESPHome (which I did): Using the YAML from esphome.io/devices, generate a firmware.bin file for your use. I greatly favor assigning a static IP address.
  2. Serve the firmware and its checksum on an accessible file server
    1. The firmware.bin file, and its sha256 hash checksum (might be optional, but I did it), must be available on your local network as a URL. If you have shell access to a publicly-accessible Linux server (I do) that works well. Alternatively, you could use Docker, mohamnag/nginx-file-browser or equivalent, to temporarily serve the file on your local machine / network. There are probably other options; I had a file server available so didn&#39;t look for them.
    2. You also need the sha256 checksum of firmware.bin. On my Ubuntu box I &quot;sudo apt install hashalot&quot; and then used &quot;sha256sum firmware.bin&quot;, which gave me a long string of characters. Copy-paste them somewhere for later use.
2. Connect a power cable to your Sonoff Mini. No need to open it or do anything with jumpers; just hook it up.
3. Make a list of what&#39;s connected to your router. I used &quot;nmap -sL 192.168.1.\* | grep \(1&quot; on my Linux box.
4. Get your Sonoff Mini&#39;s LED to blink continuously, with no discernable flash pattern. If it&#39;s flashing two shorts and a long, press and hold the button for about five seconds. If you&#39;ve done things to this Sonoff before this you might have to do that twice, and you might need to power cycle it.
5. On your computer, look for a WiFi access point named ITEAD-XXXXXXXX. Connect to it with password 12345678.
6. On that same computer, open your browser and access [http://10.10.7.1/](http://10.10.7.1/)
7. You should be connected to a (ridiculously zoomed) Sonoff screen. Fill in your router&#39;s SSID and password, and click &quot;Save.&quot;
8. If that works (you might get a &quot;request fail&quot; on the screen even if it worked), your Sonoff will start blinking slowly and steadily, indicating it&#39;s now connected to your network. (Also the ITEAD-XXXXXXX access point will have disappeared, and your computer might have gone back to being connected to your network).
9. Find the Sonoff&#39;s IP address, preferably by comparing the current list of things connected to your router to the list you made above. If you have a complicated network this can be a nuisance. My Sonoffs showed up as devices starting with &quot;esp\_&quot; or with &quot;eWeLink&quot;. For illustration, I&#39;ll say the new Sonoff is at 192.168.86.59, but yours is likely different.
10. Use Chrome plug-in RESTer. Set it for:
  1. Method: POST
  2. URL: [http://192.168.86.59:8081/zeroconf/info](http://192.168.86.59:8081/zeroconf/info) [Change to your Sonoff&#39;s IP)
  3. Body: {&quot;data&quot;: {}}
  4. Click &quot;SEND.&quot; You should get back a &quot;200 OK&quot; plus a bunch of information about the Sonoff – notably including &quot;otaUnlock&quot;: false
11. In RESTer, change that &quot;info&quot; to &quot;ota\_unlock&quot; – so my URL is now [http://192.168.86.59:8081/zeroconf/ota\_unlock](http://192.168.86.59:8081/zeroconf/ota_unlock) Click &quot;SEND.&quot;
12. Run the RESTer &quot;info&quot; command again. It should now report &quot;otaUnlock&quot;: true
13. Configure RESTer:
  1. Method: POST
  2. URL: [http://192.168.86.59:8081/zeroconf/ota\_flash](http://192.168.86.59:8081/zeroconf/ota_flash) (use your Sonoff&#39;s IP)
  3. Body:

{

&quot;deviceid&quot;: &quot;&quot;,

&quot;data&quot;: {

&quot;downloadUrl&quot;: &quot;http://www.myserver.com/myfilearea/firmware.bin&quot;,

&quot;sha256sum&quot;: &quot;187dce36882b63ddf7ea9a76f99821b97f95c5c246b23a703c92c5f22b01bc0f&quot;

}

}

Change the entries after downloadUrl and sha256sum to match your file server and hash. Hit &quot;SEND.&quot; Note that [https://blog.lukaskukacka.com/smarthome/2020/09/09/sonoff-mini-firmware-3.6-flashing-tasmota.html](https://blog.lukaskukacka.com/smarthome/2020/09/09/sonoff-mini-firmware-3.6-flashing-tasmota.html) includes a lot of applicable information here. Note if you get the hash wrong (e.g., include an extra space in the quotes) the new firmware will be rejected.

1. You should get an immediate &quot;200 OK,&quot; but if you watch the access log on your server you&#39;ll see the download takes a little while (about 15 seconds for my setup). If you can&#39;t watch the server log, wait a while to be sure it finishes.
2. If your Sonoff now shows a steady blink, you&#39;re done. My new ESPHome device soon showed up in Home Assistant.
