Controlling Devices with the Flic of a Button
Using Flic buttons to control hundreds of smart devices in my home without a phone, and why it matters.
This is part of a 2-part series. You can find the other part here:
RxJS and the Observable Flic Button
Ever since I moved into a house, I’ve been really big on home automation. I have hundreds of connected devices and needed to find a way to control my connected lights, specifically the Wi-Fi LIFX models. Phones are powerful but inconvenient to use as home automation controllers, and voice activation is really nice only when nothing else is making noise. I need a physical switch, something to replace my wall switches that allows for enough programmability I won’t have to depend on that company if I wanna use a product they don’t support.
You might be wondering why I couldn’t just use the light switches already in the walls. The problem with those and any other wireless wall switches is they physically disconnect the power going through the lines when the switch is off. This means all ceiling lights and lamps connected to the Internet lose access. At that point, no phone or voice system is going to work. I needed a separate physical switch, maybe a remote control, but preferably something I could stick on walls, under counter-tops, night stands, etc.
My solution, the Flic button. This wonderful 1 inch Bluetooth button comes out-of-the-box with a slick looking phone app and the ability to control just about every major IoT (Internet of Things) device as well as apps on your phone. Better than that, they even allow you to program double-press and press-and-hold actions!
But there wouldn’t be a need to write about them if there wasn’t some quirk. To do anything, they need to be in range of a mobile phone, and you need to have Bluetooth and the Flic app always running. Not only that, to configure each button, you need to do it once for each press type once per button per phone. In my case, that’s 2 phones, 3 press types, and 35 buttons equaling to 210 combinations I need to slowly configure one-by-one on both my and my wife’s phones. Not gonna happen. No way José!
Worse yet, family members and guests won’t be able to control the buttons unless one of the two phones is in-range. This sounds like a terrible solution.
You might think my best option now is to go with the Logitech POP, but those had so many other issues. They were completely unusable not to mention twice the price even when purchased in bulk. They also didn’t have any way for me to program them independently of their software. IFTTT integration doesn’t cut it either since that means programming over a hundred actions to use IFTTT in the Logitech POP app then programming over 100 IFTTT applets to utilize those actions.
So what’s the solution? Switch to Philips Hue? No. I’m a programmer so this is just a matter of code. Flic, specifically their Flic SDK, ended up being my saving grace.
Architecting a Solution
With the Flic SDK, I set out to design a system that would allow me to control all my IoT devices from anywhere in the house no matter the type of device.
I settled on using the Raspberry Pi 3 as I’ll be writing all my apps in Node.js. They’ve also got a huge developer community. If you’re wondering why I’ve not considered Arduino, those are primarily for programming directly to I/O and controlling specific hardware devices with physical connections. It’s completely different to running a home automation client library that multicasts UDP packets.
Writing the controller software was simple enough. To start, I created one for the LIFX lights and another for WeMo devices. There are already packages on npm with the right connections so all I had to do was write some software to use ’em. With a quad core, the Raspberry Pi 3 is really fast. It ran my Node.js instances no problem. Since they’re not exposed to the Internet, I didn’t even add any authentication although the Passport library would’ve made that dead simple.
Now that I have half the problem solved, I needed to solve the Flic portion. To use the Flic SDK, I need to pair the buttons to my Raspberry Pi. Problem is, it only supports up to 10 active Bluetooth devices at a time even though the chip supports up to 128 pairings total. Anything past 10, and you’ll start experiencing really strange pairing issues. With 35 buttons, that means I need 4 Raspberry Pis.
If you’re wondering why I didn’t just buy a Flic Hub, that’s because they didn’t and still don’t exist yet. Also, I need a Raspberry Pi to run the controller software for all the other devices.
My Custom Flic Controller
Before I purchased 34 of the 35 buttons, Flic actually sent me one for free so I could test out controlling it with a Raspberry Pi. Little did I know the Ubuntu Bluetooth drivers didn’t work properly so I had to switch over to Raspbian. Doing everything in the command line anyway, I really should’ve gone this route in the first place. It was as simple as writing an image file to a microSD card and putting it in the Raspberry Pi. The Bluetooth pairing worked on my first try!
With the button was paired, I pulled in the Node.js library and started messing around. It wasn’t long until I had a working prototype. Now it was time to sink a bunch of cash into some really expensive Bluetooth buttons.
Cost becomes an issue as you buy more and more items in bulk. To lower this particular cost, I went with three of the single-core Raspberry Pi Zero W. They’re noticeably slower than the Raspberry Pi 3, but they only need to run the Node.js Flic controller and the Flic SDK; that’s it. They don’t even need an active webserver. Since they’ve got Wi-Fi, all I needed was a microUSB cable and USB power, and I can put them wherever I want to get good coverage.
After I got everything setup, I had to run the Flic SDK and pair each button individually making note of the color, the Bluetooth address, and the location of each button along with the possible functions I wanted for each one. Needless to say, I ended up changing these multiple times until I found the right fit. Unpairing buttons requires turning off the paired Raspberry Pi and holding the button for ten seconds while pairing it to another Raspberry Pi hoping it’s gonna work the first time.
With the data I collected, I created a button configuration and setup the Node.js Flic controller software to listen for button presses and make web requests to the Raspberry Pi 3 running LIFX and WeMo controllers.
I finally have a working solution, a physical button I can stick anywhere in the house, to control not just my lights and lamps, but my computer speakers, garbage disposal, garage door, wax warmers, you name it! The power of HTTP and Node.js is really universal :D.
Check out the complimentary article on rewriting the Flic button press listener to improve the speed of button presses and add new features like double-press-and-hold and triple-press:
Flic Buttons and the Observable Customization using RxJS
If you’re like to find out more about the Flic Controller software I used, you can find it and other home automation tools on my GitHub account: https://github.com/Sawtaytoes/Flic-Controller