Remote switches, Internet of Things (IoT) and Smart home in general are quite trendy nowadays. There are plenty of trademarks and devices that allow you to switch lights, heating, garage doors etc via an application on your mobile / web page.
There is one very popular gadget among the Smart housers – the Sonoff. It is actually a trademark that includes various kinds of remote switches. Sonoff devices are getting more and more popular these days because they are small, cheap, cloud ready, easy to use and have built-in AD/DC converter (i.e. no external power supply is needed, just a cable to plug it in the grid). Some sonoffs can be controlled via RF keyfobs.
Sonoffs come in different favors fitting specific or generic Home Automation needs, for example:
1) Sonoff basic – a simple remote controlled switch
2) Sonoff TH10/TH16– remote controlled switch with ability to measure temperature/humidity
3) Sonoff 4CH – a DIN rail mountable 4 channel remote switch
4) Sonoff Touch – a wall switch with touch support. NB: It requires neutral wire!
5) Sonoff Slampher – a remote switch that supports standard E27 bulbs. Can be controlled from the App and from an RF key fob. It is good solution when you do not want to change existing house wiring.
The models differ mainly on purpose and electrical load characteristics.
- Small form factor
- Cheap – $5 – $30 (depending on the model)
- 220V ready due to the built in power supply i.e. no need to buy and fit external transformers
A typical sonoff is comprised of these blocks: power supply, relay, serial/TTL IC, ESP8266. The schematic is publicly available.
Here is an assembled PCB view (Sonoff basic):
How does it work
In general to control IoT devices you have two options:
1) A local controller that is exposed via your router. This solution requires public IP (preferably static) and manual router configuration. Usually it is done by advanced users;
2) A public server (it may be a Cloud based). In this case your IoT devices connect directly to the server via your local (WiFi) network. This solution is more flexible since the control/reporting is done centrally. The devices need to have SSL/TLS for securing the connection.
Every sonoff has a button on it which serves two purposes:
1) When pressed/released it controls the on/off state of the internal switch
2) When pressed for more than 7 seconds the device enters a configuration mode
Itead offers free mobile app to configure, view and control your sonoffs – the eWeLink app. It is available for Android & iOS devices.
The initial configuration requires the SSID and password for your local WiFi network. The sonoff connects to it and then makes initial configuration requests to Itead’s Cloud (via http/https). Once configured it maintains persistent connection with the Cloud and is ready to report its state/sensor information and accept commands.
The eWeLink application also connects to Itead’s Cloud and is used to command your sonoff devices or configure them.
How to configure your sonoff
1) Connect your phone to your WiFi network
2) Download and install the eWeLink app on your mobile phone
3) Start it, create an account and login
4) Power on your sonoff and press its button for 7-8 seconds. Its led will start blinking.
5) In the eWeLink click the “+” button and choose the first option
6) Enter your WiFi SSID and password and press Next
Within 5-20 seconds your sonoff will be configured and ready for use. You will be asked to give it a name.
It is recommended to use pragmatic names like: kitchen lights, lights, heater, living room lights etc. This will help you to easily control your sonoffs using voice commands (via Amazon Alexa, Google Home etc.)
From now on you can turn the sonoff on/off, view its status, firmware version, sensor data (if any) etc.
Sometimes sonoffs may not work as expected. Its LED will reveal the reason:
1) 1 short blink every 2 seconds – the device is not able to connect to your WiFi network. Try to configure it again using the eWeLink app
2)The LED indicator quickly blinks twice and repeats, which means the device has connected to the router but fail to connect to the server. Check your Internet connection. You can also try to ping Itead’s servers. For EU it iseu-disp.coolkit.cc. Be warned that recently there were plenty of server issues in EU region.
3)The LED blinks once every 1s, and the device is offline.The device has successfully connected to the router but hasn’t been added to the user’s account. Use the eWeLink to configure it.
You can also see the official troubleshooting guide.
For advanced users
The heart of every sonoff is the chip ESP8266. It runs the firmware, maintains WiFi connection, Cloud connectivity, controls and reports switches/sensors.
Unfortunately sonoffs do not offer local API support so you need to rely on their Cloud services. This can be a problem if you have unstable Internet connection or worst – if Itead have issues with their servers. In these cases you will not be able to control anything in your house.
For this reason many people replace sonoff’s firmware with more flexible ones:
The actual flashing (firmware replacement) can be tricky. You have two (known) options:
1) Using an FTDI module – this requires disassembly, iron work and cabling . Here is header’s pinout (sonoff basic):
And here is how to connect the FTDI module:
2) Using the original OTA process – this is very neat 🙂 The idea is to push the sonoff to download its new firmware from your server (instead of Itead’s one). Check out SonOTA for more details.But keep in mind it highly depends on Itead’s firmware and can break in case of changes.
Sonoffs offer many options for control and integrates with various systems:
- You can setup timers and scenes via the eWeLink App
- You can use voice to control sonoffs via Amazon Alexa / Google Home
- You can integrate it with IFTT