React to Channel Activity with Notification from IFTTT

This example shows how to use the React app to trigger an HTTP request to IFTTT in ThingHTTP. Using the analytical power of MATLAB®, you can generate filtered, targeted, and specific notifications of channel activity from ThingSpeak™ data. IFTTT is an external web service that lets you create applets that act in response to a trigger action.

Channel 379984 logs home temperature values. In this example, you receive a notification when the temperature falls below 50 degrees so that seedlings getting ready for the garden in spring are not damaged.

Create an IFTTT Applet

IFTTT is a web service that lets you create applets that act in response to another action. You can use the IFTTT Webhooks service to create web requests to trigger an action. The incoming action is an HTTP request to the web server, and the outgoing action is notification in the IFTTT app on your device.

1) Create an IFTTT account if you do not already have one. Log in to your account.

2) Create an applet. Select your user icon, and then click Create.

3) Select the input action. Click the word this.

4) Select the Webhooks service. Enter Webhooks in the search field. Select the Webhooks card. After you select Webhooks as the trigger, click the Receive a web request card to continue.

5) Complete the trigger fields. Enter an event name. This example uses TooCold as the event name. Click Create Trigger.

6) Select the resulting action. Click the word that. The trigger word this is now the Webhooks icon.

7) Enter notification in the search bar, and click the Notifications box. Then select Send a notification from the IFTTT app.

7) Click Create action to finish the new applet. For this example, the name of the event is TooCold. IFTTT will pass this name of the event where the variable {{EventName}} ocurs in the message. You can also pass data about the event that triggered your message using ingredients. For example, including {{OccurredAt}} adds the event time to your notification.

8) Retrieve your Webhooks trigger information. Select My Applets > Services, and search for Webhooks. Select Webhooks, and then click the Documentation button. You see your key and the format for sending a request. Enter the event name. The event name for this example is TooCold.

https://maker.ifttt.com/trigger/{event}/with/key/XXXXXXXXXXXXXXXXXXXXXX
https://maker.ifttt.com/trigger/TooCold/with/key/XXXXXXXXXXXXXXXXXXXXXX

You can test the service using the test button or by pasting the URL into your browser. Note that the IFTTT event trigger is not always instantaneous.

Create a ThingHTTP

To complete the trigger request, create a ThingHTTP. The ThingHTTP app lets you trigger predefined HTTP requests with an API key and a GET request from the web or from a device. For this example, use ThingHTTP to trigger Webhooks at IFTTT.

1) Choose Apps > ThingHTTP, and select New ThingHTTP.

2) Edit your ThingHTTP settings.

  • Name - Name your ThingHTP.

  • URL - Enter the URL from the Webhooks documentation. The URL for this example has the form https://maker.ifttt.com/triigger/TooCold/with/key/xxxxxxxxxxxxxxxxxxxxxx.

  • Method - Enter GET.

3) To send custom values in your message from IFTTT, add value1=YOUR_VALUE to the Body field. Change YOUR_VALUE to the value or text you want to send.

4) Save the ThingHTTP.

Create a React to Your Data

Create a React to trigger the ThingHTTP based on your channel data. You must be the author of the channel used to create a react. If you wish to use the data from channel 379984, you must first set up a MATLAB analysis to regularly copy the data from the target channel to your channel. See collect data in a new channel, TimeControl app, and thingSpeakRead for more information on how to copy data from a channel on a regular schedule.

The React app can evaluate your ThingSpeak channel data and trigger other events. Create an instance of the React app that triggers when the house is too cold. Choose Apps > React, and then click New React.

  • Name - Name your React.

  • Test Frequency - Select On Data Insertion.

  • Condition - Select your temperature channel in the If channel list. You will not be able to create a react directly to the HomeTemp1 channel 379984, but you can create your own copy of the data in that channel.

  • Field - Select field 1, set the requirement to is less than, and set the temperature level to 50.

  • Action - Select ThingHTTP and choose the name of the ThingHTTP you defined previously.

  • Options - Select Run action each time condition is met.

Trigger Your Message

Once the temperature in the channel reaches the set point for your React, you receive a notification in the IFTTT app on your device.

Troubleshooting

If you do not receive the notification, you can try activating each component separately.

1) Trigger Webhooks at IFTTT from your browser. Copy the address from the Webhooks documentation to your browser address window to try triggering the event directly. If successful, IFTTT replies with "You have successfully triggered the TooCold event!"

2) Trigger your ThingHTTP using a REST API call. The format for the call is available on the help pane after you edit and save your ThingHTTP. Your ThingHTTP has a unique API key.

GET https://api.thingspeak.com/apps/thinghttp/send_request?api_key=XXXXXXXXXXXXXXXX

3) Trigger your React by writing data to your channel that fits the conditions specified in your React. For example, you can write a temperature of 49 degrees to field 1.

GET https://api.thingspeak.com/apps/thinghttp/send_request?api_key=XXXXXXXXXXXXXXXX&field1=49

See Also

Related Topics