Skip to main content

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

Comments

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

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

    Thanks!

    ReplyDelete
    Replies
    1. I had always planned to do this video first https://www.youtube.com/watch?v=VY6beZqGzRo so that should address your question?

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

      Delete

Post a Comment

Popular posts from this blog

Using ESPEasy with Home Assistant via MQTT

Preface: I've just started playing around with Home Assistant on a Raspberry Pi and exploring the world of MQTT to control devices on the network. Learning curve is a bit steep but worth the effort as MQTT is very fast. The hardware and software tools I'm using are as follows: 2 x Sonoff relay units 2 x NodeMCU Boards ESPEasy firmware (must be version 121 or above as that contains the MQTT 'retain' flag option. Home Assistant software on Raspberry Pi2 MQTT Test Software: PC: MQTT.fx Android: MQTT Dashboard

My Notepad++ tricks when editing YAML files in Home Assistant

To comment out a whole section in one go: Highlight the text you want to comment out and use CTRL + Q. If you do this at the start of a line, it will only comment that line. CTRL + Q is toggle mode (comment on/off). CTRL + K will allow you to add multiple comments one after the other.

Installing ha-bridge on your Raspberry Pi

EDIT: Updated 14th June 2017 to reflect version 4.5.5. Default port is now 80 to keep Google Home happy and service now supports MQTT! Advice on backups also added 7th Feb. Version 4x also supports adding a Home Assistant instance which is great! Want to control your Vera, Harmony hub or Home Assistant entities with your Amazon echo or Google Home? ha-bridge is the best way to achieve that and installation is actually quite easy and takes less than 5 minutes. Here are the steps.