How To: Flash a Sonoff Mini to ESPHome – 2021-01 version

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:

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:

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

  2. 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.

  3. 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.

  4. 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.

  5. On that same computer, open your browser and access http://10.10.7.1/

  6. You should be connected to a (ridiculously zoomed) Sonoff screen. Fill in your router’s SSID and password, and click “Save.”

  7. 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).

  8. 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.

  9. 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
  1. 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.”
  2. Run the RESTer “info” command again. It should now report “otaUnlock”: true
  3. Configure RESTer for the OTA flash:
{
"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.

  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.
6 Likes

Thanks a lot for that tuto as I myself lost also a lot of time to figure out ho to flash these devices. I have to say that Sonoff has made a really great f*cking bad job with these devices as there are multiple versions with different behaviours and contradictive explanations !
Unhappy even with your tuto my units still fail as they never show up the ITEAD-XXXX Wifi AP. I have 3 of them and same on all 3, I have the blue led that blinks once every 2/3 seconds and that’s it ! If I hold the white plastic button on it, it doesn’t change anything too :frowning:
When did you get your Mini ? Bought mine few months ago from Aliexpress and Sonoff support is completely unhelpful on that :frowning:

Curious. I’ve bought mine from Amazon, “the Sonoff store”, within the last few weeks. The first batch had jumpers in the package and a place to put a jumper under the cover; the second batch doesn’t. All came with (from my memory) version 1.5 of the original firmware.

You probably know this, but I think you’re not seeing an ITEAD access point because your Sonoffs aren’t going into AP mode, as indicated by your blue led blink pattern - AP mode is indicated by a rapidly (perhaps 2x per second) blinking led, which you aren’t seeing. This link discusses blink patterns - though it’s confusing, like everything Sonoff seems to be. One blink per 2s seems to mean the Sonoff can’t find the router - either there’s not a 2.4G router available (they won’t use 5G) or it’s too far away.

I did have one device that didn’t want to go into AP mode. I took it through several power cycles and holding down the button, and I THINK what worked was:

  1. Power cycle
  2. Hold down button for 10s, release
  3. (Repeat) Hold down button for 10s, release.

but I wouldn’t swear to it; I just know I finally got the rapid blink, and was able to flash.

Part of me is tempted to buy a lifetime supply of these now, though that would feel like rewarding Sonoff’s inconsistency.

1 Like

Very helpful description, I’m surprised there aren’t more replies to this post!

Thank you!

I am a little late here, and maybe this is off-topic… but
I just built a programming jig:


And program the mini like any other Sonoff device using Tasmotizer or espeasy.

Pogo Pins:
https://www.amazon.com/dp/B01913L0UK?psc=1&ref=ppx_pop_dt_b_asin_title

Thingverse Programming Jig:

2 Likes

Hi,

Thanks for this. I managed to get my device to connect to my wifi but I couldn’t get the REST POSTs to work, they would just hang.

I almost gave up and was about to solder one the UART, but I found this:
SONOFF API For Developer

and the really useful tool in particular by the manufacturer(?):
GitHub - itead/Sonoff_Devices_DIY_Tools

Which at least proves my device works, it has a firmware upload option - I’ve yet to try this, I may even hold off if the APIs with the OOB firmware work as required in HA.

1 Like

One of the sonoff minir2 I bought has the issue that the REST POST API just hangs. did you find a solution for this?

@gianm Try

{ 
    "deviceid": "", 
    "data": { } 
 }

instead of

{
    “data”: { }
}

in the body.
Worked for me.
Source: SONOFF API For Developer

1 Like

Great tutorial, works like a charm!

I just share with you I directly used Home Assistant built in ability to serve the .bin file: HTTP - Home Assistant

Thank you.

Just what I was looking for, thank you!!!

Glad to see that you could get it working! I had 4 Mini R2’s that I had tried to flash to ESPHome and absolutely could not get Home Assistant to see them. The ESPHome add-on could see it and I could adopt it and flash it, but HA never saw it at all.

I just gave up and flashed them with Tasmota.

unfortunately I found this one a little bit to late,
after esphome bricked on it I destroyed my miniR2 with the soldering iron, touched some components which I shouldn’t have.
but I still have another one, and if that one bricks, I at least know there is a way to fix this without soldering