Device, principle of operation and connection of the Wi-Fi switch. Wireless switch, what is it and is it worth it to install Smart home wifi switches

Hello, dear readers and guests of the Electrician's Notes website.

In my past publications, I introduced you to and touch, controlled both manually and from the control panel.

But today I would like to draw your attention to the relay (switch) Sonoff of the Basic version with the ability to control directly from a mobile phone via a Wi-Fi network or the Internet.

The Sonoff Basic relay is a small device (88x38x23 mm) that can be placed behind the ceiling space, in a building niche, or in the bowl of a chandelier or lamp without any problems.

Its cost at the time of publication of the article is a little less than 300 rubles. As you understand, this is quite acceptable money, moreover, for such a modern device. I bought it on the well-known trading platform Aliexpress (the link will be at the end of the article).

The kit included two protective covers with mounting screws, but, unfortunately, there were no instructions.

The Sonoff relay has the following technical specifications, some of which are displayed directly on its body:

  • maximum controlled load current 10 (A)
  • supply voltage from 90 (V) to 250 (V)
  • wireless standard 802.11 b/g/n
  • security protocol WPA-PSK/WPA2-PSK
  • operating temperature from 0°С to 40°С
  • weight about 50 g

Sonoff Basic Relay Capabilities:

  • load management via Wi-Fi
  • Internet load management
  • load control according to a given timer, both with direct and reverse countdown
  • load management from multiple mobile phones

These are the possibilities the Sonoff relay has. It can be safely used in smart home systems and for various other needs and requirements.

First, I will tell you how to connect Sonoff, and then we will check all its declared control methods in practice.

So let's go.

Installation and connection of the Sonoff relay

For the Sonoff relay to work, it needs a supply voltage of 220 (V), which means that it can be installed without problems in a place convenient for you, for example, in a chandelier bowl or right under a stretch ceiling, as well as directly in a junction box if there is enough space.

The relay has two mounting holes to mount the relay to a surface.

The Sonoff relay wiring diagram is very simple.

On the terminals (L) and (N) from the side (Input-Input), the phase and zero of the supply voltage 220 (V) are connected, respectively. Naturally, when connecting, do not forget about.

Please note that the wires to be connected must have a cross section of no more than 1.5 sq. mm. But I still tried to connect wires with a cross section of 2.5 sq. mm. As a result, a rigid (single-wire) wire can still be connected without problems, but a flexible (stranded) wire is already inserted into the terminal with great difficulty, so it had to be flattened and deformed a little.

For example, I used a power cable of the PVS brand, which just the same has a cross section of 2.5 sq. mm. At the other end of the cable there is a plug, which I will later plug into any outlet with a voltage of 220 (V).

On the terminals (L) and (N) from the side (Output-Output), the phase and zero load are connected, respectively.

For the convenience of connecting the load, I connected a socket to the relay output.

By the way, terminal covers not only have a protective function, but also play the role of clamps for power wires or cables.

This is how it all turns out nice and neat. Sonoff relay connected.

As a load, I connected an LED lamp, about in one of my articles.

Here is a simple example of a Sonoff relay wiring diagram for a group of luminaires.

By the way, it is not necessary to use only a lamp or a group of lamps as a load. Any other load that does not exceed the rated current 10 (A) can be safely connected to the output terminals. And if you still need to control a load that has a current value above 10 (A), then it can be connected to a contactor, and with the help of a relay you can already control the coil of this contactor.

In this regard, we can add that when using a contactor, you can control at least a single-phase load, at least a three-phase one, at least with alternating current, even with direct current.

It will look something like this.

Thus, the scope of the Sonoff relay is very wide and varied. It can be controlled by at least one light bulb, even a powerful single-phase electric heater, even a three-phase electric motor, etc. It all depends on your needs and requirements.

And now let's look at all the possibilities of controlling the Sonoff relay in more detail.

I will not open the relay and look at its device, there is already enough information on the Internet on this subject - look at the relevant electronics resources. And judging by the reviews, the performance of the relay is quite decent. By the way, who is interested to know, the relay is assembled on the basis of the well-known Chinese microcontroller ESP8266.

Load management via phone via Wi-Fi network

Before I talk about controlling the relay via Wi-Fi, I will say that it can also be controlled manually. To do this, on its body there is a small recessed black button. So, with one short press of it, the relay turns on, and when it is pressed again, accordingly, it turns off. Moreover, for this it is not necessary that the relay be connected to a Wi-Fi network - it will also be controlled in Offline mode.

But in addition to this, the button also carries other functionality, which I will discuss below.

To implement the ability to control the load via Wi-Fi and the Internet, you need to install the eWeLink mobile application on your phone. This app is available for both Android and iOS devices. To facilitate the search for the application, you can use the necessary QR codes on the package.

For Android devices, the eWeLink app can be downloaded for free from Google Play and installed on your phone without any problems. The program interface supports Russian.

For iOS devices, this app is available in the App Store. I have not tried to download and install this application on an iPhone or iPad, so if you have tried this application on iOS devices, please write in the comments about the results.

After installing the eWeLink application, you will need to immediately register, indicating the country and your email address. In this case, the phone must be connected to the Internet.

After that, a verification code will be sent to the mail (valid for 30 minutes), which must be entered in the corresponding line "Email code". On the same page, you must enter a password to enter your future account (at least 8 characters).

By the way, letters reach the mail services Mail.ru and Mail.yandex.ru (Yandex-mail) without problems. But as far as I know, letters with a verification code do not always reach the Gmail.ru (Google mail) mail service, so keep this in mind.

Then it is necessary to pair the relay and the router by holding the same button on the switch body for a long time (for 5 seconds), after which the green LED on the relay will blink. Put a tick on the first connection mode and click "Next".

Now you need to select our Wi-Fi network from the list and enter a password from it. In order not to enter a password each time, you can check the "Remember password" box. Click "Next", after which the search for our device and its registration will begin (in time it took me no more than 2-3 minutes).

After successful pairing, the relay automatically transfers data to the Chinese cloud (Amazon AWS or Coolkit), which makes it possible to control it via the Internet. But I will return to this a little later.

As you can see, our relay is now displayed in the list of all devices (so far it is the only one in the list, but others will appear very soon).

When the relay is online (on the network), the green LED on its body is always on. As soon as the LED starts to blink, it means that the connection with the router or the Internet is lost. Just by this indicator, it is convenient to determine whether the relay is in the network (Online) or not (Offline).

While I was testing this device, I did not notice any problems with the loss of the network. The device is always online and responds stably to control commands.

Now you can try to turn on the relay through the phone. To do this, click on "Relay 1". Immediately, a red inscription appeared stating that the eWeLink application needs to be updated, although the update is not displayed on Google Play.

We go into the device settings (three dots in the right corner) and see that the application has the current version 1.5.2, and a newer version 1.5.5 is available. Click on the "Download" icon and the application update begins. After the update, the red inscription disappears, and in the settings we can see the new current version 1.5.5.

Remember!!! The main condition for the operation of the relay is the availability of Internet access.

If Internet access suddenly disappears, then the green LED on the relay case will flash, and the application will display the Offline mode on its tab, i.e. not available for management.

So, to turn on our "Relay 1", you need to enter it and click on the round virtual button in the center of the screen. Moreover, you can control the relay from the general list of all devices by clicking on the corresponding small button (on the left). In general, whoever likes it.

When the relay is off, the button is white with a gray background around it. When the relay is on, the button changes its color to green, and the background around it turns blue.

In addition to the banal principles of control, you can set the time to turn on or turn off the relay by timer by setting the appropriate date and time for its control.

Moreover, I was surprised that the relay is triggered by a given timer even when it is offline (Offline), which means that all the specified timer programs are stored directly in the relay's memory.

Click on the "Add timer" button and go to the timer settings page. Each timer is configurable to either turn the relay on or off. There are two options for setting the timer:

  • single (single operation on a given date and time)
  • repeated (periodic triggering on a given date and time, including specifying specific days of the week)

In addition to the countdown timer, there is a countdown timer. Very necessary functionality for certain purposes. It is configured similarly to a direct timer, only with the possibility of a single operation.

In addition to the forward and reverse timers, there is a cyclic timer in the "Settings" tab (three dots in the right corner).

In this tab, you can configure various options for relay operation cycles. I will not talk about this in detail, because. everything here is simple and intuitive.

The total number of configured timers, including the cyclic timer, can be no more than 8. And be careful, because. if different timers are superimposed on each other, none of them may work!!!

Also in the settings you can specify in which position the relay will remain if the 220 (V) power is suddenly turned off from it. There are three options here. By setting the appropriate checkboxes, you can choose that when the 220 (V) power reappears, the relay can either turn on, or turn off, or remain in its original state.

By the way, this is a very handy feature. Just remember the nuance, which, when the 220 (V) power disappears and reappears, for some reason always turns on, and even when it is in the off state. And imagine that you are not at home, the voltage in the network “blinked” a little and the controller turned on the chandelier on its own. Here such an incident will not occur, because. in this case, everything can be customized to your needs.

In addition to the above, all your connected devices in the eWeLink application can be grouped together and combined in various scenarios.

Is it possible to control the relay from several phones at once?

Can! Naturally, at the same time, the eWeLink application must be installed on each phone.

There are two options here. The first option is to log into the eWeLink application with the same name and password from different phones and control the relay.

True, if you enter the application on one phone, and then at the same time enter the application under the same login and password, but on another phone, then an error will occur on the first phone and the application will automatically exit. At the same time, the second phone remains in the application and can be used to control devices.

At the same time, I would like to note that when the relay is controlled from one phone, its status is displayed almost instantly on all phones that are connected to it.

Internet load management

In addition to controlling the relay via a phone via a Wi-Fi network, it can also be controlled via the Internet from anywhere in your location, i.e. absolutely from anywhere in the world where there is Internet access.

So, to control the switch via the Internet, you must log in to the same eWeLink application using your username and password that you specified during registration. And then everything by analogy. The same application, the same settings, the same control buttons, etc., the only difference is that you are not at home within the coverage area of ​​your Wi-Fi network, but at a distance of hundreds and thousands of kilometers from home.

A little about the cloud.

But still, you will not be able to control the relay without the Internet, because. control is not through a local network, but through the Internet, i.e. the same Chinese cloud that I mentioned above. And it doesn’t matter if the control is via Wi-Fi or via the Internet, the control always goes through the cloud, and access to the cloud requires Internet access.

In this regard, various craftsmen have already figured out how to untie this device from the Chinese cloud or make it control only through the local home network. For those who are interested, this information can be found on certain resources.

By the way, if you need a similar device, but with an additional radio control function from the remote control, then you can order the Sonoff RF version relay.

If you want to control the load where there is no Internet at all, then you can use the Sonoff version G1 relay (GSM / GPRS with SIM card support). Also, this manufacturer has available relays with temperature and humidity sensors Sonoff ТН10/ТН16 and two-channel (for controlling two independent loads) Sonoff Dual relays.

In general, the manufacturer Sonoff has many different devices, I will tell you about some of the most interesting and significant ones on the pages of my website, so subscribe to the newsletter so as not to miss interesting releases.

You can buy the Sonoff relay here:

  1. Sonoff Basic: https://goo.gl/jXyNm3
  2. Sonoff RF (with radio control): https://goo.gl/TRPqN6
  3. Sonoff G1(GSM/GPRS with SIM support): https://goo.gl/EkpTdp
  4. Sonoff ТН10/ТН16 (temperature and humidity sensor): https://goo.gl/MWAL5p
  5. Sonoff Dual (dual channel): https://goo.gl/a7rV56

And already by tradition, a video based on the materials of the article, where you can more clearly see the configuration and control of the Sonoff relay:

I have long wanted to automate the process of drying the bathroom after bathing. I had a lot of reviews on the topic of humidity. By the way, in winter we dry our clothes in the bathroom. But he has not yet decided what exactly to implement in life. I will describe another Chinese miracle to combat this evil.

In summer we dry clothes on the balcony, in winter - in the bathroom, it is enough to turn on the exhaust fan. But monitoring the fan is not always handy. So I decided to put automation on this case. The first implementation experience was unsuccessful. The review was. But I did not give up ... The second experience was more successful, I also did a review. But he did not manage to implement it in life. Frequent business trips take up a lot of time.
But I did not expect such a gift at all. I saw a letter in a personal with a proposal to review the work of Itead Studio. It is foolish to refuse a product for review if it is interesting (and even more necessary) yourself. Immediately after the "browsed" Muska. I found at least three reviews about Sonoff products. I'm not the first: (I can imagine how many votes there will be in the comments about the free cookie. But spitting in the back is the lot of the weak and the losers. Therefore, this review is for those who consider themselves capable.
This is what my shopping cart looks like:


But I made a small oversight, did not pay attention to the text in the picture (on a red background). The switch came without a remote control: (This is an additional option, it must be purchased separately
The order came in a small box.


The TH16 module was without packaging.

The rest is in boxes. But there were no instructions. That's all I ordered.
I'm pretty lazy person. The only thing that can make me do something is a commitment to someone. They say that laziness is the engine of progress. My engine is a promise given to someone. Thus, I killed two birds with one stone: I wrote a review and figured out these magic switches / switches.
Let me remind you a little of my story.
When I moved into a new apartment, I almost immediately put a fan with a check valve in the hood. A fan is needed to dry the bathroom after bathing. A non-return valve is needed to prevent foreign odors from neighbors from entering the apartment (when the fan is silent). It happens. All ventilation ducts are individual, but cement was apparently saved during laying. Probably the smell passes through the cracks.
Fans I have a variety of options. There are simple ones, there are with a timer (time interval adjustment), as in the photo.


That's what I've been using to this day.
Since I live in an apartment "anthill", the only place to dry clothes is the balcony. In the bathroom, it can fade. Drying requires either low humidity or air circulation. Fulfilling both conditions is the best option. The fan was supposed to solve this problem. At first, that's exactly what he did. The main thing is not to forget to turn it off. While the fan is running, it is necessary to slightly open the window. Do you need to remind about the school problem with a pool and two pipes? In order for the air to go into the hood, it is necessary that it enter the apartment from somewhere. Who has wooden windows, not plastic ones, there will be no problems. Enough cracks. But with plastic, the apartment turns into a terrarium.
Then I thought about automating the process ...
I have already shared the sad experience of implementing my idea. Here is that module. It can't work in PRINCIPLE.


I also drew a diagram of the module.


The circuit is based on a comparator on the LM393. On the face of it, everything should work. But there is one but. The sensor is unusual. It changes its resistance with respect to frequency. To take readings, it is necessary to apply a frequency to it (the normalized value is 1 kHz). That's such sadness.
On one of the sites there were three comments from one user about this:

Strange, this is a standard sensor from the Arduino peripherals - it should work.
There is nothing to check yet - I'm not particularly interested in humidity, so I don't have such a sensor yet. :)
I will order and write back...
... I don't have a single arduino module that doesn't work.
I’ll buy it for testing, maybe I’ll make a weather station for myself ...
... do you think they would have done it if they were non-working?
A year has passed...
Apparently, I can't wait.
I'm going to send.
The store page with the TH module looks like this:

On it, you can select Sonoff TH modules depending on the relay current, as well as humidity and temperature modules. What exactly I chose, you see. I did not find the humidity module in a separate sale on the store page (maybe I was looking badly). So be careful when ordering...


There were no instructions either (already wrote).
The store has a wiki help page:

Everything is there, even the scheme:

Small in size.


Weighed, 79g.


I start parsing.
220V mains wires are connected here.


Spring contactors are very tight. But, on me, with the screw it is more reliable.
The case is held on by latches.


All in the mind. I have no comments.
Loosen 4 screws.


Wi-Fi node is built on ESP8266 (who would doubt it). For aces, a whole field for activity. The main thing is that the head works. The rest has already been done. There is no need to block a separate power supply for the module, there is no need to look for a box either. Everything is assembled and working.




The payment has been cleared. There are no traces of flux. At the entrance there is a fuse and a varistor 10D471K against overvoltage (decoding - diameter 10 mm, voltage 470 volts).

Haven't seen this in a long time. I collect everything in the original.
I turn to the humidity module. This one came in a box. What is written on it (on the box), you can read. Photos allow you to do this.

The module is unusually large.

It connects via a connector, like a headphone.


It turns out in this way.


Everything is written on the body.


The store has a wiki help page (already wrote):
- Temperature and humidity module
AM2301 Product Manual
There is also a manual for the temperature sensor:
- DS18B20 - Programmable Resolution 1-Wire® Digital Thermometer
I didn't order it. He's not interested in me. Plus, the AM2301 is more versatile. It has both a temperature sensor and a humidity sensor. Moreover, in the TH10/16 case there is only one hole for the remote module.
I disassemble AM2301. Case on four latches.


On one side of the module is a temperature, humidity and quartz sensor.


Main diagram on the back.

I also collect this module.
And finally, the Sonoff RF smart switch.



Also no instructions. Even smaller than the Sonoff TH.


Weighed: 49g.



For me, it is of no particular interest. But I'll show you what's inside.

The case is also on latches. You can see the parsing sequence.
Screw contactors. For me, it's very convenient.


At the input there is a varistor 10D471K against overvoltage (decoding - diameter 10 mm, voltage 470 Volts), as in the VT module.


Power supply unit with galvanic isolation from the mains. They even made cuts in the board.
The payment has been cleared. There are no traces of flux.


All in the mind. And I have no comments here.
And here the WiFi node is built on ESP8266.


Radio module as a separate board.


I collect everything in the original.
It's time to get down to business.
I'm putting together a training plan. I connect the Sonoff TH module to the network. The connection is not obvious to everyone. Therefore, we look at the picture on the store page.

We have very few devices that work like this. Therefore, I put a red cross on the "extra" wires.
I hang a fan at the exit.
It's much easier with Sonoff RF. I connect an ordinary light bulb to the output for control.


It remains to connect the whole thing with a smartphone.
Smart switches support Wi-Fi remote control, but only via the cloud :(
It's time to link them to the eWeLink control app. To do this, you must first download it :) Install, register ...
The account has been created.
First I connect Sonoff TH. I launch the application and follow the instructions.
To add a device, click on the plus sign. Next, press the white button and hold for about 5 seconds. The blue LED should flash evenly. Exactly evenly! He can "go into a trance" :) and start giving strange signals. In this case, press and hold again.


The application asks for a Wi-Fi password. Then it searches for devices.
You will need to enter a name for the new device.
See the sequence of pictures in the photo (from left to right, top to bottom).


The switch is "linked" to my account.
Same with Sonoff RF. After binding, the picture on the smartphone looks like this. You can turn the load on and off by pressing the buttons. Three pictures: off, on and not connected to 220V (offline)


In order to turn on the switch, you need to press a button on your virtual remote control from anywhere in the world where there is Internet and Wi-Fi.
When connected to a 220V network, a blue LED lights up on the module. When the load is turned on, the red LED additionally lights up.


But it's all manual mode. In order to enter the automatic mode and get into the setting of the parameters for switching on and off the switch, it is necessary to move the lever (Auto-Manual) to the auto position.


And in the settings I put what I need.
Let me explain the pictures. Now 55% humidity and temperature 18˚С (remote module on the windowsill). The switch is off. At the same time, temperature and humidity are monitored online, regardless of which mode the switch is in (manual or auto).
Let me explain what I asked.
When the humidity reaches 65%, the switch will turn on (fan). At achievement of humidity of 60% - will be switched off. You can do the opposite (for a humidifier).


This is for those who have very low humidity in winter.
When the humidity reaches 30%, the switch will turn on (humidifier mode). At achievement of humidity of 40% - will be switched off.
All settings are in accordance with GOST 30494-96 Residential and Public Buildings.


Pay attention to the optimal humidity in winter. This is not at all 60% as many people think! 60% is only acceptable, it is impossible to go higher, it is necessary to fight. OPTIMUM 30-45%
You can control the switch by timer. There are two options.


Temperature triggering can be configured. All settings are identical to the settings for humidity, just select the temperature.

A little about the Sonoff RF smart switch.
It differs from Sonoff TH in that it has a radio module (it can be controlled using a remote control that I don't have). It also does not have the ability to work with a humidity and temperature sensor. The rest is the same: Wi-Fi control with the ability to set a timer.
The virtual remote is slightly different.


In automatic mode, too (like in VT) there are two types of timers.


I repeat. For me, it is not of particular interest, but I will definitely find a use.
I will note the nuances of the operation of these switches. Without the Internet, you will not get any control.
BUT there is one big plus. The automatic mode configured on the switches will continue to work regardless of the presence of the Internet!

When installing the application on several phones, you can manage it from all, but only if you log into eWeLink using the same login and password on each of them.
At the end, I will sum up a little.
Smart switches support remote control via Wi-Fi, but only via the cloud: (You need to link them to the eWeLink control application. And if some kind uncle Liao wants to control your smart home? For those who do not trust him, you will have to create your own MQTT server, and turn on / off the load according to your desire and rules. For those who have programming skills, this is not difficult. For those who are calm about such a problem, just connect and use. For example, I don’t care when managing fan in the bathroom.But when the time comes to a full-fledged "Smart Home", I'll think of something.
That's all.
These modules are ideal for working with a fan, air conditioner, humidifier. You can organize a smart irrigation system in the country. Even a gas boiler can be controlled by time and by a given temperature in the room.
How to properly dispose of the information from my review, everyone decides for himself. If something is not clear, ask questions. Hope it helped at least someone. Perhaps someone will want to help me. I'll be very grateful.

Good luck everyone!
Functional check and giblets:

The product was provided for writing a review by the store. The review is published in accordance with clause 18 of the Site Rules.

In the modern world, the “smart home” system is becoming common. With its help, you can remotely control many elements and devices of our home. You can also remotely control the lighting in the room. Such inventions contribute to the comfort of this room, and are also used where the elderly and people with disabilities live. This article will discuss how it works and why you need a Wi-Fi light switch, which is gaining more and more popularity among the population.

Strengths and weaknesses of the device

Wi-fi light switch has the following advantages:

  1. No need to lay additional cable.
  2. It is possible to centrally control lighting devices, that is, from one command point. In order to control the wireless light switch, you can use a smartphone, tablet, computer, as well as a remote control. For tablets and other electronic devices, the necessary software must be installed. It can be downloaded from the Internet or installed from a disk.
  3. Large signal coverage area. Despite the walls, the digital radio signal penetrates into the right room.
  4. This system is very secure. Even if the design of the device is damaged, it does not threaten the tenant with a strong electric shock, because the Wi-fi switch has a very small current strength.
  5. The device normally works with all types of light bulbs (LED, incandescent, energy-saving).
  6. You can set different combinations, as well as modes of operation of lighting devices.

If we talk about the shortcomings of light switches, then there are only a few of them. The main ones are that the price is much higher than conventional keyboard models and there is a certain risk of running out of batteries in the remote control, or a bad Wi-fi signal.

Design features

The set of Wi-fi switches includes a receiver and a transmitter. The receiver is a relay on the control. It can be controlled via a smartphone with access to a Wi-fi network, or using a remote control. When the relay receives a certain signal, it closes the wiring circuit. The relay is installed near or inside the luminaire. This is possible due to the small dimensions of the device. The reason for installing the instrument near a light fixture is so that it does not fall out of the radius in which the transmitter is operating. If there is spot lighting in the room, then the receiver can be placed in a junction box or behind a false ceiling.

The switch or transmitter has a small power generator that is capable of generating electricity when a remote control button is pressed or a specific command is sent from a smartphone via a Wi-fi connection. In turn, the pulse is processed into a radio signal that enters the device. Such radio-controlled light switches are quite expensive, and their analogue is regulation from a remote control in which batteries are located.

Types of switches and the best manufacturers

At this time, the range of Wi-fi light switches is not too large. However, products are classified according to several criteria:

  1. The device can be controlled by electronic or mechanical keys. In the first case, we are talking about the touch screen of the device. The keys are located on the remote control (remote control).
  2. There are also light switches with both and regular keyboards. With the help of the first devices, it is possible to adjust the brightness of the lighting, thereby changing its intensity. To adjust the brightness, either hold or scroll the corresponding button.
  3. This switch can provide full control of not only one, but also two or three groups of lighting devices. However, the price of a wireless device that can control entire groups is quite high.

At the moment, there are seven main manufacturers of wireless electrical fittings for lighting control:

  1. Legrand - the country of manufacture is France. The company has a whole line of products called Celian.
  2. Vitrum is a country of origin Italy. This company uses a technology called Z-Wave. It allows you to fully automate the control of lighting in the house.
  3. Delumo - products are manufactured by a Russian company that, in particular, produces dimmers, switches and thermostats.
  4. Noolite - accessories are made by Belarusian manufacturers.
  5. Livolo is a manufacturer in China. This company produces specialized devices for automation. Also in the product line there are products for both single and double frames for switches.
  6. Broadlink (China). This manufacturer has a fairly large selection of products for lighting control.
  7. Kopou is the latest company to also be based in China. The manufacturer manufactures dimmers in the form of various key fobs.

The video below provides an overview of another interesting Wi-fi light switch model:

Correct connection

In order to properly mount the switch, you need to know its principle of operation, what the device consists of and how to connect the Wi-fi switch. The wiring diagram for this wireless device is very simple.

One of the benefits of a Wi-Fi light switch is that it is easy to use and connect. With a strong desire, you can install the device with your own hands. It is important that you follow the manufacturer's instructions exactly. This installation only takes a few minutes.

The connection process consists of only two steps:

  1. Installing a radio receiver.
  2. Installation of a light switch (control buttons).

Most receivers have two to four wires. They come out of the body of the device. To determine the input wire, you must read the instructions. The remaining wires will be output, for example, a double switch will have two outputs. To install the receiver, open the phase that supplies power to the lighting fixture and connect it to the circuit, while following the sequence.

If more than one lighting group needs to be connected, proceed as follows:

  • zero is applied to all lighting fixtures;
  • phase forks in Wi-fi switch;
  • phase should be applied separately to each group of luminaires.

The control button is installed quite simply, first you need to make a hole in the wall using a perforator with a concrete cutter. An ordinary plastic socket is inserted into the finished hole, and gypsum can be used to fix it. The installation process is absolutely no different from the keyboard type. The only difference is that there is no need to lay wires, you just need to securely fasten the button in the socket.

Like( 0 ) I do not like( 0 )

Technological progress has brought new, more advanced ways to control light. Wireless technology has replaced the old-style switches. The most modern way to transmit signals is via Wi-Fi. The technology involves the transmission of digital data over radio channels. A Wi-Fi switch is used to transmit commands.

Advantages and disadvantages

Wi-Fi devices are characterized by the following positive qualities:

  1. There is no need to lay a dedicated branch of electrical wires.
  2. Lighting devices can be controlled centrally - from one command post. Smartphones, computers, tablets or remote controls are used as a control device. Smartphones and other electronic devices require special software that can be downloaded from the Internet or installed from an installation disk.
  3. Extensive coverage area. The digital radio signal penetrates even through walls.
  4. System security. In case of damage to the structure, a person is not threatened with a strong electric shock. The current strength is too small to harm the human body.

Types of devices and manufacturers

The range of Wi-Fi light switches is not too diverse. However, products are classified according to a number of criteria:

  1. The switch is controlled by mechanical or electronic keys. In the latter case, we are talking about a touch monitor. The keys are located on the remote control.
  2. Switches are available with or without dimmers. This device allows you to adjust the brightness of the light by changing its intensity. The setting is carried out by holding or scrolling the corresponding button.
  3. The switch can provide control over one, two or three groups of lighting fixtures. The prices for equipment capable of managing groups of instruments are disproportionately high.

There are several dominant manufacturers of wireless technology for light control on the market:

  1. Legrand (France). The company's product range includes, in particular, a product line called Celian.
  2. Vitrum (Italy). The Italian company uses Z-Wave technology to automate the processes of controlling light in a smart home.
  3. Delumo. Products from a Russian company that produces switches, dimmers and thermostats.
  4. noolite. Switches of the Belarusian production.
  5. Livolo (China). The Chinese company produces specialized devices for automation, including for "smart home". The range includes products for single and double frames for switches.
  6. Broadlink. The Chinese company manufactures a wide range of lighting control products.
  7. Kopou. Another company from China offers a dimmer in the form of a key fob.

Wiring diagram

Smart light switches are easy to install. If desired, they can be mounted by hand. You just need to strictly follow the requirements of the instructions. Installation will take just a few minutes.

The installation process includes two steps:

  1. Installing a signal receiver.
  2. Installing the control button (that is, the switch itself).

The receiver has two to four wires. To determine which of the wires is the input, you should read the instructions. The other wires are outputs (a dual switch will have a pair of these wires). Installation involves breaking the phase that supplies power to the lighting fixture. Next is the connection to the electrical circuit.

If there is more than one lighting group, the actions are as follows:

  1. We supply neutral wires for lighting.
  2. We branch the phase on Wi-Fi.
  3. We direct the phase separately to each group of fixtures.

The switch is installed by a series of sequential operations. First, drill a hole in the wall. Next, we install a plastic socket in the recess. The installation process here is no different from installing a conventional light switch. The only significant difference is that there is no need for wiring. It is enough to fix the button in the box.


This article will focus on ESP8266 Wi-Fi module, programming language LUA and firmware nodeMCU. The manufacturer's SDK will not be considered.

About three years ago, I tried to implement a switch on a 1-wire bus. I didn't like how it all worked.

  • Single point of failure all logic on the server;
  • Slow speed;
  • To each switch you will have to pull from 2 wires (ideally a “vitukha”).

As a result, all this was successfully abandoned, other wireless solutions were considered, but were excluded due to high cost, insecure protocol and implementation complexity. I wanted something simple with a minimum of components, with its own logic and cheap. Recently ordered 2 pieces. esp8266 just for fun, not knowing exactly what to do with them. After 2 evenings of showdowns with the chip, I remembered the unfinished business with the button and decided to bring it to its logical end.

There are already a number of firmware for this module, you can also write firmware for yourself using the SDK, but I didn’t go into the details of writing, because after studying the nodeMCU API, I realized that this functionality was enough for me with a margin and I flashed both modules.

Iron

Cost is an important factor for a simple switch, so I tried to use as few parts as possible. I decided to make from what was at home, but I had to buy a solid state relay. By the way, the “relay” is more expensive than the wifi module and can be replaced with an optocoupler, a triac and a strapping, switching circuits are easily searched on the Internet. There was a case when a bad contact in the bulb holder knocked out the triac for a short time. Let's see how the opto-relay will show itself, because I have not worked with them before. It is worth considering for a large load the installation of a radiator is required.

Here I immediately ran into a problem, if on gpio, when turned on, it went to the ground, the board switched either to the firmware mode or to an incomprehensible mode, because the button is normally open, there was nothing to redo with it and left it to be closed to the ground, and the opto-relay hung on a plus through a resistor and turned on with a supply of 0, turned off with a supply of 1, respectively. As a result, the following scheme turned out:


Attention, the scheme should be improved! The output to the relay should be fed through the transistor, and the button should be pulled up through the resistor from the plus. The ingredients turned out like this:

  • switch;
  • spring (for converting the switch into a button);
  • esp8266 itself;
  • solid state relay used(S202T02);
  • scarf for design;
  • 470 ohm resistor;
  • wires;
  • connectors to taste;
  • phone charging 400mA 5v;
  • stabilizer 1117 3.3v;
  • pair of capacitors.

The alteration of the switch did not take much time, I threw out the standard LED. He extended the wires from the module in the center of the switch, placed the module outside under the plastic button, and the power unit inside. Not many photos of the process (photo from the phone):

nodeMCU

The firmware uses the Lua programming language, this language is similar to Javascript. The version is still damp, but already the basic functionality is not badly implemented. Immediately after loading, the module starts executing the script file init.lua, this file is not in the clean firmware, you have to create it manually. All operations can be performed through the console connected to the "com" port, to simplify uploading files to the module, there is a luatool script. The fill works as follows and this code shows the process of writing to a file in full.

File.open("init.lua","w") file.writeline([]) file.writeline([[--comment]]) file.close()

An example of reading a configuration file. It doesn't look very good. Can eat also other variant of the serialized data.

File.open("config") c_wifi_ssid = string.gsub(file.readline(), "n", "") c_wifi_key = file.readline() file.close()

An example loop using the 1000 millisecond pause API is shown below:

Tmr.alarm(1000, 1, function() if wifi.sta.getip()=="0.0.0.0" then --current ip print("connecting to AP..."..c_wifi_ssid.."/". .c_wifi_key) else print("ip: ",wifi.sta.getip()) tmr.stop() -- alarm stop end end)

Working with GPIOs

If you have a module model ESP-01 new revision, you only have 2 gpios available without resorting to a dirty hack.


I decided to abandon such a hack and use what is.

One gpio button and second output to solid state relay. There is also Tx, but I couldn’t get it to work as gpio, and for indication I just pass messages to the console print(). While kostylil just like that. The longer the message, the longer and brighter the LED flashes. The owners of this modification fly through the forest and with such functions as (node.key, node.led), because they can only use GPIO16, which is also not wired on the board.

All gpios can work in several modes (OUTPUT, INPUT, INT), but what is interesting is that the function gpio.read(), before counting, goes low even if OUTPUT mode is set. That is, to get the current state of the exit, this is not suitable. I had to use an external variable and write two functions for convenience, and then define activity through the variable.

Function on() gpio.write(8,gpio.LOW) oo=1 end function off() gpio.write(8,gpio.HIGH) oo=0 end

Events can be used callback gpio.trig(pin, type, function(level)), the second parameter can take the following values ​​"up", "down", "both", "low", "high". Everything seems to be clear here. If your output is in state 1 and we lower it to the ground, it fires down, then it fires up when raised, but, to my regret, this did not happen, in the console I saw only down, depending on the speed of pressing the button, the event fired 1 or 2 times. I decided to put a cycle with a pause and break 1 on gpio.

For i=1,1000 do print(i) tmr.delay(10) tmr.wdclr() -- reset counter and prevent auto-reload end

But the pause did not work, and without a pause, the device went into reboot. But print(i) introduced a good delay. Made through tmr.alarm, but at the current moment there can be only one active cycle, which is not very suitable.

Function down() tmr.alarm(100, 1, function() timer = timer + 1 -- ok if gpio.read(9) == 1 then print(timer) tmr.stop() if timer< 20 then switch() else -- ... end timer = 0 end tmr.wdclr() end) end gpio.trig(9, "down", function (gp) if timer == 0 then timer = 1 down() end end)

HTTP server

The server starts up like 2 fingers, but you won't get any array of request parameters. It is not yet clear which is more optimal: either write your own bicycle, or find by substring. Agree, it looks terrible. In this example, 2 parameters are searched key and mode=off,on,party. The last mode is a simple flashing of a light bulb every 200ms, you can set it faster, but I was afraid for the light bulb and repulsed it.

Function HTTPd() print("start http serv") srv=net.createServer(net.TCP, 5) srv:listen(80,function(conn) conn:on("receive",function(conn,payload) print( payload) if string.find(payload, "key="..c_api_key) then msg = "key_ok" if string.find(payload,"mode=on") then on() else if string.find(payload,"mode =off") then tmr.stop() off() else if string.find(payload, "mode=party") then party(200) end end end else msg = "error_key" end conn:send("

mode=key="api_key"

") end) conn:on("sent",function(conn) conn:close() end) end) end

It is not so difficult to write a simple web interface, and place scripts and styles on external servers. From the module, take only the index page and communicate with it, for example, via json, so there will not be a big load and everything will fit into the file system, but we become dependent on the presence of the Internet.

Related Articles