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'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'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't look for them. 2. You also need the sha256 checksum of firmware.bin. On my Ubuntu box I "sudo apt install hashalot" and then used "sha256sum firmware.bin", 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's connected to your router. I used "nmap -sL 192.168.1.\* | grep \(1" on my Linux box. 4. Get your Sonoff Mini's LED to blink continuously, with no discernable flash pattern. If it's flashing two shorts and a long, press and hold the button for about five seconds. If you'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's SSID and password, and click "Save." 8. If that works (you might get a "request fail" on the screen even if it worked), your Sonoff will start blinking slowly and steadily, indicating it'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'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 "esp\_" or with "eWeLink". For illustration, I'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's IP) 3. Body: {"data": {}} 4. Click "SEND." You should get back a "200 OK" plus a bunch of information about the Sonoff – notably including "otaUnlock": false 11. In RESTer, change that "info" to "ota\_unlock" – so my URL is now [http://192.168.86.59:8081/zeroconf/ota\_unlock](http://192.168.86.59:8081/zeroconf/ota_unlock) Click "SEND." 12. Run the RESTer "info" command again. It should now report "otaUnlock": 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's IP) 3. Body: { "deviceid": "", "data": { "downloadUrl": "http://www.myserver.com/myfilearea/firmware.bin", "sha256sum": "187dce36882b63ddf7ea9a76f99821b97f95c5c246b23a703c92c5f22b01bc0f" } } Change the entries after downloadUrl and sha256sum to match your file server and hash. Hit "SEND." 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 "200 OK," but if you watch the access log on your server you'll see the download takes a little while (about 15 seconds for my setup). If you can't watch the server log, wait a while to be sure it finishes. 2. If your Sonoff now shows a steady blink, you're done. My new ESPHome device soon showed up in Home Assistant.