One of my first home automation project was designed for the convenient use of two bedside lamps. The idea was that either occupant of the bed would be able to turn on or off both lamps without having to reach over someone who could be asleep or having to get out of bed and walk around it to turn off the lamp furthest away. This was by no means a new concept; I have seen this done in hotel rooms with four three-way switches. Because the bedside lamps were controlled by Sonoff Basic Wi-Fi switches, I implemented the idea in a different fashion. The following image shows how it was done back in 2017.
The now deprecated Sonoff-MQTT-OTA-Arduino firmware made it possible to control the Sonoff relay with GPIO14 of the ESP8266 microcontroller. I just added two normally open push buttons in parallel to that pin. The same could be done with the replacement firmware
Sonoff-Tasmota, now called Tasmota (see Updating Sonoff Switches with Local Controls from October 2017). Over the many months since that scheme was put into service, a couple of facts have emerged.
- The wired connections have not been reliable. Many times, too often to be honest, one of the bedside lamps would turn on without apparent reason. I have put this down to the length of the wires between the ESP8266 and each of the two buttons connected to the microcontroller's I/O pins.
- The home automation system has proven more reliable than anticipated and other devices that rely on it for primary operation have done better than this supposedly foolproof local control solution.
Futile attempts at solving the problem with the addition of R-C circuits and varying the button timing parameters were replaced with a new arrangement that has been running without a problem for a couple of months.
Without the long 2.3 metre Ethernet cable running across the bed between the two Sonoff switches, which was probably a sensitive antenna for all sorts of random electromagnetic emissions, there have been no false toggling of either bedside lamp.
The GPIO14 and ground connections are available on the programming header of the first revision of the Sonoff Basic. The connection to GPIO0 can be made by soldering a wire to one of the pins of the built-in tactile push button. I hot glued a female Dupont connector to the top of the board and drilled a slot in the upper half of the plastic case of the switch to allow a male Dupont connector through. Four-pin Dupont connectors were used to provide a key to ensure that the connectors were matched correctly. The N.C. receptacle is replaced with a filler on the female connector and there is no corresponding pin in the male connector. As far as I know, GPIO14 is not available in later revisions of the Sonoff Basic which is unfortunate.
The only interesting thing that remains to be discussed is the firmware running on the Sonoff. Version 9.1.0 of Theo Arend's excellent Tasmota is installed on the ESP8266. It is not the most recent version but it is what is on all the other similar devices in the house. The "clever" bit here is to modify the Sonoff Basic configuration, add a second button on GPIO14 and a corresponding non-existent relay on GPIO4. That second non-existent relay is needed to ensure that Tasmota does something with the button presses on GPIO14.
Here is the backlog command I use to quickly configure the Sonoff in the Web console.
Use that command as a guide, it will be necessary to adjust the various device names, the IP address of the MQTT broker and syslog server (if one wants remote error logging) as well as the Domoticz device index numbers (
When the extra button is pressed, Tasmota toggles the state of the fake relay and sends out an MQTT message that will be read by Domoticz. The latter will use that short message with the
domoticz/in topic to update the state of its virtual second bedside lamp to
On as shown below. Then Domoticz sends a longer message with the
domoticz/out topic reporting on the state of the second bedside lamp. This message is interpreted by Tasmota running on the second lamp's Sonoff switch as an instruction to close its relay and thus turn the bedside lamp on.
If there is no MQTT broker on the local network, this could be accomplished with HTTP messages (see commands
WebSend) using a rule (see Two-way light switches without MQTT).