Flash Sonoff MiniR2(firmware 3.6.0) with ESPHome Over the Air

I hope this instruction on how you can flash the Sonoff MiniR2 with with firmware 3.6.0(without the jumper) using a ESPHome .bin created from the ESPHome integration and Sonoffs DIY tool.

WARNING i don’t know if its possible to reverse the part where you unlock OTA in step 7.

All credit goes to Chad on YouTube How to flash Tasmota on a Sonoff MINIR2 with firmware 3.6.0. There is no jumper on this version - YouTube and this is mostly a write up of that video.

  1. Setup a 2.4GHz WiFi access point with;

SSID: sonoffDiy
Security Mode: WPA-Personal
Wireless password: 20170618sn

  1. Connect the Sonoff Mini R2 to power, wait for it to flash the blue LED in pulses of three, hold the button the Sonoff for approximately 5 seconds and it should start to single flash fast. After a short time it should come up as an “ITEAD-something” access point in your available networks

  2. Connect to the ITEAD-access point using
    Wireless password: 12345678

You should now have been given an IP-address of 10.10.7.2 by the ITEAD-access point

  1. Open a web browser and enter the ITEAD-access points IP-address as url
    10.10.7.1

You should now be presented with an overly zoomed in web page like this

  1. Click on “WIFI SETTING”

You should now be presented with

  1. Enter the following and then click “Save”

Network name(SSID): sonoffDiy
Network password: 20170618sn

The Sonoff should now connect to the SSID you set up at step one.

If you need to, look up the IP-address the Sonoff got by for example checking your routers DHCP leases, i had my DHCP pool for this network set so i got 192.168.1.20x.You need to replace this with your Sonoffs IP-address. In my case i was doing ten of these i had to delete/clear the DHCP lease for each Sonoff as i progressed i cant tell why but if i didn’t i had to start over from step two(2) after i cleared the lease.

  1. Here i used the RESTer plugin for Chrome (RESTer - Chrome Web Store). And added the following as shown in the screenshots.

Choose Method “POST”

Enter URL: http://192.168.1.204:8081/zeroconf/info
Click “BODY”
Enter: {“data”: {}}

Click “SEND”

It should return some information like in the screenshot

To enable Over the Air (WARNING, i don’t know if its possible to set this back to false) updates edit the URL to
URL: http://192.168.1.204:8081/zeroconf/ota_unlock

Click “SEND”

It should return some new information and “error”: 0

The last step here is just if you want to check that “otaUnlock” should be set to ‘true’.
Enter URL: http://192.168.1.204:8081/zeroconf/info

Click “SEND”

And you should hopefully get a result like this

  1. Open up the DIY tool (i used tool_01DIY85(3.3.0 from here Sonoff_Devices_DIY_Tools/tool at master · itead/Sonoff_Devices_DIY_Tools · GitHub).exe)

The Sonoff should be visible, you can try toggling the relay to be sure that the one listed is the one we are working with.

Click “Firmware flash”
sonoff_diy_2

In the dialog that opens, select your ESPHome .bin file you created for it(Chad flashes it using a Tasmota .bin so i guess any compatible firmware should work but i haven’t tried).

Now you are at the point of no return so double check everything.

Click “Flash device list” even if there is a device listed

Now you are even closer the point of no return so double check everything again.

Click OK to start the flash process
sonoff_diy_3

That should be all, momentarily you ESPHome flashed Sonoff should be discovered by the integration.

Here’s my config for these if it is any use to someone, its frankensteined from this forum and other sources

substitutions:
  device_name: sonoff_mini_r2_template

esphome:
  name: ${device_name}
  platform: ESP8266
  board: esp8285

wifi:
  networks:
  - ssid: the_ssid
    password: the_password
    hidden: true
  manual_ip:
    gateway: 192.168.2.1
    subnet: 255.255.255.0
    static_ip: 192.168.1.178
  domain: .localdomain

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${device_name}_Hotspot"
    password: "the_fallback_password"

captive_portal:

# Enable logging
logger:

# Enable Web server
web_server:
  port: 80

# Enable Home Assistant API
api:
#  password: "api_password"

# Enable Over The Air update
ota:
#  password: "ota_password"

time:
  - platform: homeassistant
    id: homeassistant_time

sensor:
# Extra sensor to keep track of plug uptime
  - platform: uptime
    name: ${device_name}_Uptime Sensor
    filters:
      - lambda: return x / 3600;
    unit_of_measurement: "hours"
    accuracy_decimals: 2

# Extra sensor for WiFi signal
  - platform: wifi_signal
    name: ${device_name}_WiFi Sensor
    update_interval: 60s

status_led:
  pin:
    number: GPIO13
    inverted: true

output:
  - platform: gpio
    id: relay_1
    pin: GPIO12

light:
  - platform: binary
    id: light_1
    name: ${device_name}_Lights
    output: relay_1    

binary_sensor:
  - platform: gpio
    pin: GPIO00
    id: reset
    internal: true
    filters:
      - invert:
      - delayed_off: 10ms
    on_press:
      - light.toggle: 
          id: light_1

  - platform: gpio
    name: ${device_name}_Lights
    pin: GPIO04
    id: switch_1
    on_press:
      then:
#        - switch.turn_on:
        - light.toggle: 
            id: light_1
    on_release:
      then:
#        - switch.turn_off:
        - light.toggle: 
            id: light_1
5 Likes

If you are having trouble with the above method or use Linux/Mac this method is much faster and easier to do, as you don’t need to create a special hotspot with a specific password:

Take a look at this repository and download the script:

Quick instructions:
1.- Power on the sonoff
2.- press the button for 5 seconds
3.- Connect to the ITEAD-xxx hotspot
4.- Browse to http://10.10.7.1
5.- Enter your home wifi settings
6.- Connect your computer back to your home network
7.- Locate the IP address of the sonoff given by your router.
8.- Run the script this way:

./sonoff-ota-flash.sh -i ip_address_of_sonoff

Wait for a bit until the flashing finishes. And voilà!, Tasmota will be installed

Flashing ESPHome:

9.- Connect to the tasmota-xxx hotspot
10.- Browse to 192.168.4.1
11.- Enter your home WiFi Settings
12.- Connect back to your home network
13.- Browse to http://ip_address_of_sonoff in your home network
14.- Select firmware upgrade and select the esphome binary file you have created.

Explanation video:

6 Likes

I have a sonoff mini DIY wifi (I think it is the first version, not the R2), will this process work as well or I need to do something different? (I think there is a little “jumper” that I need to use in order to start the flashing process…)

any help is much appreciated.

Thank you

Hi,

Sorry for the late reply. Unfortunately i don’t know but according to this guide How To: Flash a Sonoff Mini to ESPHome – 2021-01 version it kind of indicates that it should (looking at “The OTA process I used” step 2, 3 and 4). But i really have no idea as i only have R2s, sorry.

BTW, thanks for adding the linux method @jpeletier looks way easier if you have a linux/mac box

Hello, by any chance, does the SonOff mini R2 support bluetooth? Can we use it for bluetooth proxy? Trying to see what existing device I already have to perform this instead of buying and adding a dedicated one.

Hi, to my knowledge the R2s uses an ESP8285 or 8266 and doesn’t have BT.

Thanks a lot! Saved me some time on soldering as I did before ))

Did you manage to update the firmware on the Mini v1 with this method? Amy additional step was required?

Hi everyone, today I tried to flash Sonoff mini with firmware 3.6. I can’t use sonoff diy tool to flash due to network limitations (tool can’t find the device) and did it as previously (few months ago) via RestApi. Today I successfully switched mini to diy mode, unlocked ota, but when I tried to flash it I got failed: http response 200, error: 0 but device didn’t flashed. I tried modern and legacy formats of firmware built by ESPHome with same result. Does anyone have idea what goes wrong and how to fix it?

I found the solution for my case:

  1. I used the script posted by @jpeletier and flashed my Sonoff Mini R2 (3.6) with Tasmota firmware 10.0
  2. I found manual Migrating from Sonoff Tasmota — ESPHome. Please read carefull all notes: set option in Tasmota console and reboot.
  3. I updated Tasmota firmware with minimal version.
  4. I prepared ESPHome firmware, downloaded it in legacy format and compressed it with gzip.
  5. Updated firmware via Tasmota UI.

Has anyone got this working with a Dual R3 lite? The hotspot I get puts the device on 192.168.1.1 and if I browse to that I just get a base64 encoded string.

Hi,
after i run the script, terminal is locked on “Unlocking for OTA flashing…” for some time, and next receive this error

curl: (52) Empty reply from server
Error posting to: http://xxxxxxxxxxx/zeroconf/ota_unlock

can you help me, please?

Anyone has issues with devices that have firmware 3.7 or laters?

I can get it in DIY mode, it ask for the wifi password, i fill it it, device reboots, is pingable but doesnt respond to any of the REST/POST messages. It just hangs or says error posting to the device.

A device with firmware 3.6 doesnt have any issues…

yeah, same. I get this error:

curl: (56) Recv failure: Connection reset by peer

Edit: Left for few hours, and I was able to send post messages. Weird.

Edit2: Ok, so after I realized I can send post messages, I went to this tutorial: Flashing Tasmota firmware onto Sonoff devices over-the-air: “How-to” using just a terminal and web-browser - CGomesu
Then on tasmota web UI, I went to configuration > configure other. And pasted line from this page: Sonoff Mini R2 Switch Module (MINIR2) Configuration for Tasmota

AND IT WORKS. Need to check how to add to HA tho.

FIXED MY own problem.
Apperantly on firmware 3.6 you dont have to provide the hardware id
On 3.7 and higher, you gotta specify the hardware id the the json requests. (Hardware ID can be seen when connecting to the DIY accesspoint after the _ (last 8 or ten characters),

add these to the json requests and it works fine

@kepe94 might to solution for you to if you running 3.7 or higher

2 Likes

I got the Mini (i think this is the first version, but I’m not sure) updated to 3.7.6 yesterday, and it joins my network (I can ping it), but attempts to access the REST API are no longer working (even when they were working, they were failing, I suspect this was because as @Sadisticpandabear mentioned I also was not specifying the deviceid).

I can enter compatibility mode and connect to the Mini’s AP. I can see that I’m connected (I can ping 10.10.7.1), but when I try to open it in a browser it fails/keeps loading.
I think I’m probably giving up on this thing, I’ve ordered a Shelly.

UPDATE: Of course right after this I had to do one more test. Given that the device was connected to my network, I tried Postman again and removed the deviceid entirely, and it started responding. Also, the deviceid that was provided by /zeroconf/info was not the same as the part after the _ in the device’s name - maybe it’s different on this device.

I modified the script linked above, and just removed "deviceid":"", from the body variable in the sonoff_http_request function, and also from the ota_flash function.
That made the script start working and got Tasmota flashed, and from there I was able to get ESPHome installed.

HI,
so you managed to install tasmota.
I ask for help.
I also have the problem with firmware 3.7.6. to flash

I don’t understand where to find the Hardware ID
I recovered an old image, it is perhaps the “deviceid” item at point 12

image

then i write it instead of deviceid in
{“deviceid”:"",“data”:{}}

thanks

Hey man, did you figure out how to pair your R3 Lite?
I’m having the exact same problem and can’t find any info.

Is there an option to modify the config for the S1&S2 pins on the relay to work just as the sensor (toggled status in HA). Now it also controls the relay state directly. Thanks!

@basicauth

Even though it’s an old topic, I’m posting it for anyone new or those who are still facing issues. You should run a mock server since the official unlock API is not responding.