[OBSOLETE] Sonoff, Sonoff TH, S20, Dual, 4CH, POW, & Touch Device Handler & SmartApp ($5 & $10 Smart Switches)

2017_10_04 Update: If the flashing method in this first post does not work for your device, try the method mentioned in this post:

2017_05_10 Update: Sonoff Dual - Firmware and device handler and child device handler. Flashing info here. Sonoff 4CH - Firmware and device handler and child device handler.

2017_01_21 Update: Release of firmware and SmartApp updates for the Sonoff Touch and Sonoff S20. Picture for flashing Sonoff Touch in this post.

2016_10_14 Update: I have been playing with the Sonoff TH (16 Amp Version) and am finished with a SmartThings capable firmware for it. This device has a 10 & 16 Amp version and support for a temperature sensor attachment. The device handler supports both temperature and humidity. Here is the firmware & here is the device handler. You also need to install the Sonoff (Connect) SmartApp posted below.

2016_06_02 Update: I have created a custom firmware and service manager for these switches. I was able to really simplify the setup and significantly reduce the code footprint for the firmware. I wanted to update this main post but leave the old information for those that may still be using it. Still trying to figure out how to do that in a non-confusing way. Right now if you search Google for “Sonoff SmartThings” you will find my blog post with the old instructions. If you want to update from the old EasyESP firmware to this new one. Just go to http://ipaddressofswitch/update and upload the .bin image posted below. You don’t need to connect via FTDI if you already have the EasyESP image flashed. Also, any subsequent update from me will be updated the same way. After switching over to the new firmware you will have to reconnect to Wifi, but this will be a one time process.

This is a wifi relay that can be found for as low as $5. I have had a few of these up and running for a little while now and they are working great. They can even support instant status updates when the switch is toggled by pressing the button, and are really quite simple to setup.

Warning: Do all of the flashing before connecting the switch to mains electricity. Be safe when working with electrical devices. I take no responsibility if you do something that damages yourself or your property. :wink:

Flashing Firmware

This step is extremely easy, so don’t let it intimidate you. I have built custom image (with the inclusion of a couple of esp8266 Arduino libraries) for the switch to interact with SmartThings. First, download the ESPEasy firmware flashing tool. You will use esptool.exe from this zip to flash the firmware. Next download the firmware image that I have built here, and place it in the same directory that you extracted the esptool.exe binary. Now, with an FTDI adapter (SET AT 3.3V) connected to the switch (square pin = VCC, then TX, RX, GROUND - that order), plug the FTDI adapter into the USB port of your computer while holding down the button on the switch. This puts it into programming mode. Run the following command (make sure to replace %comport% with the comport number of your FTDI adapter i.e. COM6):

esptool.exe -vv -cd nodemcu -cb 115200 -cp COM%comport% -ca 0x00000 -cf Sonoff.ino.generic.bin

Connect to Your Home Wifi

Now, plug the switch into power and wait for a moment. It should create an access point named Sonoff.[macAddressofSwitch]. Connect to that access point with the password: configme and it should redirect you to the page where you can connect it to your access point. If it doesn’t redirect you the IP address is 192.168.4.1. Put in your network access point information and hit connect.

The switch should then connect to your Wifi access point.

SmartThings Setup

Add the device handler to your account:

Also add the Service Manager SmartApp:

Install the SmartApp from your mobile device and let it discover the switches connected to your network. It uses SSDP, so unless you have something funky configured on your network they should show up. With the service manager there is no need to set static IP addresses or DHCP reservations for the switches. If the IP addresses change, the service manager should update them.


That’s it. Try it out and let us know how it goes.

53 Likes

Interesting device for that price point. Does it work with local network or is this cloud base switch?

1 Like

The switch is locally controlled if programmed with the firmware I provided. Of course, if connected to SmartThings you are still dependent on the SmartThings cloud, but at least it isn’t cloud-to-cloud.

3 Likes

Sounded like it’s a good little device for rebooting the ST Hub. Thanks for the device handler!

Very interesting device! And just $4.85? https://www.itead.cc/sonoff-wifi-wireless-switch.html

So you basically spliced it into an existing extension cord?

Yeah, it’s not necessary if you want to splice it directly into the lamp or appliance, but I thought it would be more flexible this way. I also have a version with ground where I just routed the ground wire through the switch enclosure.

1 Like

Just ordered 5, these look like fun! Thanks Eric!

3 Likes

Awesome find and nice integration. Just curious if these are UL listed? Thx

They also have some other variants, one with DHT11 temp/humidity sensor (my experience with DHT11 is that it is not accurate enough for anything), one with 433MHz remote, plus a couple others.

It doesn’t appear to be UL listed or FCC. Some ESP8266 modules are FCC approved.

Would be awesome if they get UL listing and make one with enclosure and terminals to put inside wall switch

Thanks for sharing this find!

Would be interested in seeing how this compares in size to something like the aeon labs micro switches. I was going to have to buy about 20 of them, but if I can get away with throwing these $5 switches in place, it will get my setup moving much faster.

It is a little thicker and longer than the Aeon. I have several Aeon’s, but they are all installed or else I would do a side by side. With the length of the Sonoff, it might be tricky to fit into a 1 gang box. There are several unused solder pads toward the bottom of the PCB that are used for the RF transmitter on a different model of the switch. If any of them are GPIO points then an external switch could easily be attached and the rules logic adjusted accordingly.

@michaelahess, overall this is a very cool device and a lot of fun to play with. Let me know how it goes!

1 Like

Looks like they ship from China. How long did it take for the product to arrive? Also, would you be willing to share the source code for the ESP?

Any way to do this firmware update with a Mac? The FTDI adapter only supports Windows. I have numerous equipment but all Mac.

They took a couple of weeks to arrive. Source is available on github.

I am not the author of the firmware, but have merely compiled a version of it that supports the rule engine necessary for the switch logic.

@joelw135 I have flashed ESP from Linux (which I am guessing would be similar) but the process is very complicated. The FTDI adapter I referenced in my original post does support Linux and shows up as a /dev/ttyUSB serial device. If you are serious about it you can find instructions here. I had to install the ESP compiler, then the development environment, then flash the image. If possible, it would be a lot easier to use a Windows VM and just pass through the FTDI adapter to it.

2 Likes

Thanks, but i think it will be way to time consuming, so I will spend the extra on the available ones that work out of the box.

And be careful with those adapters, most of them are cheap knockoffs that can brick themselves if you use the latest official drivers from FTDI. Minefield ahead…

I personally use a WinXP VM that has the older driver for mine, I know mine is fake and just don’t want to risk it.

But… FIVE BUCKS! :slight_smile:

1 Like

hmmm, this option is pretty sweet and it would also save a lot from my budget for switches. Just a quick question, anyone know how safe these are? (don’t want it to catch on fire especially if I am installing multiple units).

I haven’t had any problems with them, but make sure you don’t try to go over the 10A rating on them. If used as intended, I think that they will be fine (knock on wood). If anyone has any problems, be sure to report back here.

Some people who have done teardowns have expressed concerns about the internal design, particularly around the power circuit. There’s probably a reason this device doesn’t have any safety certifications. Just sayin’ …

I heard from an online friend who did a teardown. He said there are two issues besides the one already mentioned that he found. First, the specs are wrong: the Triac is described as 2A but the one in the device he tore down has a third party part number that is actually a 1A. Second, if you splice it into an existing cord you should be aware that there is no passthrough for the ground. Just hot and neutral. So using the Sonoff turns a grounded cord into an ungrounded one that just looks like it’s grounded.

Again, I haven’t verified any of that myself, but I don’t see any reason to disbelieve him. It is possible that they have made changes and there are different configurations out there.

@ZebraBlinds

1 Like