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.

× × × × × × ×

A New Keyboard

I already own the best mouse in the world. Maybe it’s time for a new keyboard, too.

An unexpected parcel.
What a large package! I wasn't expecting that!

A few weeks ago, Adam blogged about his trip to London last year, and mentioned that, after trips out to Soho’s “G-A-Y” nightclub when he was younger, he’d often surprise himself the following morning to wake up in some quite distant travel zones of London. My favourite bit was when he mentioned that, on one ocassion, he’d…

…somehow managed to whore my way beyond the reach of the Underground.

Adam

I replied with a comment, stating, among other things:

You owe me a fresh herbal tea. Also a new keyboard, which might never recover from the nasal spraying of herbal tea that it’s just been exposed to.

Dan

(it’s not a particularly original comment, I know: Jimmy said something similar in a comment on this very blog, about four years ago)

A gift note from Mr. A Westwood: Hi Dan, As requested, one replacement keyboard. I do hope that it's a suitable replacement and that nobody's got their wires crossed. Happy tapping! Adam xx
This note went a little way to explaining the parcel.

In any case: the week before last I received a pair of unexpected parcels. I opened the first, an Amazon box, and pulled out a note. It was from Adam, and stated that the contents were “a replacement keyboard”, assuming that “nobody’s got their wires crossed.”

The 'keyboard' that Adam had sent.
Adam's instrument. You need to wrap your lips around the tube and give it a good blow, while you finger the other end.

A musical keyboard: this one’s powered by air (I’d have never guessed that Stagg would have made such a thing!). The musician blows into a tube while they play the notes in order to elicit a tune. It doesn’t sound bad, actually, although I do feel that it could do with a MIDI port. And an air-driven dynamo to power that port. And then a battery-powered pump so that you don’t need to blow it at all.

The second parcel continued the theme:

Several boxes of fruit and herbal teas.
Hot and fruity: just the way I like them.

A selection of herbal and fruit teas, from Asda’s Morrisons’ range. There was no note in this parcel, but it was pretty clear by now who the sender must be. I’d have been ever so confused if I’d have opened the second parcel one first.

So thank you, Adam, you crazy old fool, for making me laugh out loud yet again. I shall have to compose a song in your honour: and given the amount of air intake that’s needed to keep the keyboard playing, I shall call it, The Big Puff Song.

× × × ×

Diplomacy, Parcels, and WW2 RTS Games

What have I been up to of late? Well, as you ask…

Diplomacy

Ruth‘s game of Diplomacy got off to a fine start, and the backstabbing began soon afterwards. I’m not so keen on the engine, for reasons I’ll discuss later. Here’s how the map looks right now.

Diplomacy Map 211

I’m the red guys down at the bottom who are getting their arses kicked by the purple and brown guys. Very sweetly, JTA (leader of Russia) sent me an e-mail to apologise a little (and gloat a lot) about his recent pillaging of my lands, and congratulate me on trying to set him and Andy (Germany) against one another. It’s kind-of sweet, as I said, but really un-necessary: breaking alliances is what the game is all about.

Plus, it’s not like I didn’t see it coming. My alliance with Russia as a show from the start, but I didn’t realise that Russia planned to attack me so soon (I’d just issued attack orders against him). My mistake was that I didn’t anticipate that Germany side with Russia and backstab me. Memo to self: assassinate leader of Germany.

Sadly, the Diplomacy engine we’re using – phpDiplomacy – has a few interesting bugs that make it hard to work out who’s actually on your side. Here’s an example situation:

The problem with phpDiplomacy

The screenshot is faked, but the situation is plausible – the engine doesn’t accomodate for this. In this situation, the red player has been successfully attacked by the brown player, displacing their army (according to the message from 10:36pm). It’s not possible that the brown player did this alone, in this situation: they must have had help from at least one of – the green army in Piedmont, the green fleet in Venice, the purple army in Vienna, possibly a purple army from the region above (not shown), or perhaps even from the red fleet in Trieste (an unusual strategy, but not unheard of in some unusual circumstances, is to support the enemy against your own units).

But the engine gives no indication which this is. In this situation, the red player does not know which – green or purple – supported the attack. If the red player had alliances with the two of them, they would not know which one had betrayed them, for example. Whoops!

This could make it an interesting (or a frustrating) game. I’m certain that in the near future we’ll see players strategically helping one another perform attacks, without revealing that it was them that supported it.

A Strange Parcel

A strange parcel from Matt.

This morning, I received a strange parcel from Matt in the Hat, addressed to “Jen, Paul, Dan & Claire”. The contents, as pictured, seem to be two Guinness glasses and three cartons of organic fruit juice. I’m not sure which bits are for whom – or even why we’ve been sent this package at all – but I’m sure Matt will enlighten me soon.

Update: I’ve spoken to Matt on Jabber, and apparently the Guinness glasses box does not contain Guinness glasses. And I’m to make sure that Jen gets one of the cartons of juice.

Basically, Matt’s lost the plot. However, he still managed, through his insanity, to pick a selection of objects who’s size ratios made packing them easy.

Company of Heroes

I’ve been playing a lot of Company of Heroes these last couple of days: it’s a spectacular game. It’s been a long time since a real-time strategy game has amused me so much (since, perhaps Red Alert 2, seven years ago). It’s yet-another-world-war-2 game, as if we haven’t seen enough of them of late, but it’s a battle-level strategic game, rather than a first-person shooter, and it does a wonderful job of what it does.

Tanks roll through deformable terrain. Infantry hide in the craters your artillery has blown out. And the whole thing looks and sounds beautiful, from the hushed descent of paratroopers into a muddy field (reflections and all) to the flashes and blasts of a distant battle (complete with radio chatter, or plain old voices if you’re looking directly at the speaker). You can build sandbag walls and minefields, and blow them down just as easily. Don’t want to risk your men down a long, sniper-infested street? Steal some German artillery pieces and blow your way though the walls, then – the whole map is completely reshapable. The AI’s not to be sniffed at, either (although it’s a bit fiddly when it comes to multi-selecting and moving a group of vehicles together and they all crumple into each other when they reach a chicane, rather than taking turns).

It needs a beefy machine to do it justice, which is why I got it – to push my new gaming rig to the limits – but it’s more than just a graphics-fest: it’s also a very clever and gritty game.

So, who’s for a co-op?

Writing Comedy

And, of course, the other thing that’s been occupying my time has been writing stuff to say on Sunday’s Gorillamania event. But I’ve already said enough about that recently, so I’ll shut up and get on with some work.

Paul Is The Most Fucking Random Person In The World

Paul M: fucking nutter. The most random person you’re ever likely to meet. But you’ve got to love his sincerity.

This morning, I’m happily sat at my workstation, staring, as I do, at program code and pausing from time to time to check the RSS feeds of the usual crew, when the phone rings: Matt answers it; it’s Technium reception – they’ve got a parcel for us. Ooh; that’s exciting, but Matt’s deeply involved in some code so I offer to go and collect it. The arrangement here among us lazy folks is that the receptionist puts the parcel in the lift, and one of us toddles along the corridor and takes it out of the lift on this floor.

I stood outside the lift and listened as it came up to the first floor. The door opened, and I lifted out the parcel… and that’s when I noticed the first strange thing: the parcel was addressed to me, personally (which is very unusual) and the address was written entirely in marker pen (rather than being a printed label, as most goods delivered to us here are). I’m not expecting anything; least of all at work: I never give my work address to anybody. Who could have sent this?

I opened it and laughed out loud. It took just a second to realise what was going on, as I recalled a conversation in the RockMonkey ChatRoom yesterday lunchtime…

[11:38] * Ava_Work goes to nuke food
[11:38] <Ava_Work> Hmm… spaghetti hoops on toast for me, methinks…
[11:39] <Pacifist_049> You’re microwaving spaghetti hoops?
[11:41] <Ava_Work> Yup.
[11:41] <Ava_Work> Why?
[11:41] <Pacifist_049> Philistine
[11:41] <Ava_Work> So…
[11:41] <Ava_Work> …how else can I do it?
[11:41] <Ava_Work> And think carefully now…
[11:41] <Pacifist_049> Pan
[11:41] <Ava_Work> A pan. Which I don’t have. But let’s pretend I did. How would I heat it?
[11:41] <Pacifist_049> I know you don’t have a cooker at work, but that’s not the issue here. It’s the principle, damnit!
[11:42] <Ava_Work> So; as it pisses YOU off so much, feel free to bring me a pan and a cooker. Then I’ll do it your way, which is – in the end – preferable.
[11:42] <Ava_Work> However, it doesn’t piss ME off enough that I’ll go hungry rather than nuke spaghetti hoops.

Parcel containing a loaf of bread, a tin of spaghetti hoops, a pan, wooden spoon, and an electric hob. Close-up on the beans pan, and wooden spoon.
Click on images for larger versions.

The parcel, as shown above, contains a pan, wooden spoon, loaf of bread, tin of spaghetti hoops, and a strangely familiar electric hob.

Which is a fab gesture, although if I use it for my lunch today I’ll have to do so on the sly, on account of the fact that the Technium facilities manager is in today and this particular piece of electrical equipment has not been electrically safety-tested.

Electrical safety test sticker.

What the fuck. Thank you, Paul!

×