Saturday, 11 February 2017

How to flash ESPEasy onto the Sonoff Touch for MQTT control

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.
You can completely remove the low voltage board and connect as shown below.Sonoff Touch US 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.




  1. Download the latest release candidate from here http://www.letscontrolit.com/wiki/index.php/ESPEasy#Release_candidates 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 192.168.4.1
  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
        gpio,12,0
    if [button#state]=1
        gpio,12,1
    endon
  10. Under devices, add a switch input configured as shown to enable the touch button

    image
  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.

    image
  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:
    /devicename/button/state
    /devicename/relay/state
  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.
BUTTON is on GPIO0
RELAY is on GPIO12
LED is on GPIO13