Flashing a Sonoff Mini Relay with ESPHome and Integrating it with Home Assistant
In this step-by-step guide, we’ll show you how to flash your Sonoff Mini Relay using ESPHome and integrate it with Home Assistant.
Flashing a Sonoff Mini Relay with ESPHome and Integrating it with Home Assistant
In this step-by-step guide, we’ll show you how to flash your Sonoff Mini Relay using ESPHome and integrate it with Home Assistant. You’ll learn how to enable DIY mode, connect the relay to your Wi-Fi network, compile and flash custom firmware, and set up the device in Home Assistant. Follow along, and by the end, you’ll have a fully functional Sonoff Mini controlled by Home Assistant.

1. Switch the Sonoff Mini into DIY Mode
To flash custom firmware onto the Sonoff Mini, you first need to switch it into DIY mode. Follow these steps to enable DIY mode and connect it to your home Wi-Fi:
- Power on the Sonoff Mini Relay.
- Press the connected light switch 5 times repeatedly with 1-second intervals.
- The Sonoff Mini’s LED will start to quick flash, indicating it’s now in Compatible Pairing Mode (AP mode).
- On your computer or mobile device, go to the Wi-Fi settings. Look for an access point named ITEAD-XXXXXXXXXX (the
Xs represent the device’s unique ID). - Connect to this access point using the default password: 12345678.
- Once connected, open a browser and navigate to http://10.10.7.1/. This is the device’s configuration page.
- Enter your Wi-Fi SSID and password to connect the Sonoff Mini to your home network.
- Once the device connects successfully, it will be in DIY mode and ready for flashing.
2. Confirm the Connection and Unlock OTA Mode
Now that the Sonoff Mini is in DIY mode and connected to your Wi-Fi, you need to confirm the connection and unlock OTA (Over-the-Air) updates.
Check the Device’s Connection:
To verify the connection and check the relay’s status, you can use the RESTer extension or similars to send an API request.
- Open the RESTer extension in your browser.
- Set up a POST request to the relay’s IP address. Pay attention on port 8081. URL: http://<relay_ip>:8081/zeroconf/info
- Send the request. If the response includes your Wi-Fi SSID and no errors, your Sonoff Mini is connected.

Unlock OTA Mode:
To flash ESPHome firmware over-the-air, OTA mode must be unlocked. Use the following API command to enable OTA:
- Set up a new POST request in RESTer. URL: http://<relay_ip>:8081/zeroconf/ota_unlock
- Send the request. Once you receive a success message, the device is ready for OTA flashing.

3. Compile ESPHome Configuration into a .bin File
With OTA mode unlocked, the next step is to compile your ESPHome configuration into a .bin firmware file.
- Make sure ESPHome is installed. If not, install it using:
pip install esphome - Create a configuration file for your Sonoff Mini. Use the example below
esphome:
name: sonoff_mini
platform: ESP8266
board: esp8285
wifi:
ssid: "your_wifi_ssid"
password: "your_wifi_password"
api:
password: "your_api_password"
logger:
ota:
password: "your_ota_password"
switch:
- platform: gpio
pin: GPIO12 # Relay pin
name: "Sonoff Mini Relay"
binary_sensor:
- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
name: "Sonoff Mini Button"
on_press:
- switch.toggle: relay
status_led:
pin:
number: GPIO13
inverted: true
- Save the file as
sonoff_mini.yaml. - Compile the configuration into a
.binfirmware file:esphome sonoff_mini.yaml compile - After compiling, the firmware file (
sonoff_mini.bin) will be in the.esphome/buid/folder.
4. Set Up a Local HTTP Server
To flash the firmware over-the-air, you’ll need a local HTTP server to serve the sonoff_mini.bin file.
- Open a terminal and navigate to the directory containing your sonoff_mini.bin file:
cd [path/to]/sonoff_mini.bin - Start a simple HTTP server:
python3 -m http.server 8000 - Verify the server is running by visiting http://<your_local_ip>:8000/sonoff_mini.bin in your browser. If you can see the file, your server is set up.
5. Verify Firmware Integrity (Checksum)
Before flashing the firmware, generate a checksum to ensure its integrity.
- Run the following command to get the SHA256 checksum of the bin file:
shasum -a 256 sonoff_mini.bin - Copy the SHA256 checksum value. You’ll need it in the next step to verify the firmware during flashing.
6. Flash ESPHome Firmware
With your local HTTP server running and OTA mode unlocked, you can now flash the ESPHome firmware onto the Sonoff Mini.
- In RESTer, set up a POST request for OTA flashing: URL http://<relay_ip>:8081/zeroconf/ota_flash
Body:
{
"deviceid": "",
"data":
{
"downloadUrl": "http://<your_local_ip>:8000/sonoff_mini.bin",
"sha256sum": "<your_firmware_sha256_checksum>"
}
}
- Send the request. The device will download and verify the firmware, and the response will show the flashing progress.
- Once flashing is complete, the Sonoff Mini will reboot with the new ESPHome firmware.

7. Add Sonoff Mini to Home Assistant
Now that the Sonoff Mini is running ESPHome, add it to Home Assistant:
- Open Home Assistant and go to Configuration > Devices & Services.
- Click on ESPHome and enter the Sonoff Mini’s IP address.
- Congratulation! The device will appear in Home Assistant, ready for control and automation.
Troubleshooting
- Device doesn’t enter DIY mode: Ensure you are following the 5-time press sequence exactly. Try resetting the device and repeating the process. Or connect your device to eWeLink and upgrade firmware to the last
- Sonoff Mini not appearing on Wi-Fi: Check that your mobile device or PC is connected to the 2.4 GHz band and that the device is within range.
- OTA Flashing fails: Ensure the checksum matches and the local HTTP server is accessible from the Sonoff Mini’s network.
Conclusion
Congratulations! You’ve successfully flashed your Sonoff Mini Relay with ESPHome and integrated it into Home Assistant. Now you can control the relay remotely, automate it with your smart home, and even add more ESPHome devices in the future. Explore additional features of ESPHome to further customize your setup and enjoy the flexibility of your DIY smart home system!
메타데이터
- post_id
- 5be96242f2d6
- slug
- flashing-a-sonoff-mini-relay-with-esphome-and-integrating-it-with-home-assistant-5be96242f2d6
- url
- https://medium.com/wireless-flashing-a-sonoff-relay-with-esphome-and/flashing-a-sonoff-mini-relay-with-esphome-and-integrating-it-with-home-assistant-5be96242f2d6
- canonical_url
- https://medium.com/wireless-flashing-a-sonoff-relay-with-esphome-and/flashing-a-sonoff-mini-relay-with-esphome-and-integrating-it-with-home-assistant-5be96242f2d6
- author_url
- https://medium.com/@q12349
- status
- ok
- fetched_at
- 2026-07-22 15:27:04