WiFi Switch for home appliances with ESP8266

Learn how the build your own WiFi switch with the ESP module and how to control any appliance of your favorite place.

What are WiFi Switches?

Nowadays we are living in an Internet of Things age and WiFi Switches are basically the foundation of it. They are devices that can turn on, off or dim home appliances like lights, fans, etc remotely or autonomously, controlled by our cellphones, our voice, the room temperature or even weather reports.

How do they work?

They are based on wireless communication (commonly known as WiFi) that let them connect to the internet and process data, so they can take action due to certain conditions established by the user.

2. Ubidots Device and variable creation.

Go to the Device section of your Ubidots account and create a new device called "wifiswitch".

Inside your "wifiswitch" device, create a variable called "light".

3. Ubidots Dashboard and Widget creation.

Once our device and variable are created, we can create a dashboard and widget to control the light from a web or mobile dashboard. To create a new dashboard, press the "Data > Dashboard". Then press the plus icon and complete the dashboard configuration as is desired.

Now, create a control widget to set the status of the light bulb associated with the variable "light". To create the control widget, select the plus icon located at the right upper side of the page. Then press "Switch" as widget type, select the variable desired to be controlled and complete the widget configuration as is desired.

If properly uploaded, you get the response: "Library added to you libraries."

8. Close and open again the Arduino IDE.

Programming the ESP8266:

Once your ESP8266 is set up, we can start publishing and subscribing data from/to Ubidots in order to control the Wifi Switch.1. Copy and paste the following code in the Arduino IDE. Don’t forget to customize the Wi-Fi SSID and password and your Ubidots Token.

To upload the code to the ESP8266 we need a serial interface to communicate (Programmer) the module with the PC, we can use USB to TTL converters, but in this case, we are going to use the serial of the Arduino that do a very good job.

To upload the code into the ESP8266 you have to follow the connections below.

Arduino Nano

ESP8266

TXD

TXD

RXD

RXD

3.3V

VCC

GND

GND

3.3V

CH_PD

GND

GPIO0

NOTE:Please be careful with the VCC of the ESP8266, it works only with a 3.3V supply.

Now, verify your code is correct by clicking the check button in the Arduino IDE above the editor.

Once the code is verified, you will receive a response similar to the one below, indicating that it is properly set up.

Next, your have to upload the code into your NodeMCU. To do this, choose the right-arrow icon besides the check icon.

Once the code is uploaded, you will receive the message below in the Arduino IDE:

5. Configure voice commands using Google Assistant:

To control your “WiFi Switch” with Google Home, first we need to configure an intermediary platform called IFTTT, this will let us to pair our Switch with the Google Assistant. To configure correctly, follow the steps shown below.

If you don't have an account, Sign up.

Click on “My Applets”.

Then, click on “New Applet”.

Click on “+ this” to configure the trigger of your condition.

Search for “Google assistant” service and click on it.

Click on “Say a simple phrase”.

Complete the trigger fields with the phrases you want to use to control the light, the response and the language, then click “Create trigger”.

NOTE:Repeat everything to set the “Turn off the light” applet, with the correct Body statement.

6. Testing Session:

Due to the diagram shown in the picture, connect correctly the module to your AC appliance.

Home

Module

Line

L

Neutral

N

Light Line'

B

Add a momentary button of your preference in the terminal block called SW.

Identify the Line, Neutral and Light cables:

Make the connections and place the button, tight the screws and test.

In case you're a visual learner check out the following video tutorial. You can find all the steps I made to build this project carefully explained:

Summary:

In this guide, we just learned how to build a WiFi switch that can be controlled over the internet by your voice, cellphone app, or your PC, that let you control a light bulb of a bedroom or any other place. This device works based on the ESP8266 WiFi module, that is a tiny module that let the project get online easily. And this device can be applied in the control of many different devices like fans, motors, curtains, lights, led strips, and much more.