I bought a couple Sonff Mini’s from Amazon this week, and when I looked for information on how to flash them (to ESPHome in my case) I was surprised by how much digging I had to do. The information is all out there, but one must sort through obsolete and new information across many sites.
I decided to write down the steps I took.
Web sites used:
-
Essential
- Chrome extension for RESTer
- 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 - Does tell how to actually flash OTA
- 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 - Documents API (I found later)
- https://notenoughtech.com/home-automation/sonoff-r3-diy-mode/ - ota_unlock
- 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/ (Old way)
- 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 - Mini DIY mode (not really needed)
- 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 an electric device.
The OTA process I used:
- Create and serve your new firmware:
-
Create the firmware:
-
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
-
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.
-
-
Serve the firmware and its checksum on an accessible file server
- The firmware.bin file 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.
- 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.
-
Connect a power cable to your Sonoff Mini. No need to open it or do anything with jumpers; just hook it up and plug it in. Be careful of those exposed screws hereafter.
-
Make a list of what’s currently connected to your router, so later you can figure out the Sonoff’s IP address. I used “nmap -sL 192.168.1.* | grep (1” on my Linux box.
-
Get your Sonoff Mini’s LED to blink continuously, with no discernable flash pattern. The user manual discusses this. 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.
-
On your computer, look for a WiFi access point created by the Sonoff. It will be named ITEAD-XXXXXXXX. Connect to it with password 12345678.
-
On that same computer, open your browser and access http://10.10.7.1/
-
You should be connected to a (ridiculously zoomed) Sonoff screen. Fill in your router’s SSID and password, and click “Save.”
-
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).
-
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_” For this how-to I’ll say the new Sonoff is at 192.168.86.59, but yours is likely different.
-
Use Chrome plug-in RESTer. Set it for:
- Method: POST
- URL: http://192.168.86.59:8081/zeroconf/info [Change to your Sonoff’s IP)
- Body: {“data”: {}}
Click “SEND.” You should get back a “200 OK” plus a bunch of information about the Sonoff – notably including “otaUnlock”: false
- In RESTer, change that “info” to “ota_unlock” – so my URL is now http://192.168.86.59:8081/zeroconf/ota_unlock and click “SEND.”
- Run the RESTer “info” command again. It should now report “otaUnlock”: true
- Configure RESTer for the OTA flash:
- Method: POST
- URL: http://192.168.86.59:8081/zeroconf/ota_flash (use your Sonoff’s IP)
- 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 includes a lot of applicable information here. Note if you get the hash wrong (e.g., include an extra space inside the quotes as I did) the new firmware will be rejected.
- 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.
- If your Sonoff now shows a steady blink, you’re done. My new ESPHome device soon showed up in Home Assistant.