How to trigger IFTTT actions from IoT Hub messages

Quick & Easy application creation with IoT Hub and IFTTT

IFTTT stands for “If This, then That”. It is an easy to use yet powerful automation service where you can choose to perform an action upon an event. There are thousands of events and actions available and customizable. This is awesome.

In this article we will show you how to quickly build a simple reporting application which stores your devices data in a Google sheet.

There are three steps to achieve this:

  • Create an IFTTT account and set up an applet
  • Set up an IoT Hub and an IoT Route to the IFTTT applet
  • Publish messages on the IoT Hub and see the data flowing to your Google sheet

Create an IFTTT account and set up an applet

1 . Sign up to IFTTT. When done click on the create button to start building your applet.

2 . Choose Webhooks: Receive a web request as the “If This” trigger. Type in iot_event as the event name and create the trigger.

3 . Choose Google Sheets: Add row to spreadsheet as the “Then That” action. We’ll use default settings, just create the action without changing them.

4 . Click on the continue button

5 . Choose a title, such as Scaleway IoT Hub to Google Sheet as your applet name and click Finish. You’re done with the applet.

Now the applet is set-up, we need to find our webhook key, head to your webhook settings, you will find there an URL like<key>. Write down the key part, we’ll use it later.

Creating an IoT Hub and setting up the IoT Route

Now that we have our IFTTT applet ready, we need to create an IoT Hub. This will be where our simulated IoT Device will publish messages to trigger our IFTTT applet.

1 . Please follow this procedure to create an IoT Hub. Select your name and plan of choice, and click the Create Hub button.

2 . Head to the Routes tab of your IoT Hub.

3 . Create a new route with the following settings:

  • Name: anything you’d like (ex: IFTTT Route)
  • Topic: This will be the topic to publish to from your Device, let’s use my/data
  • Route type: REST Query
  • Verb: POST
  • Endpoint:<key> where <key> is the key you got from IFTTT earlier.
  • HTTP Headers: Content-Type: application/json

Now that we have everything set up, let’s add a Device and send a message from there.

Adding a Device a triggering the IFTTT applet

In your Scaleway Console, head to the Devices tab of your IoT Hub. From there, to add a new Device, give it any name and pick the Allow insecure connection option (you don’t want to do that in production, but this is fine for this tutorial’s purpose). Click the Add button, and, finally, the Close button.

Now your Device appears in the Device list, click on it and then on the MQTT Webclient button to simulate a real device.

In the Topic field write my/data (which is the topic we chose for the IoT Route). In the Message field write { "value1" : "Hi", "value2" : "from", "value3" : "Scaleway!" }. Then click the Publish button (no confirmation will be issued).

The message published on my/data topic will be received by the IoT Route and forwarded to the IFTTT Webhook trigger, which will save the values in the Google sheet.

Now head to your Google sheet home page, open the IFTTT_Maker_Webhooks_Events spreadsheet, and voila. You can even see data flowing in live when publishing more messages!

We're done!

We hope you had fun collecting data from your IoT Hub to a Google sheet. This is one of the many possibilities the IoT Hub REST Route provides. Stay tuned for more REST Route usage examples.

Learn more about Scaleway IoT Hub, discover how to add Devices to the hub, check the IoT Hub metrics or get started in a few clicks with the IoT Hub Kickstarts.

Discover the Cloud That Makes Sense