In this post, you’re going to learn how to control an outlet from anywhere in the world using the Sonoff device. The Sonoff is a device that you put in series with your power lines allowing you to turn any device on and off.
First, watch the step by step video tutorial below
Here’s the basic Sonoff. You can get a Sonoff for approximatly $5 – visit Maker Advisor to find the best price.
It’s very simple, it has an input in one side and an output on the other side.
Then, you can simply send commands via wifi to turn on and off. That’s pretty much how it works.
Opening the Sonoff
Let’s take a look inside the sonoff device. These are the main sections:
- There are the two powerlines and they are isolated from the rest of the circuit
- The active line goes to the relay (that’s on the other side of the PCB)
- The ESP8266, that is the processor that provides wifi and receives the control commands
- The Sonoff is meant to be hacked and you can see clearly that those 4 connections were left out, so that you can solder some pins and upload a custom firmware
In this project, we’re going to use the standard firmware that came with the Sonoff. In future post I’m going to show how to flash a custom firmware into the Sonoff device.
Sonoff Example
Let’s take a look at how this would fit in a normal circuit. Basically you cut the wire that goes to the device, and you put the Sonoff in the middle, so that you can control any device that is connected on the other end.
Normally, what you have is a power source that has an active and neutral line that goes to a load, your load can be lamp for example. In the middle, you usually have a switch.
With the sonoff, you cut that connection…
And you place the sonoff in the middle. The sonoff acts as a switch that is controlled via Wifi.Â
Note: if you have a earth line, it has to go outside the sonoff.
Safety warning
Before proceeding with this project, I want to let you know that you’re dealing with mains voltage. Please read the safety warning below carefully.Â
Sonoff usage
Let’s hook up the Sonoff. On the left side, you connect the active and neutral accordingly to the pinout. Active and neutral come out on the right.
Installing the App
Now you have everything in place to install the app to control the light with your smartphone, follow these next instructions:
- Search for the app eWeLink app and install it
- Open the app and create an account
- Power up the Sonoff device and connect the appliance that you want to control (in my case, it’s a desktop lamp)
- Press and hold the Sonoff button for 5 seconds, so the LED green starts blinking
- Go to the app and press the next button
- Enter your network credentials and choose a name for your device
- Add it to your dashboard.
Refresh the dashboard and you should see your device. Press the on button to turn it on. Now the lamp is On. and if you turn off. The lamps goes off.
Watch the video to see a live demo of the Sonoff device.
Keep in mind that with this app you can control any device on and off from anywhere in the world, because it’s controlled through the eWeLink cloud servers.
The app also comes with a nice set of features, click the timer button. You can add a timer that can be activated on a certain date and time.
I’ve tested this feature and it has been working flawlessly.
Sonoff tutorials list:
Wrapping up
That’s it for now, I hope you had fun learning about the Sonoff device. Make sure you subscribe to my blog, because I’ll be posting more tutorials about the Sonoff. I’ll be showing how to flash custom firmware.
Do you have any questions? Leave a comment down below!
Thanks for reading,
Rui
Can we change the ESP8266 firwamre ?
Yes, that’s the next post Miguel!
Awesome product with great application!
Could it be used to work in parallel with a switch, i.e., together? For example, turn on a device either through the swith or via Sonoff?
Again, congrats!
You can get the Sonoff version that also supports the 433MHz remote and you could switch the sonoff state
Hello please where can i buy Sonoff in africa, precisely in gabon
I honestly don’t know,..
I have already purchased 5 of these units am using 3 but look forward to your further posts.
Thanks Rui.
Regards
Clem
Thanks for reading! More blog posts about the Sonoff and how to flash a custom firmware in the next few days.
Hi Rui,
Thanks. Interesting solution but it maybe safer to work with standard remote control sockets (for example Energenie in the UK and similar elsewhere). These plug-in sockets can be controlled with a very cheap 433MHz transmitter. I control my lamps with a WeMos D1 board (based on the famous ESP8266) that sends on/off codes to such a 433MHz transmitter. The codes can be picked up with a receiver+Arduino when using the remote control unit that comes with these sockets. I can send more info if you wish.
There’s also a version of the Sonoff that’s got RF functionality. They also make a newer version that includes connections for ground (earth).
True but I use mine through Google Home Assistant via Voice Activation. It’s so nice to be able to just say “Good Night” and have Google turn off my TV, all of the lights in several rooms, turn on the Bathroom lights over the mirror in the Master Bath and finally start playing Cricket Sounds for 45 minutes to soothe me to sleep. Some lights come on at sunset. Others work via a simple “Hey, Google. Turn on the Table Lamp.” Home automation is great and with these switches, it;s inexpensive as well.
Where we can download the Android app? Is it included in the package when we buy? Thanks
Yes, the app is available both on App Store and Google Play store if you search for the term “eWeLink”
Thanks a lot for your interest and exposure, but I particularly think that what really matters is controlling this sonoff device not with its own app (ewlelink) but integrated with node-red turning on and off the light from the node-red dshboard
Hi Jose,
I totally agree with you! The next post is about flashing a custom firmware in the Sonoff device.
The post after that is about integrating the sonoff with Node-RED
Thanks for reading,
Rui
Hi Ru, I dowloaded the app. And read some of the comments. Some are very negative and criticise the working of the device. I.E failing in many instances. What is your comment on that. I like to see that before i purchase the gadget. Thank you. Ben
BEN,
fails in software or Hardware ?
Why earthing is outside of this device? It makes connection very complicated as you have to strip out earthing cable which is then too short as this Sonoff device adds approx 5 cm to original cable.
In this version, it doesn’t have earth connection. So you have to route the cable outside the Sonoff
Just cut out 5 cm of L and N wires and leave the earth not cutted and guide t around the switch.
Hi Rui,
I suggest you also this cool project:
github.com/arendst/Sonoff-MQTT-OTA-Arduino/wiki
I’ll be integrating these modules with MQTT very soon
I have experienced several times that the Sonoff looses connection with the WLAN network. I find it blinking with double blinks.
After a bit of investigation, it seems that if the WLAN is interrupted (turned off temporarily), the Sonoff does not manage to reconnect. Turning its power off and on fixes the problem.
Clearly a SW design fault.
For me, this makes the device unusable for a remote operation.
Maybe there is a firmware update that can fix it?
I’ve never experienced that error and I had the Sonoff running for a while.
It might be a good idea to flash a custom firmware that hopefully fix that problem.
I’ll be showing more tutorials in the next couple of weeks
I did experience similar problems but after much investigation it is all solved now by installing a new router and all is stable. means my NEST thermostat is now working all the time too.
Have you tried turnng the WLAN off, wait until the Sonoff starts blinking, then turn the WLAN on again?
I like this tutorial and the comments. Considering its cost ~$6, sonoff is a good product.
These are great devices and my only concern has been that eWeLink required full access to everything on my phone. I have 7 of them running right now and a TH10 on order for temperature control. Hope to break away from eWeLink if possible.
Hi Craig,
Here’s the tutorial that you’re looking for: https://randomnerdtutorials.com/reprogram-sonoff-smart-switch-with-web-server/
I hope that helps,
Rui
É possÃvel usar ele em paralelo com um interruptor de uma lampada?
Pode comprar a versao que pode ser controlada com o comando de 433MHz, e o Sonoff tem um pinout a mais que poderia ser usado
https://randomnerdtutorials.com/reprogram-sonoff-smart-switch-with-web-server/
Can you use MQTT to control this, is there enough memory to make this a client with MQTT?
Yes, It should handle the MQTT client. I’ve tried the PubSubClient library for the Arduino IDE (ESP8266 add-on)
How is it with proper European CE certificates of the devices? Not the China one CE.
Great Article 🙂
Great article. Thanks.
Thank you!
Hi I am interested to buy sonoff for my properties
Hi, you can go to the folllowing link to get the basic sonoff device:
https://makeradvisor.com/tools/sonoff-wi-fi-smart-switch/
I hope this helps 🙂
I want to use this inline with my current light switches. Is it possible to wire so the switch is still active, along with allowing Alexa to control?
Hello Rob, it should be possible, but I’ve never tried and I also don’t have any tutorials on that exact subject…
Hi , im newbie. sorry for the noob question. Is it this can work with TCP/IP protocol ?
This was a great introduction. I just have one question. Do you know how does pairing mode work? How do smart switch and your communicate that initial settings ie. wifi ssid and pass? Switch does not use bluetooth to communicate with the phone, and you cant be simultaneously connected to two wifi networks with your phone
Hello!
I had 4 switches working perfectly well with ewelink app using mobile outside of my home. Recently, I my modem/ router was replaced due to some problems. As some of my Son off switches were giving problems, I replaced everything with new onesSonoff (Basic 2) . Now when you switch on for the first time, the LED flashes Twice every cycle. After pressing the front button and getting into pairing mode, (led flashing continuously) I am able to add devices and operate while my mobile is connected to the Home wifi. However, when I go out of my house or disconnect the mobile from home wifi, I am unable to operate any device. It says the device is offline. I see the LED flashing twice with a long gap, which as per manual is: device not connected to Router. All my laptops and mobiles work well with the same modem/ router. Further while setup I noticed that while connecting to ITEAD, it says no internet. I tried checking same setup keeping the Sonoff switch very close to the modem/ Router. Same situation. Please help