Step One, Prepare the Sonoff Mini R2:
Disconnect power.
Connect the Sonoff Mini R2 to power.
(Neutral, White or Return to “N In” and Hot, Black or Line to “L In” terminals.)
Reconnect power.
Observe three blue flashes, pause, three blue flashes, etc.
(If you do not see this flash sequence, press and hold the button for 5 seconds.)
Step Two, Pair in Ewelink App:
Open Ewelink App.
Press blue “+” at the bottom.
Select “Quick Pairing”
Select “Add one device”
Enter your home WiFi name and password at the bottom and choose “Next”
Wait for the device to be found (up to 3 minutes)
When you see “Device added successfully” give it a throwaway but unique name.
Select the device in the App. Toggle it.
Go to “Device Settings”, “Basic Info”, “Current Version. Confirm firmware 3.7.6 or upgrade it.
It may take awhile for the App to offer you a firmware upgrade.
Scroll down to the bottom of “Device Settings” and make a note of the Mac address. Write it down.
Step Three, find the IP Address:
Use your router or network scanner software to find the IP address of the MAC address you just wrote down.
(I can’t really walk you through this part, every router is different.)
Write down the device IP Address.
Step Four, reset the Sonoff Mini R2:
Hold down the button for 5 seconds until you see 3 blue flashes, pause, three blue flashes.
Hold down the button for 5 seconds again, until you see steady blinking.
Step Five, Delete the device from the Ewelink App:
Open the Ewelink App.
Select the device. It will be offline.
Select “…” in the top right corner.
Scroll to the very bottom and select “Delete device” then “Confirm”.
Step six, Sonoff Mini R2 hotspot:
Connect to “ITEAD-numberandletters” with the password “12345678”
In your browser, visit “10.10.7.1”
Choose “WIFI SETTING” and enter your home WiFi name and Password and select save.
Step Six, Script:
Follow the instructions at GitHub - njh/sonoff-ota-flash-cli: Bash script to perform an OTA (Over the Air) firmware update for Sonoff 'DIY Mode' device on the command line
The script that worked best for me was:
./sonoff-ota-flash.sh -i 192.168.x.xxx
(replace the IP address with the IP address of the device you found in step three)
Be patient for the script to find, flash and let the device reboot. Give it several minutes.
Step Seven, Tasmota hotspot:
Connect to “tasmota_lettersandnumbers” no password required.
In your browser, visit “192.168.4.1”
Under “Wifi parameters” enter your home WiFi name and Password and select save.
Give it time to reboot and connect to your home WiFi.
Step Eight, Tasmota:
Enter the IP address of the device you found in Step Three.
If you cannot connect, repeat Step Three to find the new IP Address of the same MAC address you wrote down.
In your browser, visit that IP address. You should see Tasmota 9.5.0.
You could stop here if you like. Tasmota is pretty cool.
Leave this browser window open.
Step Nine, ESPHome:
In Home Assistant, go to your ESPHome Add-On Web UI.
Select “+ NEW DEVICE”, “CONTINUE” and select a name for your ESPHome flashed Sonoff Mini R2.
(You can change this name, but it’s a pain, so choose wisely now.)
Choose “ESP8266” and “SKIP”.
Choose “EDIT” on the new device.
substitutions:
device_name: "the-name-you-selected-in-step-nine"
esphome:
name: ${device_name}
friendly_name: AnyName YouLike
esp8266:
board: esp8285
# Enable logging
logger:
# Enable Home Assistant API
api:
reboot_timeout: 15min
encryption:
key: "yourencryptionkey"
ota:
password: "yourpassword"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "any fallback hotspot name"
password: "apassword"
captive_portal:
Choose “SAVE” then “X”.
Select “…” then “VALIDATE”
Select “…” then “INSTALL”, “Manual Download”, “Modern Format”.
Wait for it to compile, and download. This can take awhile.
When you see a line of green text you can select “CLOSE”.
Step Ten, Upload ESPHome Firmware in Tasmota:
Go back to the browser window you left open.
Go to “Console” and type “SetOption78 1” then press enter.
Go to “Main Menu”
Go to “Firmware Upgrade”
Select “Choose File” and navigate to wherever you saved the firmware.
When you see “Upload Successful” go to Home Assistant , ESPHome.
Step Eleven, ESPHome:
In Home Assistant, go to your ESPHome Add-On Web UI.
Wait for the device to reboot and show as ONLINE.
Choose “EDIT” on the new device.
Add the rest of the yaml code below “captive_portal:” to fully enable the device:
web_server:
port: 80
sensor:
- platform: wifi_signal
name: ${device_name} Wifi Signal Strength
update_interval: 60s
- platform: uptime
name: ${device_name} Uptime
#######################################
# Device specific Config Begins Below #
#######################################
binary_sensor:
- platform: gpio
pin: GPIO00
id: reset
internal: true
filters:
- invert:
- delayed_off: 10ms
on_press:
- switch.toggle:
id: relay_1
- platform: gpio
name: ${device_name}_status
pin: GPIO04
id: switch_1
on_press:
then:
- switch.toggle:
id: relay_1
on_release:
then:
- switch.toggle:
id: relay_1
switch:
- platform: gpio
name: ${device_name}_switch
icon: "mdi:lightbulb_outline"
pin: GPIO12
id: relay_1
restore_mode: restore_default_off
status_led:
pin:
number: GPIO13
inverted: true
output:
- platform: esp8266_pwm
id: blue_led
pin: GPIO13
inverted: True
light:
# the 4 lines below define the Blue LED light on Sonoff Mini, to expose in HomeAssistant remove line "internal: true"
- platform: monochromatic
name: ${device_name}_blueled
output: blue_led
internal: true # hides the Blue LED from HomeAssistant
Save.
Validate.
Install → Wirelessly.
Wait for it to compile, upload and reboot. This can take awhile.
When you see a bunch of purple text you can select “STOP”.
Step Twelve, Sonoff Mini R2:
Disconnect power.
Disconnect the device from wires.
Ideally mark it “ESPHome” or something with a permanent marker.
Install it for real.