Milk and Mail Notifications with Flic 2 Buttons

I’ve been playing with a Flic Hub LR and some Flic 2 buttons. They’re “smart home” buttons, but for me they’ve got a killer selling point: rather than locking you in to any particular cloud provider (although you can do this if you want), you can directly program the hub. This means you can produce smart integrations that run completely within the walls of your house.

Here’s some things I’ve been building:

Prerequisite: Flic Hub to Huginn connection

Screenshot showing the location of the enabled "Hub SDK web access open" setting in the Flic Hub settings page of the Flic app.
Step 1. Enable SDK access. Check!

I run a Huginn instance on our household NAS. If you’ve not come across it before, Huginn is a bit like an open-source IFTTT: it’s got a steep learning curve, but it’s incredibly powerful for automation tasks. The first step, then, was to set up my Flic Hub LR to talk to Huginn.

Screenshot showing the Flic Hub SDK open in Firefox. Three modules are loaded: "IR Recorder", "UDP to IR Blaster", and "The Green", the latter of which is open. "The Green" shows JavaScript code to listen for 'buttonSingleOrDoubleClickOrHold' events then transmits them as HTTP POST requests to a 'webHook' URL.
Checking ‘Restart after crash’ seems to help ensure that the script re-launches after e.g. a power cut. Need the script?

This was pretty simple: all I had to do was switch on “Hub SDK web access open” for the hub using the Flic app, then use the the web SDK to add this script to the hub. Now whenever a button was clicked, double-clicked, or held down, my Huginn installation would receive a webhook ping.

Flow chart showing a Flic 2 button sending a Bluetooth 5 LE message to a Flic Hub LR, which sends a Webook notification to Huginn (depicted as a raven wearing a headset), which sends a message to an unidentified Internet Of Things device, "probably" over HTTPS.
Depending on what you have Huginn do “next”, this kind of set-up works completely independently of “the cloud”. (Your raven can fly into the clouds if you really want.)

For convenience, I have all button-presses sent to the same Webhook, and use Trigger Agents to differentiate between buttons and press-types. This means I can re-use functionality within Huginn, e.g. having both a button press and some other input trigger a particular action.

You’ve Got Mail!

By our front door, we have “in trays” for each of Ruth, JTA and I, as well as one for the bits of Three Rings‘ post that come to our house. Sometimes post sits in the in-trays for a long time because people don’t think to check them, or don’t know that something new’s been added.

I configured Huginn with a Trigger Agent to receive events from my webhook and filter down to just single clicks on specific buttons. The events emitted by these triggers are used to notify in-tray owners.

Annotated screenshot showing a Huginn Trigger Agent called "Flic Button C (Double) Details". Annotations show that: (1) "C" is the button name and that I label my buttons with letters. (2) "Double" is the kind of click I'm filtering for. (3) The event source for the trigger is a webhook called "Flic Buttons" whose URL I gave to my Flic Hub. (4) The event receiver for my Trigger Agent is called "Dan's In-Tray (Double) to Slack", which is a Slack Agent, but could easily be something more-sophisticated. (5) The first filter rule uses path: bdaddr, type: field==value, and a value equal to the MAC address of the button; this filters to events from only the specified button. (6) The second filter rule uses path: isDoubleClick, type: field==value, and value: true; this filters to events of type isDoubleClick only and not of types isSingleClick or isHold.
Once you’ve made three events for your first button, you can copy-paste from then on.

In my case, I’ve got pings being sent to mail recipients via Slack, but I could equally well be integrating to other (or additional) endpoints or even performing some conditional logic: e.g. if it’s during normal waking hours, send a Pushbullet notification to the recipient’s phone, otherwise send a message to an Arduino to turn on an LED strip along the top of the recipient’s in-tray.

I’m keeping it simple for now. I track three kinds of events (click = “post in your in-tray”, double-click = “I’ve cleared my in-tray”, hold = “parcel wouldn’t fit in your in-tray: look elsewhere for it”) and don’t do anything smarter than send notifications. But I think it’d be interesting to e.g. have a counter running so I could get a daily reminder (“There are 4 items in your in-tray.”) if I don’t touch them for a while, or something?

Remember the Milk!

Following the same principle, and with the hope that the Flic buttons are weatherproof enough to work in a covered outdoor area, I’ve fitted one… to the top of the box our milkman delivers our milk into!

Top of a reinforced polystyrene doorstep milk storage box, showing the round-topped handle. A metal file sits atop the box, about to be used to file down the handle.
The handle on the box was almost exactly the right size to stick a Flic button to! But it wasn’t flat enough until I took a file to it.

Most mornings, our milkman arrives by 7am, three times a week. But some mornings he’s later – sometimes as late as 10:30am, in extreme cases. If he comes during the school run the milk often gets forgotten until much later in the day, and with the current weather that puts it at risk of spoiling. Ironically, the box we use to help keep the milk cooler for longer on the doorstep works against us because it makes the freshly-delivered bottles less-visible.

Milk container, with a Flic 2 button attached to the handle of the lid and a laminated notice attached, reading: "Left milk? Press the button on the Milk Minder. It'll remind us to bring in the milk!"
Now that I had the technical infrastructure already in place, honestly the hardest part of this project was matching the font used in Milk & More‘s logo.

I’m yet to see if the milkman will play along and press the button when he drops off the milk, but if he does: we’re set! A second possible bonus is that the kids love doing anything that allows them to press a button at the end of it, so I’m optimistic they’ll be more-willing to add “bring in the milk” to their chore lists if they get to double-click the button to say it’s been done!

Future Plans

I’m still playing with ideas for the next round of buttons. Could I set something up to streamline my work status, so my colleagues know when I’m not to be disturbed, away from my desk, or similar? Is there anything I can do to simplify online tabletop roleplaying games, e.g. by giving myself a desktop “next combat turn” button?

Flic Infared Transceiver on the side of a bookcase, alongside an (only slighter smaller than it) 20p piece, for scale.
My Flic Hub is mounted behind a bookshelf in the living room, with only its infrared transceiver exposed. 20p for scale: we don’t keep a 20p piece stuck to the side of the bookcase all the time.

I’m quite excited by the fact that the Flic Hub can interact with an infrared transceiver, allowing it to control televisions and similar devices: I’d love to be able to use the volume controls on our media centre PC’s keyboard to control our TV’s soundbar: and because the Flic Hub can listen for UDP packets, I’m hopeful that something as simple as AutoHotkey can make this possible.

Or perhaps I could make a “universal remote” for our house, accessible as a mobile web app on our internal Intranet, for those occasions when you can’t even be bothered to stand up to pick up the remote from the other sofa. Or something that switched the TV back to the media centre’s AV input when consoles were powered-down, detected by their network activity? (Right now the TV automatically switches to the consoles when they’re powered-on, but not back again afterwards, and it bugs me!)

It feels like the only limit with these buttons is my imagination, and that’s awesome.

× × × × × × ×

On This Day In 2005

Looking Back

On this day in 2005 (actually tomorrow, but I needed to publish early) I received an unusual parcel at work, which turned out to contain a pan, wooden spoon, tin of spaghetti hoops, loaf of bread… and an entire electric hob.

A parcel from Paul, containing everything required to make a "proper" plateful of spaghetti hoops on toast.
A parcel from Paul, containing everything required to make a “proper” plateful of spaghetti hoops on toast.

This turned out, as I describe in my blog post of the day, to have been the result of a conversation that the pair of us had had on IRC the previous day, in which he called me a “Philistine” for heating my lunchtime spaghetti hoops in the office microwave. This was a necessity rather than a convenience, given that we didn’t have any other mechanism for heating food (other than a toaster, and that’s a really messy way to heat up tinned food…).

It was a different time: a time when the lives of many of my friends were still centered around academic persuits (Siân was working on and handing in her dissertation, as was Liz, Claire was getting results back, Ruth was stressed out by a useless student on her team, Paul took things too far, and even JTA was suffering: struggling with his wordcount of an essay that he considered handing in late). It was a time when our evenings were being consumed watching Knightmare (my blog posts mentioning: the first series, first half of second series, second half of second series, Ruth’s commentary) or at the Ship & Castle (both, sadly, without Sian). It was a time when Andy worked at the cafe under The Flat, like we were all in some kind of sitcom or something.

It was clearly a time when we were all blogging quite regularly: apologies for the wall of links (a handful of which, I’m afraid, might be restricted). Be glad that I spared you all the posts about the 2005 General Election, which at the time occupied a lot of the Abnib blogosphere. We were young, and idealistic, and many of us were students, and most of us hadn’t yet been made so cynical by the politicians who have come since.

Another shot of the parcel. This wasn't posted, mind: he lugged this over to my office by hand, and dropped it off at the reception desk.
Another shot of the parcel. This wasn’t posted, mind: he lugged this over to my office by hand, and dropped it off at the reception desk.

And, relevantly, it was a time when Paul was able to express his randomness in some particularly quirky ways. Like delivering me a food parcel at work. He’s always been the king of random events, like organising ad-hoc hilltop trips that turned out to be for the purpose of actually releasing 99 red (helium) balloons. I tried to immortalise his capacity for thinking that’s not just outside the box, but outside the known Universe, when I wrote his character into Troma Night Adventure, but I’m not sure I quite went far enough.

Looking Forward

It seems so long ago now: those Aberystwyth days, less than a year out of University myself. When I look back, I still find myself wondering how we managed to find so much time to waste on categorising all of the pages on the RockMonkey wiki. I suppose that nowadays we’ve traded the spontaneity to say “Hey: card games in the pub in 20 minutes: see you there!” on a blog and expect it to actually work, for a more-structured and planned existence. More-recently, we’ve spent about a fortnight so far discussing what day of the week we want out new monthly board games night to fall on.

There’s still just enough of the crazy random happenstances in my life, though. As I discovered recently, when I once again received an unusual and unexpected parcel in the post. This time, it wasn’t from Paul, but from Adam, who’d decided to respond in a very literal fashion to my tongue-in-cheek suggestion that he owed me tea, and a keyboard.

Several boxes of fruit and herbal teas.
The second of the two unexpected parcels I received from Adam.

I got the chance to live with Paul for a couple of years, until he moved out last month. I’m not sure whether or not this will ultimately reduce the amount of quirkiness that I get in my diet, but I’m okay either way. Paul’s not far away – barely on the other side of town – so I’m probably still within a fatal distance of the meteor we always assumed would eventually kill him.

We’ve turned what was his bedroom into an office. Another case of “a little bit less random, a little bit more structure and planning”, perhaps, in a very metaphorical way? Maybe this is what it feels like to be a grown-up. Took me long enough.

This blog post is part of the On This Day series, in which Dan periodically looks back on years gone by.

× × ×

A Very Confused Courier

I’ve just had a phone call from a very confused courier. My mother (who many years ago for reasons both too long and silly to go in to I nicknamed “Crusty Pasty”) texted me last night to say that I was to be delivered an early Christmas present that would arrive today, and that she’d given the courier my phone number so that he could ensure that I was in when he came around. My mobile rang:

Me: Hello.
Him:
Hi, is this Dan… Q?
Me: Speaking.
Him: Hi: I have a delivery for you from a… I just want to make sure I say this right: Crusty Pasty?
Me: That’s correct. I’m expecting it.
Him: I think there might be something wrong with your landline: I called and got a strange robot voice.
Me:
Oh, that was you? That phone is never answered. Best to call this number.
Him:
I just wanted to double-check the address: [number] Corpse Lane?
Me: Copse Lane.
Him: Oh yes, sorry. Just my bad handwriting. I’m on the M4 right now; I’ll be there in about an hour: is that okay?
Me: Yes, I’ll be at that address all morning.
Him: Okay. See you at about 11.

Codenames? Mysterious parcels? Phone numbers that always go unanswered? Yes, that’s right: I’m about to be treated as being part of some kind of terrorist cell. If my “early Christmas present” is something that can be used in the construction of an explosive, then the jigsaw will be completed and this will probably be my last ever blog post… until I’m released from Guantanamo Bay.