Sonoff is a Wifi Smart Switch produced by ITEAD that you can get from China for cheap. This switch can be used for Smart Home / Enterprise solutions. You can connect it to 90V-250V / 10A AC line and can control it over Wifi
If we cut it open; we will find its a 10A Relay connected to ESP8266 (1Mb model) based switch with required Power regulatory circuit, and good thing about this switch is that they have exposed the TTL and GPIO pins making it very DIY/Maker/Hacker friendly. We can solder Male Headers to these pins; either by our self or seek some help from some road side Radio / Repair shop
We need to connect that Square pin and three pins above for powering ESP8266; its Microcontroller Unit (MCU) and for Serial TTL.
The Square pin; the closest to the Reset is Power; the next two are RX and TX and the fourth one is Ground. Once soldered; we can connect the jumper wires to these male headers
Above picture from: http://randomnerdtutorials.com/reprogram-sonoff-smart-switch-with-web-server/
Next we need USB – TTL Adapter; get the one that has 3.3V / 5V setting; we need to power it with 3.3V. I am using a cheap CH340 based USB-TTL Adapter
Keep the reset button pressed when power it up; it will take the on board ESP8266 into programming mode; and USB port will get connected and you will be able to connect to it either from ESP8266 Flasher and flash NodeMCU; like we did in the Blink post or use Arduino Core for ESP8266 and make a custom firmware similar to Arduino core for ESP8266 WiFi chip post. The onboard LED is connected to ESP8266’ pin 13 and the relay is connected to pin 12. You can open these both pins as OUTPUT and writing HIGH to pin 12 where relay is connected; the switch will turn on allowing the AC current to flow and writing LOW will disconnect.
Using this information; I wrote one such firmware that's being demoed in this video; PI3 along with power adapter is connected as the appliance; and we can turn it on or off “remotely” using the web interface; similar to Arduino core for ESP8266 WiFi chip post where we were turning the led on or off