Electronic – How do Shelly products detect button presses

esp8266iomains

I've been playing with home automation for a while now (mostly Sonoff) and recently discovered Shelly.cloud. I'm fascinated by the fact that most of their relays use a mains connected switches to interact with external inputs (see image below) – fascinatingly brilliant as this allows one to leverage existing wiring to retro-fit automation products into existing installations.

But how does it work (the switch part)?

These devices are based on the ESP8266EX (PDF) wi-fi microcontroller that uses 3.3V. This part I get – from what I can see on photos they use a AC-DC on-chip converter, the Shelly 1 (see FCC entry) uses a LNK304DN (PDF) to convert mains to 12V and then they bring that down to 3.3V somehow (I assume something similar to a PMP4536 (www)).

Having worked on ESP8266 I know that it has IO pins that one can use to measure either digital variance or pull-up or pull-down … but that's all in VCC (3.3V). How on earth is the external button press being detected? And this thing works in both power modes, i.e. 220VAC and 12VDC modes.

This question pertains specifically to the theory of how one would go about detecting a 220VAC ON state and translate that to signal that can be used in a 3.3VDC microcontroller (think in terms of the example of using an Arduino to detect if a light is on or off).

enter image description here

Another of their products (Shelly Dimmer) has two SW pins and from some close up photos each has a 240 kΩ resistor and then a S1M diode … but I can't see more from just the photo.

enter image description here

Best Answer

All they need is a pullup resistor to one of the internal power rails- +12 or +3.3V (and some protection/filter passives most likely).

No isolation is provided in the circuit, so the signal can go more-or-less directly into the MCU.

From here:

Do not connect AC power and the serial connection at the same time The GND connection of the Shelly is connected to the live AC wire. Connecting serial with your PC will fry your PC.

For this reason, the external switch should use wiring standards adequate for any other mains wiring.

Edit: Textbook circuit to the left (even R1 might be unnecessary if an internal MCU pullup is enabled). More robust circuit to the right. More protection is possible, such as TVS diodes and so on, there is no way to tell how solid their design is without taking it apart, but being an inexpensive consumer product probably not all that much.

schematic

simulate this circuit – Schematic created using CircuitLab

The N is one side of the 110/230V power source and the internally derived power supplies are relative to that N. Probably they are using half-wave rectified AC for the flyback supply to keep the N common with the input power. Guess:

schematic

simulate this circuit

Related Topic