UPDATE: Source code

I’m on holiday just now and one of my projects for my time off was to fix a fan. Well, not quite the fan, but its remote control (it’s some posh Dyson thing, bought on a whim but which has turned out to be great). Maisie chewed the remote, of course. She chews everything. She’s probably chewing something as we speak, if she’s awake.

The remote is a reasonable amount of money to replace, either from Dyson or somewhere like Amazon, and while that’d be fine, I always thought it’d be a prime candidate for voice control. It’s got the same limited range of adjustments as a Hue lightbulb — on, off and speed map well to on, off and brightness — and I control those with Alexa, via a set of Amazon Echoes.

So my task was to spend no more than the £15 or so I’d spend on the real thing, to duplicate its functionality and have it controlled by Alexa. I started with the obvious Raspberry Pi. I’d bought, on a whim with no real idea what to do with them, a pair of Raspberry Pi Zeroes. At £5 a go, even with the pound on the slide due to Brexit, I knew they’d come in handy for a project one day.

The Zero doesn’t have any way to talk to my home network, so I’d need some way of getting Ethernet onto it. Thankfully I have a nice USB Ethernet adaptor, that also brings 3 more normal USB 2.0 Type-A ports to the party. Sadly it’s only got a full-size Type-A connector at its end, whereas the Zero only has a single micro USB port to connect USB things to. I’d need an adaptor. Micro USB to full-size Type-A “On The Go” adaptors are cheap and cheerful though, and Amazon got one to me for a whole 90 pence!

I already had a mini HDMI to HDMI cable to plug the Zero in to set it up, so I thought I was finally off to the races. The Raspberry Pi folks have a version of Debian that supports the hardware and features of the Pi, called Raspbian, so it was a matter of downloading that, finding a suitable microSD card…ah, I don’t have one! Two minutes on Amazon later and one would arrive later that day for £3.99. Yay for same-day Amazon Prime.

OK, where was I? Ah yes, Raspbian. The website has a set of handy steps for how to get the Raspbian images onto your SD card no matter what operating system you’re using, so I followed that and had a bootable card for the Zero a small handful of minutes later. Ah, I’ve forgotten about power…no, it’s OK, the Zero powers over micro USB and like all good technology enthusiasts I have at least a million spare micro USB cables.

Plugging one in for power, the USB Ethernet hub thing into the other micro USB port, HDMI to see, and the keyboard and mouse from my PC, and the Zero booted first time, straight into a usable desktop environment, with a user called pi. You can guess what pi’s default password is.

With that pre-flight check complete and the Zero doing something useful, I got Raspbian up-to-date with the latest software packages and then started to think about the infra-red side. The great thing about the Raspberry Pi is the amount of broken-out general purpose I/O (GPIO) you get, plus power. That’s let a whole ecosystem of what the community calls hats to pop up (because it looks like your Pi is wearing a hat, of course!). Every Pi, including the tiny Zero, supports those pins. On the Zero you need to provide them yourself, though. I knew I’d need to connect whatever IR hardware I wanted to those pins.

So I raided my box of drone parts for the headers (I bought loads for flight controller work) and dug out my soldering iron — an absolutely fantastic Hakko FX888D, thanks Simon for recommending that! — and popped on a two-row pitch of 12 pins. I think that’s the right terminology in connector world at least.

Now all I needed was an IR transceiver to connect to the pins, preferably in standard Raspberry Pi hat form so I didn’t have to do any extra soldering. A couple of days prior (sorry for writing this bit out of order, I’m writing it stream of consciousness style) I’d run a quick DuckDuckGo search or two. The results told me that I wanted to use software called LIRC to handle recording and playback of the IR commands the Dyson remote emits. Searching for Raspberry Pi and LIRC showed a bunch of popular transceivers and what better way to choose one than by looking at what’s known to work.

I had roughly £5 left to spend, but the Energenie ENER314-IR that I wanted is was £9.99. Do I win my budget game or do I call it £5 spent on adding voice control to the fan? The latter. £9.99 later and the ENER314-IR showed up the next day. That means, with pins attached to the Zero, I was ready to go. My soldering skills aren’t the greatest, so the ENER314 needed the slightest amount of persuading to slide over the pins; my fault for not using the helping hands to hold everything straight. Lesson learned.

With LIRC setup properly, all I needed to do was run the irrecord part of the LIRC suite and have it watch me press all of the buttons on the remote over and over again. After a while, LIRC things it’s seen everything you can possibly send it. Then it asks you to press each button in turn and give it a label, outputting a configuration file for the remote that you can then drive with irsend. Simple!

irsend SEND_ONCE Dyson BTN_0 toggled the power. BTN_1 toggles the motion. BTNs 2 and 4 control the fan speed. Easy! Now to wrap that up in something the home automation proxy software I use, ha-bridge, can talk to. ha-bridge can call arbitrary URLs, or run arbitrary scripts, on receiving commands from Alexa, to control things that Alexa can’t control natively. It presents everything as if it was a Philips Hue lightbulb, so you get on, off and some control over intensity and brightness. That maps well to the Dyson fan’s controls.

I wrote a small web service that shells out to irsend directly using interned strings, so you can send it on, off, move and stop. No speed control yet because I haven’t figured out a good way to make that work in the confines of how you can talk to it with Alexa. It’s possible — Alexa has the concept of turning the brightness of a Hue bulb up or down — but I haven’t figured out how to wire it up yet because ha-bridge specialises the brightness/intensity commands. And I’m not sure how to do the movement control. Maybe by pretending to be a 2nd device.

Right now I can say, “Alexa, turn Dyson on” (or off!), and it works! Mission accomplished, with a tiny computer, some soldering, some IR spoofing, a little programming, and a little cheating to pretend to be a lightbulb so that Alexa is happy to play along, all for a little bit more money than the boring old remote that Maisie would probably chew again anyway.