Saturday, 11 February 2017

How to flash ESPEasy onto the Sonoff Touch for MQTT control

You can completely remove the low voltage board and connect as shown below. GPIO0 needs to be pulled to ground on power up (it can be left grounded during flashing) to enter programming mode. Power the device from your FTDI programmer set to 3.3V.

The Sonoff Touch is a nice glass touch panel based on an ESP8285 with 1MB of integrated flash that can be quite easily flashed with a self compiled version of ESP Easy.  You need to compile yourself as the builds available online are all made for the ESP8266 and will not work with the Sonoff Touch.
Sonoff Touch US

  1. Download the latest release candidate from here and the copy the compiled version I created here into the same folder.
  2. Run flash.cmd and choose your com port, then 1024 to match the flash size of the Sonoff Touch and then 148 for the version number. Flashing should take about 30s.
  3. Once completed, disconnect from your programmer and reconnect. The device will boot into AP mode with a SSID of ESP_0.
  4. Connect to that network using configesp as the password then navigate to
  5. Connect to your SSID and enter your network password. The Sonoff should now connect to your Wi-Fi and tell you what IP it got assigned.
  6. Connect your PC back to your network and navigate to the IP your Sonoff got assigned.
  7. Under ‘Config’, give your device a name (I called mine sonofft1) and change the protocol to OpenHAB MQTT and set your broker IP, username and password.
  8. Under Tools > Advanced, tick ‘MQTT Retain Msg:’ and ‘Rules:’ right at the bottom and click Submit.
  9. At the top, you’ll now have a new tab called Rules. Paste the following into the rules section and click submit.

    on button#state do
      if [button#state]=0
    if [button#state]=1
  10. Under devices, add a switch input configured as shown to enable the touch button

  11. Add another switch input for the relay as shown. The IDX/Var you can make up and I don’t think they matter if you’re using MQTT. They do if you’re connecting to Domoticz.

  12. You should now be able to push the button and your light will come on. Using the rules I’ve posted, the light should go off when the Sonoff is rebooted and stay off.
  13. You can get a report on the button and relay states by subscribing to:
  14. You can control the relay by publishing to /devicename/gpio/12 with a payload of 1 for on and 0 for off

    N.B The integrated LED does not need control and simply tracks the button/relay state.
For your reference, here are the GPIO assignments.
RELAY is on GPIO12
LED is on GPIO13


  1. Thanks for your post and the precompiled binary! It works!

  2. Hey there XBMCNut,

    Great write up as always!

    Quick question for you. From watching your video, is it safe to assume that you have the US version of the switch since it is rectangular?

    If it is, would you be able to possibly post a a comparison picture of the sonoff touch to a regular light switch?

    After looking at all the picture of the US sonoff touch, I just don't feel like it will fit in a regular light switch box. It looks as if i I would have to install it vertically for it to fit.


    1. I had always planned to do this video first so that should address your question?

    2. I can confirm it does fit into US gang boxes. I also had the same fit problem due to the screws sticking out. My workaround was to drill holes in the middle piece as you suggest but use those holes to access the screw heads to attach the first plate onto the gang box.