3

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

Vino
  • 141
  • 6
  • We're missing the links to the datasheet and the other devices you've mentioned. What do terminals 0 and 1 do? Hit the [edit] link ... – Transistor Sep 27 '20 at 21:10
  • I will edit the question to make clear my question. Also, terminals I and O are just the output ends of a relay. – Vino Sep 27 '20 at 21:30

3 Answers3

3

I don't know the internal circuitry of the product given in the question, but I almost always use resistor-diode-capacitor configuration for 110V/220V input detections. Here is an example for a non-isolated (i.e. L or N serves as DC ground) configurations:

schematic

simulate this circuit – Schematic created using CircuitLab

This is a half-wave rectifier: D1 conducts only at the positive half cycles of the input sine. R1 drops some voltage and limits the current drawn from the Line. C1 is charged (through R1 and D1) to some DC voltage (with some ripple of course, due to the half-wave rectification). This voltage drives Q1's base through R2. Normally Q1 is off, thus GPIO is at VDD level. So when the Q1 is on, GPIO will see 0V. Of course, the transistor configuration can be modified so that the input can be logic-low initially (and can be logic-high when there's a 220V input).

Using a half-wave rectifier is a very efficient way of detecting 110/220V inputs because the components count is quite low. But it's not that efficient in terms of power consumption because R1 is a very dissipative element here. In the example above, the voltage across R1 can be as high as 150Vrms which results in around 100mW.

Rohat Kılıç
  • 26,954
  • 3
  • 25
  • 67
  • Replace R1 with a capacitor dropper, and a diode with anode to ground and katode to anode of D1 – Lenne Feb 09 '21 at 22:25
2

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

Spehro Pefhany
  • 376,485
  • 21
  • 320
  • 842
  • Thank you for your answer, and I can assume that my question is not clear (so I will edit it). I'm specifically looking for the electronics theory around detecting the state of the SW line on the shelly and how that drives an IO pin on the microcontroller. – Vino Sep 27 '20 at 21:32
  • Electronics theory of a pullup resistor? – Spehro Pefhany Sep 27 '20 at 21:33
  • No - the theory of how to detect a 220VAC ON state for a 3.3VDC microcontroller. And I know about non-invasive current sensor (also known as a “split core current transformer”) ... but the Shelly doesn't have one ... so how do they do it? – Vino Sep 27 '20 at 21:44
  • There are a number of ways to measure current. I don't know which one they've used. Shunt, tiny CT (does not have to be 'split'), Hall sensor near a conductor. – Spehro Pefhany Sep 27 '20 at 22:09
  • I think you may be close - see my further edits about a diode and a resistor. But I don't see a flyback anywhere :( – Vino Sep 27 '20 at 22:18
  • Actually it's a simple buck converter, based on the chip number you mentioned. You'll find a large-ish inductor. – Spehro Pefhany Sep 27 '20 at 22:23
  • I don't see a flyback, transformers, or any* coils anywhere. (There is an inductor, but not near the SW circuit, and I assume its for voltage regulation from the LNK304DN (thats the "buck" that transforms the 220VAC to 12VDC). This one confounds me, I know all about AC current detection, but this thing also detects DC switches. (The Shelly can operate in either 220VAC or 12VDC mode.) – Vino Sep 27 '20 at 22:27
  • This is really far beyond the scope of your original question. Seems like you want to reverse-engineer their design which will require some effort to trace out the circuit. – Spehro Pefhany Sep 27 '20 at 22:29
  • I can reverse engineer if I wanted ... but this is not the case. I'm just really curious about how that switch circuit works. Your answers are absolutely great and for others coming across this question will derive significant value from your answers. (So I will up-vote.) – Vino Sep 27 '20 at 22:37
1

Been thinking on this and have come to a conclusion: Looking at some of the recommended installation circuits - specifically the 12V installation - and one can see that in the 12V mode the switch is connected to the Negative line.

Looking at the photos, there is a resistor (2403 = 240kΩ) and a diode (S1M = Glass Passivated Rectifier Diode with 1000V peak reverse voltage) with the cathode band facing the resistor and the SW pin.

I also read somewhere (and also in Spehro Pefhany's answer) that the internal GND is directly coupled to the AC line (or one of them).

I'm thus inclined to assume that this is indeed a PULL DOWN RESISTOR (but not in the traditional way, rather this thing has the switch on the ground-side of the pulldown resistor) configuration with the Diode providing a positive Sine Cycle block and the negative cycle allowing the pull down to occur. How smart is that!! Hope someone can confirm my assumptions with a simple theory example.

Vino
  • 141
  • 6