AWS Startups Blog

One-Click Check-In/Check-Out for Airbnb guests using an AWS IoT Button

Post by Karan Desai, Solution Architect, AWSAWS IoT button smart home architecture

Are you an Airbnb host? Would you like to have an easy way to know when your guests come in and leave, or need help? In this post, I show how you can set up an AWS IoT button to build a simple project that can do the following:

  • Send you a notification SMS or an email informing you what time your guests check in and check out.
    Send you a notification if your guests need help.
  • Update a Google Drive spreadsheet to keep track of all guest check-ins and check-outs.
  • Prepare your smart home for your guests. For example, turn on a Philips Hue light bulb when they check in to create a warm welcoming environment, turn on your Nest thermostat to a comfortable temperature, and turn it all off when they check out.

This project doesn’t require you to purchase any additional hardware or learn any programming. If you sign up for AWS Free Tier, you can run this project for 12 months at no cost, and even without the Free Tier, it will only cost a few pennies per month, depending on your usage. All the code you need is provided with instructions, so you can build this even if you are new to AWS. All you need is an AWS IoT button, an AWS account, your Google account, and a free IFTTT app on your smartphone. If you have Philips Hue light bulbs or a Nest thermostat, you can integrate them into your project, but they are not necessary to build the rest of the project. So, let’s jump right in.

Set up the AWS IoT button for notifications and smart home controls

You need the following things before we proceed further:

Step 1: Set up your button

  1. Download the AWS IoT button app on your phone. See iOS – App Store or Android – Google Play.
  2. Sign in to the app using your AWS account credentials. Follow the instructions on the app to register, configure, and set up your button.

    download AWS IoT Button app

  3. On the Set button action page, choose Send SMS (nodejs), and then type a phone number for receiving text messages (SMS).Setting up account on AWS IoT Button App

 

Step 2: Set up your SNS topic and subscriptions

 

Sign in to the AWS Management Console. On the navigation bar, choose Services, and then search for Simple Notification Service or SNS. Here you will set up what phone numbers and email addresses to use for notifications.

  1. On the SNS dashboard, choose Create topic. For topic name, type a name of your choice.
  2. After the topic is created, copy the topic ARN and save it in a text file. You will need it later. The ARN is a text string that looks like this- arn:aws:sns:<region-name>:<numbers>:<text>
  3. Choose Create subscription.
  4. For Protocol, choose SMS. For Endpoint, type a phone number for receiving text messages, or choose Email if you prefer to receive an email instead of a text message.
  5. Choose Create subscription.

    setting up AWS SNS

 

Repeat the steps if you want to add more than one phone number or email address.

Note: If you downloaded the IFTTT app on an iPhone or iPad, create another topic and add the Gmail address that you configured on your iPhone or iPad. This is in addition to one subscription of type SMS. Since IFTTT for iOS currently does not support incoming SMS notifications as a trigger, you will use incoming email as a trigger for certain actions. This is not necessary if you are using an Android phone or tablet.

 

Step 3: Update IAM permissions

 

Next, you update the security settings so that your SNS subscriptions are accessible only by your IoT button.

  1. On the navigation bar, choose Services, and then search for IAM.
  2. On the IAM console, choose Roles. In the list of roles, select the role that has “iotbutton” in the name. On the Permissions tab, you should see that the role has two policies already attached to it, as shown in the following screenshot.IAM permission settings for IoT Button
  3. Select the policy that has “SMSExecutionRole” in the policy name. Choose the JSON tab, and then choose the Edit button to open the policy editor.
  4. Delete everything in the text box, and replace it with the following code:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sns:Publish"
            ],
            "Resource": [
                "arn:aws:sns:xxx:xxx:xxx"
            ]
        }
    ]
}

Replace arn:aws:sns:xxx:xxx:xxx with your topic ARN that you saved in Step 2. Choose Save.

 

Step 4: Modify your Lambda function

 

Your AWS IoT button registration process has already created a Lambda function on your AWS account that is triggered by a click of your IoT button. However, in this step you personalize it to invoke Amazon SNS to send the notification text messages and emails.

  1. On the navigation bar, choose Services, and then search for Lambda.
  2. On the Lambda console, you should find a newly created Lambda function named iotbutton_XXX, where XXX is your device code (DNS). Select the function. If you don’t see the function, make sure you are in the same AWS Region where the button was registered. The current region is shown on the top right corner of your AWS console screen.
  3. On the Code tab, delete all existing code and replace it with the code provided here: https://github.com/awslabs/iot-button-notifications/blob/master/iot_button_notifications.js.
  4. Make three simple changes to this code:
    • Search for const TOPIC_ARN in the code and replace the existing ARN text string with your SNS topic ARN that you saved in Step 2.
    • Search for var localTimeZone in the code and enter the UTC time offset of your local time zone. If you don’t know your UTC time offset, you can find it here or you can keep it at 0 to get the timestamp in your notifications in Coordinated Universal Time (UTC).
    • Search for var emailSubject in the code and edit the message if you prefer a different subject for your notification emails. This is optional, if you like the existing message, you can leave it as it is.
  5. Choose Save. This completes your setup on the AWS console.

 

Step 5: Set up your IFTTT app

 

In this step, you set up the IFTTT app to receive notifications from your AWS IoT button and you use that to update a Google Drive spreadsheet with your guest check-in/check-out details, and optionally control your Philips Hue light bulbs or Nest thermostat.

  1. Open the IFTTT app on your smartphone that you previously downloaded. Sign in, or create a new account if you’ve never used this app before.
  2. Choose My Applets on the bottom menu, and on the next page choose the + icon to create a new applet.
  3. Choose +this. From the list of trigger services, choose Android SMS if you are using an Android device, or GMail if you are using an iPhone.
  4. If you use an Android phone, from the available options choose New SMS received matches search. In the text box, type ‘ALERT’, and then choose Save. If you use an iPhone, choose New email received matches search. In the text box, type ‘ALERT’, and then choose Save.
  5. Choose +that. From the list of action services, choose Google Drive.
  6. From the available options, choose Add row to spreadsheet.
  7. In the form on the next page, type the name that you want to give your spreadsheet, for example, “Airbnb Guest Log”. Choose what information would you like in the spreadsheet. I recommend keeping “Occurred At” and “Text” so that you can have a record of times and dates of every check-in, check-out, and help request from your guests.
  8. You can also edit the Drive folder path if you want to save the spreadsheet under a specific folder in your Google Drive.
  9. Choose Save.

 

Step 6: Connect your smart home devices

 

If you don’t have Philips Hue light bulbs or a Nest thermostat, you can skip this step and continue to the next section.

If you want to control Philips Hue light bulbs or a Nest thermostat in response to your AWS IoT button notifications, create additional applets following instructions in Step 5, but with the following changes:

 

To set up for guest check-ins

  1. From the available options under Android SMS or Gmail trigger, select New SMS received matches search or New email received matches search. In the text box, type ‘CHECK-IN’, and then then choose Save.
  2. To control Philips Hue light bulbs, choose +that. From the list of action services, choose Philips Hue. From the available options, choose Turn on lights. Make sure that you have connected the IFTTT app to the Philips Hue app on your phone.
  3. To control a Nest thermostat, follow the same steps but from the list of action services, choose Nest Thermostat and from the available options, choose Set temperature to configure it to the levels that you want. Make sure that you have connected the IFTTT app to the Nest thermostat app on your phone.

Tip: If you want to control both a Philips Hue light bulb and a Nest thermostat from the notifications, just create two applets by following the preceding instructions. If you have a different brand of connected lights or connected thermostat, you can check if is supported by IFTTT and set it up similarly.

 

To set up for guest check-out

  1. From the available options under SMS trigger, select New SMS received matches search or New email received matches search. In the text box, type ‘CHECK-OUT’, and then choose Save.
  2. Choose +that. From the list of action services, choose Philips Hue and Turn off lights, or Nest Thermostat and set the temperature of your choice.

 

Start clicking!

 

That’s it, you are all set! You can click your IoT button and test that it works as expected.

Pressing the button once will do the following:

  • Send you an SMS or an email with a message similar to this:

CHECK-IN ALERT! Guest in Room 1 has checked in at 22:37:04

  • Update your Google Drive spreadsheet with an entry similar to this:

June 10, 2017 at 10:37 PM | IoT Button> CHECK-IN ALERT! Guest in Room 1 has checked in at 22:37:04

  • (Optional) Turn on your Philips Hue bulbs or set your Nest thermostat to the temperature you desire when guests are in the room

Pressing the button twice will do the following:

  • Send you an SMS or an email with a message similar to this:

CHECK-OUT ALERT! Guest in Room 1 has checked out at 09:25:45

  • Update your Google Drive spreadsheet with an entry similar to this:

June 11, 2017 at 09:25AM | IoT Button> CHECK-OUT ALERT! Guest in Room 1 has checked out at 09:25:45

  • (Optional) Turn off your Philips Hue bulbs or set your Nest thermostat to the temperature you desire when guests have left the room

Long pressing the button (longer than 2 seconds) will do the following:

  • Send you an SMS or email with a message similar to this:

HELP ALERT! Guest in Room 1 needs help! Help requested at 23:18:24

  • Update your Google Drive spreadsheet with an entry similar to this:

June 10, 2017 at 11:18PM | IoT Button> HELP ALERT! Guest in Room 1 needs help! Help requested at 23:18:24

This completes your project of setting up the AWS IoT button. You’re ready to welcome your next Airbnb guests and have them experience your cool, convenient solution!

If you are interested in the technical details of the AWS services involved in this project, you can read the next section.

 

Behind the scenes: architecture and service overview

 

The following high-level architecture diagram shows the serverless setup used in this project.

architecture for serverless IoT Button

 

The AWS IoT Button is a programmable button based on the Amazon Dash Button hardware. The device connects to Wi-Fi and sends a JSON payload that contains the device serial number, the measured battery voltage, and a click type to the AWS IoT service when the button is pressed.

AWS IoT is a managed cloud platform that lets connected devices interact easily and securely with cloud applications and other devices. AWS IoT can process and route billions of messages to AWS endpoints and to other devices reliably and securely. In this project, an AWS IoT rule is used to invoke a Lambda function, passing the message data.

AWS Lambda is a service that lets you run code without provisioning or managing servers. With Lambda, you can run code for virtually any type of application or backend service—all with zero administration. Just upload your code, and Lambda takes care of everything required to run and scale your code with high availability. In this post, a Lambda function is used to invoke an SNS topic to send notification text messages and emails.

Amazon Simple Notification Service (SNS) is a fast, flexible, fully managed push notification service that lets you send individual messages or to fan-out messages to large numbers of recipients. Amazon SNS makes it sim

ple and cost effective to send push notifications to mobile device users, email recipients. You can even send messages to other distributed services.

AWS Identity and Access Management (IAM) is used to securely control access to AWS services and resources. Using IAM, you can create and manage AWS users and groups, and define policies to allow and deny their access to AWS resources. This project uses an IAM role with a policy that restricts access of your Lambda function to your SNS topic only, identifying it by its Amazon Resource Name (ARN).

IFTTT is a free web-based service that allows users to create chains of simple conditional statements, called applets. An applet is triggered by events within other web services, such as an incoming text message or a new email received on Gmail, and can be configured to perform specific actions such as updating a spreadsheet on Google Drive, or controlling connected devices such as a Philips Hue light bulb or Nest thermostat.

 

Conclusion

 

AWS serverless and managed services allow you to quickly build applications without worrying about the underlying infrastructure. In this post, you have seen an example of this by building a fun, simple IoT project to enhance the experience of your Airbnb guests and to make your job as a host more convenient. You can expand this to other use cases such as opening your garage door, tracking common household medications or products, or even unlocking or starting a car. With AWS and the IoT button, the possibilities are almost endless!