How to make a Not-For-Emergencies Parent Button using AWS IoT

Andy O'Sullivan
5 min readDec 12, 2020

This is a quick tutorial on how to use an AWS IoT button to create what I like to call a Not-For-Emergencies Parent Button! I say quick because it’s a lot easier than it used to be to set it all up, and I say Not-For-Emergencies as I wouldn’t necessarily rely on it!

What’s the “business case”?

I’m lucky enough to have a great job that has me working from home during COVID, until at least May 2021. In an effort to get actual work done, sometimes I literally lock myself away in the attic, so the kids, dog … or wife … can’t interrupt, distract or jump on my head!

I know this looks staged, but it sadly/happily isn’t! My head is the best perch to watch Super Wings

If they need me, they can come up a few flights of stairs and hammer on the door or my wife rings or texts me, usually with a message like “we need you downstairs now!” or “the dog’s going crazy, can you take him?!”.

As an early Christmas present to the family, I decided to use an AWS IoT Button that was gathering dust in a drawer to make a Not-For-Emergencies Parent Button!

So now, they can just hit a button, I’ll get a text on my phone, and I’ll come downstairs, as if by magic! Most likely with my headphones still on and mouthing frantically “I’m on a call, this better be an emergency!”.

For anyone who hasn’t seen an AWS IoT button, it’s a little button that you can hook up to a Lambda function in your AWS account — and it can send three messages by using the button three different ways:

  • A single click
  • A double click
  • A long press

What you do with the Lambda then is up to you — send an email, or SMS or whatever! For the Not-For-Emergencies Parent Button, I decided to send SMS messages.

It’s a lot easier than it used to be

I first tried this about three years ago, and I vaguely remember a lot of messing around with security certificates in the AWS console. However, like a lot of AWS services, they’ve streamlined it over the years and really made it easy. Let’s do it!

Steps

  1. You need an AWS IoT Button, obvs. Mine’s a few years old, and I’m not sure are they selling this model anymore. The more recent models are here: https://aws.amazon.com/iot-1-click/devices/ but at the core it seems to have the same main features — single, double or long clicks.
  2. You also need an AWS account, and knowledge of javascript or python would be good.
  3. Download the AWS IoT Button app — Apple or Play Store.
  4. Open the app and sign into your ASW account,
  5. Then you can add a new button. Note the AWS region at the bottom — you may want to change this.

6. Follow the instructions — which include hooking up to your WIFI — and eventually you’ll see this screen, where you can select what action you want to happen:

I picked Send SMS (nodejs), as who actually likes python … then give it a phone number to send the SMS’s to, and it’ll create a new Lambda for you in your AWS account, named something like iotbutton_G12345634ABCD1234_iot-button-sms-nodejs

7. If you take a look at it, you should see something like:

'use strict';const AWS = require('aws-sdk');
const SNS = new AWS.SNS({ apiVersion: '2010-03-31' });
const PHONE_NUMBER = '353123456789'; // change it to your phone number
exports.handler = (event, context, callback) => {
console.log('Received event:', event);
console.log(`Sending SMS to ${PHONE_NUMBER}`);
const payload = JSON.stringify(event);
const params = {
PhoneNumber: PHONE_NUMBER,
Message: `Hello from your IoT Button ${event.serialNumber}. Here is the full event: ${payload}.`,
};
// result will go to function callback
SNS.publish(params, callback);
};

8. Hit the button, its little light should flash white a few times, then green to indicate success, and you should see then on your phone:

Easy!

9. You can change the “NOTICE” sender ID in the AWS Console at SNS -> Text Messaging (SMS) -> Text Messaging Preferences. I changed mine to “Family”, as I thought “Distractions” was a bit unkind:

10. Note the Account spend limit — this defaults to $1 dollar a month, and to increase it you need to request it from AWS, see here for more info: https://aws.amazon.com/premiumsupport/knowledge-center/sns-sms-spending-limit-increase/

This is worth knowing for two reason:

  • SMS messages aren’t free, see pricing here: https://aws.amazon.com/sns/sms-pricing/ so you don’t necessarily want the two year old sending you 2000 texts a day from the button.
  • You’ll probably hit the limit pretty quick, as I did during testing!

11. Back to the code — let’s change it to send more interesting messages, with changes in bold:

exports.handler = (event, context, callback) => {
console.log('Received event:', event);
console.log(`Sending SMS to ${PHONE_NUMBER}`);
const payload = JSON.stringify(event);

//default reply for SINGLE clickType in event
var reply = "Daddy we need you!"
if (event.clickType === 'DOUBLE') {
reply = "Can you take the dog?"
} else if (event.clickType === 'LONG') {
reply = "NO TEABAGS!!!"
}


const params = {
PhoneNumber: PHONE_NUMBER,
Message: reply,
};
// result will go to function callback
SNS.publish(params, callback);
};

This basically checks the “clickType” field in the payload from the button i.e. single, double or long click and then sends a different SMS message depending on what it is.

And you’re done!

Not-For-Emergencies

I wouldn’t recommend this for emergency usage as I’ve found it a bit flaky (could just be my button / WIFI connection, don’t sue me AWS) and also in case you’ve hit your SMS limit and haven’t realised.

For more info on the buttons, see here: https://aws.amazon.com/iotbutton/faq/

Any thoughts or comments, let me know below, or feel free to reach out on LinkedIn or Twitter.

--

--