Check a Sonoff Basic R2 via a button or an external switch

6 minutes of reading
Purposes of projet:
  • Check a switch Sonoff Basic R2 through the use of an external switch or button, also in deviation (via buttons)
  • Difficulty level: medium
  • Cost: did
Concepts dealt with:
  • Electric device modification
Software components used:
Physical devices used:
Procasting more suitable for:

All environments

Notes and disclaimer
  • qualsiasi modifica all'impianto elettrico dev'essere progettata ed effettuata da personale qualificato;
  • any changes implemented in probefore is a propersonal responsibility as well as a profirst risk and danger (the contents of the present page are purely educational);
  • any changes implemented in proprior to a device it voids the guarantee, quality approvals and certifications.
Driving review: 1.0

CAUTION: this guide appgranted to the R1 model is available here.

Abstract

The smart switches of the family ITEAD Sonoff Smart Home they are extremely versatile, very economical and functional domotic components, but when it comes to integrating them in existing systems may, sometimes, rappresent a proproblem, especially in the presence of one or more diverters.

This is the case of the transformation of a light point (or of a more generic user) controlled by a traditional wall switch into a home automation element: we want to keep it manual, mechanical, integrating the home automation one.

Switch-traditional-to-wall

There are more alternatives.

THE FIRST

The first alternative - the simplest one - is to replace the entire wall element with a home automation touch switch, for example theITEAD Sonoff T1, which will provide both the "mechanical" functionality (in contact), both the home automation one. Specifically in the example, since it is a Sonoff will be reprogrammable with firmware Sonoff-Tasmota, therefore configurable by our loved ones HUB personal and therefore with our personal home automation.

THE SECOND

A second alternative is to add a domotic element to the mechanical switch to "domotize it". In this case the choice of this element must be made with criteria, especially if they are used for profirst personal domotics of the HUB personal (compatibility with them must be guaranteed).

THE THIRD

A third alternative is to directly connect a button on the electronics of the Sonoff Basic.
Il Sonoff Basic already presents on propria board a button for activation and deactivation relay manual. The pressure of this button comes out when opening or closing the relay based on the pre-existing status. Essentially closes if it was before open, is opens if it was before closed: they are called function, in English, TOGGLE.

Wanting to use the Sonoff without any software modification, the only way to command "esternamethe "function"namethat's it to connect in parallel the two contacts of a traditional button (mechanical, wall) to the two contacts present on the button on the board of Sonoff Basic. This will practically replace the button on the actuator with an external one.

THE FOURTH - OBJECT OF THIS GUIDE

The fourth street, the one that prolet's say in this guide, is that of modify the firmware of the Sonoff Basic in order to (among many other things) enable and be able to use the pitches (one, specifically, that "in the factory" is not enabled) present on the board and so you can attest one or more buttons, or a classic mechanical switch, thanks to the features guaranteed by the firmware.
No fear: we explain everything in the following paragraph.


First di profollow over, we remind you again that:

Notes and disclaimer
  • qualsiasi modifica all'impianto elettrico dev'essere progettata ed effettuata da personale qualificato;
  • any changes implemented in probefore is a propersonal responsibility as well as a profirst risk and danger (the contents of the present page are purely educational);
  • any changes implemented in proprior to a device it voids the guarantee, quality approvals and certifications.

Description of the change

We therefore pursue this guide on the fourth street.

Il Sonoff Basic R2 (but also the other components of the same line prodotto) presents a series of contacts on the board. The ones we are interested in are the GND and l 'RX (which corresponds to the logical pin GPIO3).

Sonoff-Basic-RF-R2-POWER-V1.0-Retro - RX and GRN contacts
the contacts seen from the back of the unit.

Usually GND, TX, RX (GPIO3) and 3.3V (VCC) are used for the riprofirmware weight; that's why for this projet will recommend to weld pins on the four contacts: so as to be able to reproprogram the firmware, and check - subsequently - the behavior of the unit used GPIO3 (RX) e GND.

To ensure that the couple of contacts GPIO3 e GND can be used for the purpose, it's necessary the adoption of an alternative firmware, specifically the Sonoff-Tasmota. The guide takes this firmware for granted.

In the presence of such firmware, when the contact GPIO3 is briefly short-circuited with GND, the action cause opening or closing the relay based on the pre-existing status. Essentially closes if it was before open, is opens if it was before closed: the TOGGLE above which is usually performed using the factory button on the board.

Nb There's a ma.
We appena explained that the Sonoff Basic R2 (equipped with firmware Sonoff-Tasmota) change status (open / closed) when the GPIO3 and the GRD are short-circuited. To change status again, it is necessary remove the short circuit e appsell it again.This is the behavior offered by a button (or button), NOT a switch (mechanical, wall-mounted) which has two mechanical states (closed and open) which yes prothey draw in time (until the next mechanical state change). In essence, with the modification to the electrical scheme we are proplacing, to manually control the TOGGLE of status it would be necessary to set the switch (mechanical, from the wall) to the off / on / off position. Such an annoying situation it is easily solved, as follows.
Nota per smanettoni.
Unlike the board model R1, on the R2 there is no "traditional" pines GPIO14. Instead, there is a new pin called IO2: if short-circuited with GND, the action activates the relay. It is in practice the same contact welded to the button on board. It goes without saying that it is possible to use the couple IO2 - GND to sign on a foreign button without the need, therefore, to update the firmware. We have created this guide indicating only the use of the pair GPIO3 - GND for use both with button and switch (in association with the firmware Tasmota) for pure simplicity, but it is obvious that if you want to install only an external button the road can even be the one to use IO2 - GND without any firmware modification.
Solution

It will be possible to leave it unchanged the presence of the switch (mechanical, wall-mounted), which will act (at each change of state, regardless of whether it is the closing or opening of the contact between GPIO3 and GRD) How TOGGLE thanks to the use of the command Tasmota "SWITCHMODE”Duly configured.

Obviously there will be no mechanical position of the switch apt to indicate the functional statusnameof the Sonoff (relay closed or open). Each actuation of the switch will cause a change of state of the relay, end.

Get contacts

The most complex part, if you are not familiar with welding, is profirst this: have contacts through which to connect the button / switch to GPIO3 and GND.

First of all it is necessary to have connectors male pins e of female pins with thread.

PIN male
detail of male PINs.

Weld these pins (4) on the board at the pitches, taking care to place the shortest segment on the board. Once the welding is done, we will have contacts on which to position ourselves for the modification to the wiring diagram (we will use the female pins to connect to contacts of the button or switch).

Use of a button

This road involves the use of a Sonoff Basic and the replacement of the pre-existing switch with a button (in the illustrated case of type "Normally Open“).

Let's see the initial wiring diagram:

Switch-load diagram

And how becomes:

Button Scheme - Sonoff. - GPIO3

Once implemented this change, the work is completed.

To make the change work, however, it is necessary to implement:

  • su Sonoff Basic with original firmware: nothing, it works by itself;
  • su Sonoff Basic riprogrammato with firmware Tasmota: appuse the command "SWITCHMODE"

In the second case, the command is as follows:

cmnd/Sonoff/SwitchMode 3

which will interpret the short closing of the GPIO3-GRD contact (implemented via a button) as "change of status compared to the current one"

In case you use a button "Normally Closed", The command will be:

cmnd/Sonoff/SwitchMode 4

This is done by pressing / releasing the button will be implemented TOGGLE of the relay status of the Sonoff (turns off if on, turns on if off); at the same time, the same command can be implemented at home automation. Obviously if the Sonoff be controlled manually, the new state will be correctly detected inside the home automation practically instantly.

In the following video you can see the behavior of the circuit thus conceived:

Nb Use of one or more buttons such as "diverters" it's possible, but only:

  • using appgrease buttons, and no switches;
  • by connecting the contacts of all these buttons on the GPIO3 and GROUND contacts of the Sonoff Basic.

By doing this, pressing any of the buttons connected to the Sonoff will control its behavior.

Use of a switch

If you decide, instead, to leave it at home switch pre-existing, then the scheme will be the following:

Scheme - Switch - Sonoff - GPIO3

As said, for a correct functionnameof the circuit and manual activation will be necessary, primarily, the presence of the firmware Tasmota, this because, as widely explained, only in the presence of Sonoff-Tasmota it will be possible to implement a configuration that allows interpretation each change of state (any!) of the switch as TOGGLE.

Performed the highernamefirmware and wired the circuit as above, you will need to set it from the console Tasmota the following command (it is assumed that the device has a name "Sonoff"):

cmnd/Sonoff/SwitchMode 1

which will prepare the closing or opening of the short GPIO3-GRD as "change of status compared to the current one". For the rest (home automation control, state change detection in home automation etc.) the same considerations made in the example related to the button will be valid.

Lastly, it is necessary to indicate to the firmware Sonoff-Tasmota what is the use of the GPIO3 pin, in our case "switch". To do this, go to Configuration / Module Configuration (Configuration / Module Configuration) of the web interface under the heading "GPIO3 Sensor", Select the item"01 Switch". Finally click on "SAVE"

Now the actuator will act as intended.

Add an MQTT switch to the configuration Home Assistant


ITEAD Sonoff BasicATTENZIONE: remember that there is on our FORUM community an ad hoc section dedicated to Sonoff (and more generally to devices ESP8266), for any doubt, question, information on the specific merit of these components.


Please comment below