IFTTT stands for IF This Then That, and is a free web service that allows users to build their own custom applets. In this article, we will learn how to build a custom applet that can be used with our Raspberry Pi. That is, how to connect to IFTTT, set up a Webhook within it, and how to trigger it. This can be used for a plethora of projects and applications, but for the purpose of this article let us assume that we want to build an applet that will send a notification to our phones if motion is detected. Please note that the applet is simply going to push notification if the event is True, not actually detect the motion for you. It is, therefore, a small part of a bigger application.
What is IFTTT?
IFTTT (If This Then That) is a free IoT service that allows you to send a trigger from one device/thing, and allow that trigger to make something happen elsewhere. In our example, the ‘this’ is the motion, and the ‘that’ is the notification. The exciting thing about IFTTT is the number of services available for use as triggers (THIS) or actions (THAT).
Now imagine combining that with the range of a Raspberry Pi! Considering the flexibility and range of programming with sensors and other components, you can let your imagination run wild. Making such projects come true is possible using IFTTT Webhooks service, which was specifically designed for custom applet makers. Webhooks can send and receive triggers via HTML POST and GET requests.
Hardware Requirements:
- Raspberry Pi with OS installed on SD card (available on the official website)
- Power cable
- Monitor
- HDMI connector
- USB or Bluetooth mouse
- USB or Bluetooth keyboard
- WiFi or Ethernet connection for internet
Setting up the IFTTT account and action:
1. Creating an account:
To create an IFTTT account, open the website (https://ifttt.com/join)
2. Creating an action:
To create an action, click on the profile option on the top right corner to open a drop down list.
On this list, click ‘Create’
3. Creating a Trigger
When you click create, it will open a page that looks like:
On this page, click on ‘+This’
4. Choosing the service
As mentioned earlier, we will be using Webhook service for the trigger for which we have to search and select the option called Webhooks from the list provided.
After selecting Webhooks, click on the Connect button
5. Selecting the Trigger
Some services provide more than one type of trigger, however Webhooks provides us with only one option.
Click on the option box that appears, as in the above picture.
6. Assigning an Event name
The trigger will be activated only if an event is true. We thus need to assign an Event name to the trigger.
7. Creating an action
We now have to select action service, to do this first press the ‘+That’ on the page
8. Selecting an action service
As discussed, we want a notification to be sent to our phone when there is motion detected, that is when the event is true the action should be a notification. Therefore, select the notification from the list provided
After this, press the Connect button to see the actions provided
9. Selecting the action
Since we are aiming to send only a simple notification to our phone, select the ‘Send a notification from the IFTTT app’ option
10. Write the notification that you want to send
IFTTT notifications are made to be customized, such that you can write the message that you want to see in the notification. After you click on the blue option box in the previous step you will see the message option open up in which you can type the text you want, and then click the ‘Create action’ button and then finish.
11. Finding the API keys
The Webhooks page should open on its own, if not double click on the icon. On this page, click on ‘Documentation’ (in the right hand corner).
12. Copying the Keys
When you open this page, the first line is the API Key.
The URL to which we must send the Webhook calls to is specified below Make a POST or GET web request to.
Using the IFTTT from your Raspberry Pi:
Make sure to update and upgrade your software before starting this. It is also assumed that you have python installed on your Pi with the code for your project, in this case for the motion detector.
1. Install the Python requests module
sudo pip install requests
2. Modify your code to include the following statements in the beginning
import time import requests
3. At the end of the script add the following line
requests.post('https://maker.ifttt.com/trigger/event name/with/key/apikey')
In the above line, make sure to replace the event name and apikey with the one you have entered and found respectively.
4. Install the IFTTT app on your smartphone
You have to download the app, from the Play Store or the App Store
5. Save and run your python code on the Raspberry Pi
When the event, here motion detection, is true – you will receive a notification on your smartphone.
And that is it! You have successfully created a well rounded project that will push notifications to your smartphone. This is an impressive project to build and is fairly easy as well. Exploring the bounds and possibilities that IFTTT can provide is an ocean of its own. So feel free to read through the services and try to use a few other ones that aren’t mentioned here.