Like most makers, my home is automated - not with off-the-shelf IoT devices, but with home-built switches and relays, Raspberry Pis and ESPs.
My first remote switches - all controlled through ESP8266 01s- were mostly built with Blynk. I'd contentedly call up the app on my phone and tap things on and off.
This was fine until the emergence of voice assistants like Alexa and Google Home. Now, I was no longer satisfied with the Blynk app. Instead, I wanted Google to do the job at my verbal command.
This required a bit of engineering. I'd need to use a combination of Blynk, IFTTT, and Google Assistant to achieve it. It worked fine for a while. I blogged about it here.
The Dreaded STT
Before I continue, we really need to talk about the elephant in makers' collective rooms. We are all very familiar with the Spouse Tolerance Threshold - the point over which we must never roam, lest our wires, connectors, and improvisations be banished forever from the family abode. (I've been informed more than once, that if my wires have to go, I'll probably have to join them.)
I, like so many of us, have been living on the cusp of the STT for as long as I can remember. Over the years I've learnt that this threshold is dynamic - moving up and down in direct correlation to whether my devices continue to function or not. Unfortunately, as we're talking about home-made gadgets, I tend to teeter on the edge of the abyss.
Then Google Screwed Me
One of my favorite Blynk/ESP switches is attached to the reading light above the matrimonial bed. At the command, "Reading Light Off" we're plunged into darkness without the need to interrupt our semi-conscious state to stretch up to flick the switch. Significant Other grew accustomed to my nightly mantra, even participating herself when I'd fallen into premature slumber.
But then the calamity happened. For some spurious "security" reason, Google decided that its connection to IFTTT would only work for the voice of the principal account holder. In other words, Significant Other could no longer turn our Reading Light on or off!
"Get that bloody thing fixed or get it out of here," was the general drift of what I heard.
IKEA?
I stalled. As far as I was concerned, the voice-controlled reading light was an essential part of my automation armory. How could I placate Significant Other without upsetting my digital karma?
It was while I was scouring the IKEA website, seriously considering a Tradfri bulb, that my eyes fell on the ThingsonEdge Cricket that has adorned my desk - in test mode - for several weeks.
"Wait a minute," I thought, "why buy an IKEA remote bulb when I can just as easily rig up a remote switch with the Cricket that will work with my existing Blynk relay?" The Cricket is an easy board to work with and with its power management, the battery would last for years.
When I first thought of the idea, I didn't really know how to do it - but isn't that the essence of a maker's soul?
Cricket, Node Red, & MQTT
I'm not going to explain much about the Cricket here. I've blogged about it before. In short, with just two wires, a momentary push-button switch, and a couple of AA batteries, I had the hardware constructed literally (no, not figuratively - l i t e r a l l y ) in three minutes.
But how to get the Cricket to talk to the Reading Light?
I could dismantle and re-flash the ESP8266 that controls the Blynk relay. That would mean taking it off the wall, opening the box, pulling it all apart, installing an MQTT script, then putting it all together again.
Mindful of Significant Other's watchful eye, disruption had to be minimized. Perhaps there would be a way of doing it without producing more dust in the bedroom? Maybe even, without touching the Blynk setup?
This is where Node Red and MQTT came in.
My home automation revolves around Node Red running on a Raspberry Pi. I have plugins (pallets) for almost everything - including the Blynk API. I already turn Blynk ESPs on and off to control my garden lights through Node Red. Integrating the Cricket would be just another step.
The Cricket is great for MQTT and all I needed to do, was connect its wake_up, through MQTT, to the Blynk relay.
With Node Red, nothing can be simpler. The only problem I encountered was getting the light to toggle on an off with successive presses of the button. This was achieved with the help of the Node Red forums. (See below for the Flow Code).
Boxing it up
Another bane in the life of the maker's spouse is the 3d-printed plastic boxes spread throughout their living space. To us, the aesthetics are unquestionable. Alas, their eyes is a little more discerning.
Thus, for the special gift of reinstated control of her Reading Light, a visit to the craft store rendered a tasteful wooden box, replete with dainty (not!) hooked fastener. The box, just large enough for the Cricket and two AAs, would be easily drilled for the push-button switch.
(Well, I did make a mistake when drilling the hole, but that was soon repaired).
But labelling would be a problem. Adhesive from my machine wouldn't stick to the coarse wood, and felt-tip ink would smudge. There was nothing else for it - it would have to be PLA.
A Happy Spouse
Well, I wouldn't say she's entirely happy, but my banishment is on hold. My little Cricket box has done the job; it lies next to her pillow and obeys her every press. We are in reprieve - at least until the next automation crisis.
Node Red Flow
Node Red flow code. One press of the button turns on. The next off, and so on...
[{"id":"7347b78.8b23848","type":"switch","z":"38820a4e.6bd416","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":800,"wires":[["82ff5a1a.efefc8"],["26637948.29d256"]]},{"id":"82ff5a1a.efefc8","type":"change","z":"38820a4e.6bd416","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"str"},{"t":"set","p":"next","pt":"flow","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":780,"wires":[["72e68b7b.5cf8c4"]]},{"id":"26637948.29d256","type":"change","z":"38820a4e.6bd416","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"},{"t":"set","p":"next","pt":"flow","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":820,"wires":[["72e68b7b.5cf8c4"]]},{"id":"5047f5ea.66c1ec","type":"function","z":"38820a4e.6bd416","name":"get next value","func":"msg.payload = flow.get(\"next\")||0;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":300,"y":800,"wires":[["7347b78.8b23848"]]}]