Coming Out of My Shelly With Home Automation
As is tradition, I first have to point out the infrequency of my posts. I stand in awe of those who manage a consistent weekly output. Now, some of you may be skittish and disbelieving, but I hope to actually pulp out a few of these this week to talk about further home automation stuff.
Maybe even touch on some of the stuff I vaguely vagued at this post. It’s the partial end times, anything could happen.
To sort of guide you and mentally prepare you for the word goulash that lies ahead, I am planning to do a bit of a deep dive on the Shelly series of IoT devices as the main informative meat of this post. Along the journey I will be lightly touching on the following topics:
- Sonoff IoT - They’re fine. Just okay really.
- Apple HomeKit - I’m a sucker for low friction interfaces.
- Homebridge - Certified HomeKit stuff? Who am I, an oligarch?
- Automation - Remotes are pretty cool, but getting stuff to do it automatically? More like automagical.
If you want to skip the fluff and head straight to my vivisection of the Shelly you can find it under “Shucking the Shelly”.
The Overly Optimistic Start
When we bought our new house I had a bold vision for automation and convenience the likes not seen since before the French revolution. After buying a few Sonoff devices as showcased in my human hands below, reality asserted itself quite rapidly. To put it mildly, the wiring in my old house had about the same functional integrity as jelly worms would have for suspension bridge cables. Also money, Capitalism™ strikes again.
Now, the Sonoff devices aren’t really that bad to start with, they are cheap and readily available, but there were three serious pitfall for my planned use. These days I’ve removed almost all of these from my home in various fits of rage and crushing ennui.
I can’t very well just blame a plain ol’ ESP8266 and a relay for making me unreasonable, and truth is there is nothing (much) wrong with the hardware. Rather the software is simply a bit shit lacking.
So, the standard app for controlling the Sonoff’s is eWeLink, something which by name alone was not marketed to people with my puntential. If you want to do basic control of a device such as timers, remote control, and scheduling, you can do it all within the app. For integration into other automation, things seem a bit more difficult, not to mention slow.
The Sonoff devices appear perfectly happy to keep communicating back to the mothership (wherever it may be) before taking remote action. These delays, while brief in the context of geological epochs, are tangible and mildly grating.
Perhaps I have some overly aggresive network partitioning to blame, but can you blame a fella for the security risk that cloud interacting IoT devices have? I mean, I’m sure all of you review the forty thousand lines of C and Assembly code for each open source ESP firmware project.
Now, those three pitfalls I mentioned earlier:
- They can only handle 10A, making them suitable for lighting circuits at best (may vary by jurisdiction).
- For the MINI devices, their switch sense lines use logic level inputs. This does not work great at all with normal wall switches. Why keep normal wall switches? It’s a matter of taste.
- While open source firmware such as esp-homekit exists, the flashing process is positively barbaric compared to the Shelly devices
Before I espouse my current darling that is Shelly, let’s talk about the automation infrastructure I’m currently gelling with.
Pomme MaisonFourbi et al
These days I have an iPhone, an Apple TV, and
an M1 Air a broken Fatbook Slow. So HomeKit was a natural first choice as the framework within which to restart my home automation journey.
Now, despite being a Mac user since 2013, I was always very hesistant to merge deeper into the Apple ecosystem. A certain snoody elitism and walled garden that was presented with their services just rubbed me up the wrong way when I was young and full of hot blood. Nowadays I like to practice digital realpolitik while yearning for simpler times. Life is less stressful not having to explain to your significant other that they can’t open the gate because an SSH cert expired and a rogue cronjob switched the geyser 2000 times yesterday and wore out the contactor.
HomeKit is a pretty good choice if your automations are relatively simple, and when non-techies need to also experience digital hedonism. Using the delightful Homebridge gives access to all manner of interesting devices without requiring first party HomeKit support or even flashing a HomeKit friendly firmware. With a little config you get a nice lightweight and locally running instance to connect all those cheep and cheerful IoT thingamajigs to your shiny Apple devices. I leave you a tantalising screenshot for the future blog post
I’ll totally forget about.
That said, Homebridge doesn’t really provide any automation options within itself when you want to do more complex actions. You are still dependant on the frankly obtuse Apple scripting options, if you can even find them. Maybe I’m just afflicted by the olds in this case, but it’s a good idea to look at options such as Home Assistant to do the more complex interactions.
Shucking the Shelly
The main event! This will be focussed on the Shelly 1, which by my exhaustive 4 minute research appears to be the first device made by the company. It certainly is a svelte little device, and all while supporting switching of full 16A loads!
As with most of these devices it’s an ESP8266 with a relay bolted on. What makes the Shelly particularly interesting compared to it’s competitors are:
- Wide input voltage support (DC and AC)
- SW pin magic??
- Like, really nice firmware and flashing
Now, the SW pin in most application notes of the Shelly don’t really say what signalling voltage it’s using, and it has two fascinating use cases depending on whether it’s being used in AC or DC modes. In AC mode the external switch is wired up to live and some sensing occurs on the SW pin. In DC mode we wire up to the negative rail and pull the pin low. What.
Let’s do some testing starting at 12V DC operation. Do take careful note of how under DC you connect negative to the L terminal and vice-a-versa. If you reverse your DC polarity the Shelly will release the magic blue smoke, but no one would do that while connected to a current limiting PSU with current limiting off. Right? Not speaking from experience or anything.
I’ve not done too much circuit analysis, since it’s tiny and has a multilayer board. Maybe I’ll sacrifice one for full dissassembly in the future.
Some quick playing around shows that the Shelly web interface remains stable down to between 7-8V, I would expect a bit lower considering the ESPs standard operating voltage of 3.3V, they certainly don’t seem to be using a low dropout regulator. While you can switch the relay at these trickles of electromotive force, the force bit isn’t really there, so don’t expect reliable operation. Pushing up to 15V or so seems to have no poor effects, this is the highest you’re likely to encounter in 12V nominal systems.
Across this full voltage sweep the voltage on pin SW stayed locked at around 3 volts, with only slow drift noted in the output voltage. The Shelly itself seems to happily read the input as closed anywhere from dead short to 100kOhm (the highest value resistor I found in arm’s reach) between the pin and negative. I can’t seem to find the reference now, but I recall reading that pulling SW low causes one of the GPIO pins on the Shelly to be pulled high, so definitely an interesting circuit here to explore later.
Let’s jump up to 24V operation and switch that jumper over. Quite anticlimactically, SW voltage stays right at 3V. My bench PSU maxes out at 31.5V, and up to that there is no appreciable difference in SW voltage. They must be reusing the same AC voltage circuitry with DC in this case, though then I don’t really see why they insist on limiting DC to 50V. Your currents are going to be lower at higher voltages, so not like your input diodes or whatever are going to be MORE stressed at higher DC voltages. Speculation without circuit analysis and my approximate knowledge of electronics would only be increasing entropy at this point.
Anyway, when dealing with simple NO/NC switches, none of this really matters, they’ll sink whatever voltage as long as there is not too much current, and by all indications SW acts as a high impedance source in this case. For more complex use case (wait for the next post) this is important information to have going forward.
Alas, I don’t quite have the requisite bits or moxie to test at line voltages right now, but I will definitely be doing so in the near future.
That’s it for the hardware. I would love to show you a screenshot of the stock firmware, but alas I’ve flashed all my devices to the excellent shelly-homekit firmware. Suffice to say, the stock firmware allows full setup and control from the local web UI, no need to to sign up for anything or any cloud connections. Not even for firmware updates! As for flashing other firmware, it’s comically easy. To flash the HomeKit firmware it’s a one liner you can do from any web browser. Behold:
Ain’t that a thing of beauty to end this post with? But wait, a quick teaser of what this looks like in HomeKit now….