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.

× × × ×

HDMI Virus, or How I Became An Old Person

So I saw this HDMI cable online:

Apparently the plastic coating around this cable helps to prevent 'virus noises', whatever those are. Red scribbles added by me.

Somehow, this triggered a transformation in me. You know how when Eric eats a banana, an amazing transformation occurs? A similar thing happened to me: this horrendously-worded advertisement turned me into an old person. I wanted to write a letter to them.

My letter... er... email to Bluemouth Interactive.

There were so many unanswered questions in my mind: what is a “virus noise” (is it a bit like the sound of somebody sneezing?)? How a polyester coating protects against them? And what kind of viruses are transmitted down video cables, anyway?

It took them five days but, fair play to them, they – despite Reddit’s expectations – wrote back.

Bluemouth's response to me. Like the other pictures, you can click it to see it in full.

Their explanation? The ‘Virus’ was transcribed from French terminology for interference. It’s not a computer virus or anything like that.

The world is full of examples of cables being over-sold, especially HDMI cables and things like “gold-plated optical cables” (do photons care about the conductivity of gold, now?).

Does anybody have enough of a familiarity with the French language to let me know if their explanation is believable?

× × ×

Poly and the Census – Success! (almost)

You may remember the long-running story of my letters to the Office of National Statistics, and the more-concentrated effort by another blogger, in regard to the automatic “correction” of supposedly-“erroneous” data in the 2011 census, like somebody having multiple partners or identifying as neither gender. You don’t? Well here’s a reminder: part one, part two, part three, part four.

Well: we’ve finally had some success. A response has been received from the ONS, including – at last – segments of business logic from their “correction” code.

It’s hard to tell for certain what the result of the correction will be, but one thing’s for sure – Ruth, JTA and I’s census data won’t have passed their validation! Their relationship validations BP2, BP2a, and BP2b state that it is logically-impossible for a person to have a spouse and a partner living with them in the same household.

I should invite them around for dinner sometime, and they can see for themselves that this isn’t true.

I also note that they consider it invalid for anybody to tick both or neither of the (two) gender option boxes, although again, it’s not clear from the data they’ve provided how the automatic correction occurs. Increasingly, I’m coming to suspect that this might actually be a manual process, in which case I’m wondering what guidelines there are for their operators?

One good piece of news from this FoI request, though: the ONS has confirmed that the original census data – the filled-in paper forms, which unlike the online version doesn’t enforce its validation upon you – is not adjusted. So in a hundred years time, people will be able to look back at the actual forms filled in by poly, trans, and other non-standard households around the UK, and generate actual statistics on the frequency with which these occur. It’s not much, but it’s something.

Poly and the Census – Part Four

Following up on my earlier blog posts about how data on polyamorous households is recorded in the census (see parts one, two, and three), as well as subsequent queries by Zoe O’Connell on this and related topics (how the census records data on other relationships, such as marriage between same-gender partners and civil partnerships between opposite-gender partners), there’s finally been some progress!

No; that’s a lie, I’m afraid. We’re still left wading around in the same muddy puddle. Zoe’s Freedom of Information Act request, which basically said “Okay, so you treat this kind of data as erroneous. How often does this happen?” got a response. And that response basically said, “We can’t tell you that, because we don’t have the information and it’d cost too much to work it out.” Back to square one.

Still: it looks like she’s not keen to be beaten, as she’s sent a fresh FoI request to instead ask “So what’s the algorithm you’re using to detect this erroneous data?” I was pleased to see that she went on to add, effectively, “I don’t need an explanation: send me the code if you need to,” which makes it harder for them to fall behind the “It’s too expensive!” excuse yet again.

Anyway: it’s one to watch. And needless to say, I’ll keep you all posted when anything changes…

Poly and the Census – Part Three

Unimpressed with the slow response time that I and others were getting to my query to the Office of National Statistics (to which I still never received a response) the month before last, Zoe O’Connell decided to send a Freedom of Information Act request demanding a response to a couple of similar questions. After some hassling (I suppose they’ve been busy, with the census and all), they finally responded. The original request and the full response is online now, as is Zoe’s blog post about the response. But here’s the short version of the response:

Polygamous marriages are not legally recognised in the UK and therefore any data received from a questionnaire that appeared to show polygamous relationship in the manner that you suggest would be read as an error. It is recognised that the majority of respondents recording themselves as being in a polygamous relationship in a UK census do so erroneously, for example, ticking the wrong box for one household member on the relationships question.

Therefore, the data to be used for statistical purposes would be adjusted by changing one or more of these relationships, so that each respondent is in a relationship with no more than one person. This is consistent with all previous UK censuses, and others around the world.

A copy of the original questionnaire would be retained as part of the historical record which would show such relationships as they were recorded. We do not attempt to amend the original record.

Any mismatches between the indicated sex and marital status of respondents will be resolved using a probabilistic statistical system which will not necessarily deal with each case in the same way. The system will look at other responses for each person, including those for the Household relationships, and will alter one or more variables to make the response consistent. In the example that you propose, it would either change the sex of one individual, or change the marital status to “Same-sex civil partnership”, depending on which is considered statistically more likely to be correct.

Honestly, I’m not particularly impressed. They’ve committed to maintaining a historical record of the original, “uncorrected” data, so that future statisticians can get a true picture of the answers given, but this is about the only positive point in this response. Treating unusual data as erroneous is akin to pretending that a societal change doesn’t exist, and that this approach is “consistent with previous censuses” neglects to entertain the possibility that this data has value that it might not have had previously.

Yes, there will be erroneous data: people who accidentally said that they had two husbands when they only have one, for example. And yes, this can probably (although they don’t state how they know to recognise this) be assumed to be more common that genuine cases where somebody meant to put that on their census (although there will also be an error rate amongst these people, too). But taking the broad brush approach of assuming that every case can be treated as an error reeks of the same narrow-mindedness as the (alleged; almost-certainly an urban legend) statement by Queen Victoria that lesbianism “didn’t exist.”

“Fixing” the data using probabilities just results in a regression towards the mean: “Hmm; this couple of men say they’re married: they could be civil partners, or it could be a mistake… but they’re in a county with statistically-few few gay people, so we’ll assume the latter.” Really: what?

I’m not impressed, ONS.

Update: a second FoI request now aims to determine how many “corrections” have been made on censuses, historically. One to watch.

Poly and the Census – Part Two

No reply yet from the Office of National Statistics after the letter I sent the other week, but I imagine that they’ve been busy, what with the census and everything. Needless to say, I’ll keep you posted.

However, in the meantime somebody’s one-upped me and has put in a Freedom of Information request, which – of course – the law mandates that they respond to. I should’a thought of that. Anyway, you can read the request here, and there’s options to follow it by RSS and/or email if you want updates.

Update (27th April 2011): Still no word in response to the FoI request.

Poly and the Census

I’ve just sent a letter to the Office of National Statistics, about the 2011 census. In case you’re interested, or if you’d like to send a similar letter to ensure that your own living arrangements will be correctly recorded, you’re welcome to use it as a template. My letter reads:

Census Customer Services
ONS
Segensworth Road
Titchfield
Fareham
Hampshire
PO15 5RR

10th March 2011

Dear Sir or Madam,

Re: Households containing people with multiple romantic relationships in the 2011 census

I write to you to ensure that the data that will be provided by my household for the 2011 census will be properly recorded and processed. I am a supporter of the census and understand its importance, but I am concerned that my response, and the response of others in my position, is at risk of being misunderstood or misinterpreted as a mistake.

I live with my partner and her husband in a three-way committed relationship. We have attempted to express this on the census form: my partner has checked the “husband or wife” box in reference to her relationship to her husband, and she had checked the “partner” box in reference to her relationship with me. Like many people in this kind of relationship, our family is the victim of unfair discrimination, and it’s important to us that we can be counted so that future lawmakers, armed with the statistical evidence, can pass policy that is fair to all: including those who choose to be romantically-involved with multiple people at the same time.

Please give me your assurances that our data will be correctly recorded. If this is not possible, please advise me to whom I should write to put the case that this should be changed.

Yours sincerely,

Dan Q

If the census isn’t the time for a little Poly-activism, then I don’t know when is. I’ll keep you posted if I get a response.

Postcard From Kit And Fi

Received a postcard this morning from Kit & Fi, and it’s as much to many of you lot as it is to me, so I’ll relay it to you here:

Postcard from Mull

[CLASSIFIED – OPERATION TROMA // EYES ONLY]
Dear Dan, Claire, Paul, Bryn + Ruth, JTA, Andy, Siân & any other Troma fanatics (Jon + Hayley I’m guessing!)
Just thought we would write you a card to say we haven’t forgotten you all! On holiday in Mull, just finished making a Rhubarb crumble and will be planning trips to Iona + Oban. Should get down for freshers, but Fi will have to stay here – being a student and all!
Wish I could be with you all more! I do miss you!
Look after yourselves – say hi to the nocturnal bunch for me.
Love Kit + Fi… (it looks like it might say “Fio” or “Fiona”, but the stamp has been stuck over it)

Thanks for that, Kit, Fi. Made my morning (I usually only get envelopes with windows in them through my door). And yes, Kit, you got the postcode right.

×

Parcel Of Goodies

Woo and indeed hoo. Just when I was about to wander down to Richley’s and take advantage of their sale on jeans (having had a nasty shredding-related accident with one-too-many of my existing pairs of trousers a couple of weeks back), my Auntie Anne sends me a parcel of goodies, including several pairs of trousers (including one with a million pockets, or thereabouts).

I think I’ve put on weight since the last time she sent me any clothes. [measures waist size]. Yup; I’m two inches fatter than this time last year. Well; there’s an incentive to lose it again.

In other news; I’ve almost completed an exciting little project that will provide some amusement to those of you who attend Chez Geek Night (BTW: it’s on Tuesday this week, so we don’t end up in a fight with the Irish Band again). No; it’s not a computer game version (although I’m hoping that the author will allow me to write one, one day)… but I think you’ll like it, anyway. Details tonight or tomorrow.

Yay! No more lectures today!