HomeHome AutomationIs it worth hacking Sonoff basic?

Is it worth hacking Sonoff basic?

To hack Sonoff Basic or not to hack!?

Thanks to Banggood I own two Sonoff basic devices. While the original and intended use is waiting for the local Hackspace to reopen, I thought I would take a look at hacking options. The Sonoff community is strong, and there seems to be plenty of support for Sonoff devices. Is it worth hacking Sonoff? The short answer is Yes, the long answer is below.

Hacking Sonoff basic

Latest Sonoff R3 series

The reason for straight-up YES is the ability to reflash the original software back on the ESP8266. This means should anything happen, you can always go back to the intended use. Here is the breakdown of Pros and Cons:

Enable HTTP, MQTT, and other protocolsRequire programming knowledge
Utilise additional exposed pinsAndroid/iOS app support is not there
Reduce “talk home”Poor coding practices can increase security risks
Can function better offlineWarranty
Better cooperation with other devicesOff the shelf support with Home Assistants

For me, the pros outweigh the cons. And for a lot of you as well as the hacking community is strong and there are plenty of examples of Sonoff devices being used in an awesome way.

Hacking Sonoff – hardware

BE AWARE: Sonoff device backup will only work with the specific unit. Currently, there is no way of sharing the backup file between the devices. Make sure that you create the backup file for each Sonoff device you own.

Before you open a device like this, remember to only program it using power from the FTDI programmer. DO NOT USE MAINS to power up the chip for programming.

Guys at Sonoff has been nice enough to expose all the pins needed to flash the software. To make the job easier, I have added 5 header pins to the board so I could use jumper wires when hacking Sonoff devices.

The pinout of the Sonoff basic is as follows:

Pay attention to the board orientation to connect the correct wires between your device and FTDI converter.

Sonoff BasicFTDI

Once you have the hardware ready, we have to set up the hacking environment. I will cover the setup of Windows 10 as it’s the most troublesome.

Buy FT232RL Serial adapter

Buy it using these links to support NotEnoughTech.

Hacking Sonoff – software

Thanks to Tasmotizer, you can flash and configure your Sonoff devices in under a minute. Follow this guide about how to back up, erase and flash your ESP device with Tasmotizer.

I kept the old way of flashing ESPs as a reference, but I would strongly suggest you give the Tasmotizer a go since it doesn’t require the painstaking setup and it works like a charm.

Flashing Tasmota - the old way

To be able to hack the relay, you will need several downloads:

  1. Python 2.7
  2. pip installer
  3. pyserial
  4. esptool

Start with the installation of the Python 2.7 (New installer has option to include PATH – use it). Once it’s installed, open Windows 10 system settings  (Win key then search for Advanced System Settings) then navigate to Environmental Variables, find Path and edit. Add a new line:


This will save you a lot of trouble.

Download the pip installer and place it in a folder (not desktop). Hold right Shift and right-click within that folder to bring up the cmd/PowerShell window in the current directory. Then run:

python.exe get-pip.py

Now that we have the latest pip, it’s time for the pyserial. Download the tar.gz file and unpack it to a folder. Open the folder and a new cmd/PowerShell window inside it then run:

python setup.py install

Now you are ready to play with esptool software. Download the tool and unpack it to a folder. Bring up the cmd/PowerShell in that location.

Hacking Sonoff – backup

Connect the Sonoff device and power it up while holding the built-in button for 2-3 sec. You will be able to make changes to the bootloader now. Your first action should be a backup. Check the COM port connected via device manager.


python esptool.py --port COM5 read_flash 0x00000 0x100000 image1M.bin

Once the backup is done, you will notice a new file present in the folder. It’s the image1M.bin (or whatever you named it). This is your recovery file. Keep it safe. If you delete the file, you won’t be able to restore the original firmware.


python esptool.py --port COM5 erase_flash

If you want to delete the firmware completely and prepare it for the custom software.


python esptool.py --port COM5 write_flash -fs 1MB -fm dout 0x0 image1M.bin

You can restore or flash a custom software. Just place the file in the same folder as the esptool.py file.

3rd party firmware – Tasmota and AFE Firmware

If you don’t feel like coding yourself, you can use already developed firmware by the community. My favourite options are:

Custom Software – Arduino IDE

Now that we have the image backed up, we can use the Arduino to push the custom code to the ESP8266. Make sure to add the boards to the manager by opening Arduino IDE preferences and setting the path for the manager:


Select the ESP8266 and the following Arduino IDE options:

Board: "Generic ESP8266 Module"
Flash Mode: "DOUT"
Flash Size: "1M (no SPIFFS)
IwIP Variant: "v1.4 Higher Bandwith"
Erase Flash: "Only Sketch"

Now you can put your board again into a flash mode (hold the button for 2-3sec when powering up) and flash a custom code. I will be writing a better code especially made for the Sonoff basic, but for now, feel free to interact with a web-based interface. For now, I used the code I made for DIY Smart Socket as it suits my needs for testing. You can download the modified version at the bottom of the article.

AFE Firmware

An excellent firmware, developed by Adrian and available on www.smartnydom.pl (most of the content is available also in English). AFE Firmware is best for ESP8285 and ESP8266 devices which are not made by Sonoff’s ITEAD.


  • HTTP support
  • MQTT 
  • Custom Pin Mappings
  • OTA updates

I talked about this in detail in my ESP8285 4-way relay tutorial. If you use ESP8266, don’t worry – the principle is the same, just download the correct version for your chip.


This firmware aims to use the exposed dev pins on Sonoff devices for the purpose of adding the sensors and modules. Tasmota firmware works best with Sonoff devices as the options are tailored for each product released by ITEAD.


  • MQTT support
  • HTTP support (although less fun to use than AFE Firmware)
  • Easy config – just pick the model from the list
  • Included libraries for sensors etc
  • OTA updates

There is already a tutorial about the Tasmota and sonoff devices, and you can take a look at the implementation and flash it to your device.

Shop with Sonoff

Take a look at the ZigBee and WiFi range of the devices compatible with eWeLink:


It’s very rewarding to hack your own Sonoff device. You learned new skills, you can integrate it with your automation systems. The biggest advantage for me is the ability to link it to any device you wish almost directly. The consumer-based systems have a very limited scope and aim to work with the most popular solutions. On top of that, 5 years down the line there is no warranty that home automation systems owned by you will still be in use and supported. Having total control over a device you own is the best!

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.


Nothing says "Thank you" better than keeping my coffee jar topped up!


Support me on Patreon and get an early access to tutorial files and videos.


Bitcoin (BTC)

Use this QR to keep me caffeinated with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

Smart Ideas with

Automate your space in with these ecosystems and integrate it with other automation services


Learn NodeRED

NodeRED for beginners: 1. Why do you need a NodeRED server?

To server or not to server? That's a very silly question!

Best Automation Projects

Tuya SDK for beginners: Intro to Tuya Cloud API

Working with Tuya Cloud API. A guide to Cloud automation for beginners, get started with REST!

NEST your old thermostat under $5

Nest-ing up your older thermostat under $5

Nora – Google Assistant in NodeRED

Integrate Google Assistant with NodeRED thanks to Nora - NodeRED home automation

Sonoff Zigbee Bridge – review

Sonoff line up will soon include Sonoff Zigbee Bridge and more Zigbee sensors - here is the first look

DIY Smart Washing Machine – for about 15 bucks!

Learn how to add washing machine notifications to your Google Home on the cheap

Smart Home

I wish I had known about the SMLIGHT ZigBee/Thread Coordinators sooner!

SMLIGHT coordinators are the perfect choice for anyone just diving into ZigBee. SLZB-06 series is easy to use and comes with future-proofing Thread support.

Sonoff ZigBee Bridge U isn’t what you think!

I expected Sonoff ZB Bridge U to be a next gen ZigBee bridge with Matter support. Turns out, there is much more to talk about!

Aqara “Everything” M3 Hub

When I started my home automation adventure, the current problem was the number of ecosystems needed to outfit your smart home. Aqara M3 Hub has a long list of protocols to match that!

Sonoff ZB Micro did it! (and bonus ZigBee device)

A long time ago, I took an angle grinder to the humble Sonoff Micro, will I do this again? Meet Sonoff ZB Micro and Sonoff ZB Contact (SNZB-04P) - the latest devices from the ZigBee ecosystem.

This keyless entry is PRO: SwitchBot Lock Pro

SwitchBot Lock Pro offers comprehensive upgrades over the original, combining enhanced design, stronger performance, and a faster mechanism for keyless entry