To download NI software, including the products shown below, visit ni.com/downloads.
Demonstrates the use of the HTTP Post VIs to interact with and generate triggers for If This Then That (IFTTT) web services.
IFTTT stands for If this then that. The this and that can be quite freely selected from a range of services. For example, you can select a weather channel for 'this' and a phone notification for 'that'. But just as easy you can trigger your NEST thermostat, or Philips Hue lights.
In the attached example you will find LabVIEW code to send a trigger (the this) using HTTP POST methods to the IFTTT Maker service. Additional parameters can be sent in JSON format using the HTTP POST Multipart.vi,
In the additional information section is explained how to receive actions from the IFTTT using LabVIEW web services.
Hardware: none. The code can be executed on desktop or real-time targets (i.e. CompactRIO or myRIO).
Software: LabVIEW 2012 Base Development System “or compatible”
If This Then That website: www.ifttt.com
More information about IFTTT
IFTTT defines the following terms:
- applets (recipes)
- events (triggers)
- actions
- ingredients
Recipes are a combination of a trigger and an action. There can only be one trigger and one action. The trigger gives the IFTTT a signal when to run the recipe (it is the 'this' part). If the trigger is received, the IFTTT does the action (that). Using recipes is an easy way to automate a lot of tasks.
Ingredients are the variables (up to three) that you can sent with a trigger to pass on to the action.
There are pre-built actions and triggers for many devices. To connect from LabVIEW you can use the 'Maker channel'. It can be run on desktop but also on embedded devices like CompactRIO, single-board RIO and myRIO.
Triggering an event — creating the “if” of IFTTT — is simple. All you need to do is send a GET or POST web request with an event name and secret key — the key is assigned when you create the channel — of the form:
https://maker.ifttt.com/trigger/{event_name}/with/key/{secret_key}
with an optional JSON body consisting of up to three values, or strings, to be passed on to the action in your recipe.
Getting started step-by-step
First you have to go to the IFTTT site and sign up for a free account, using an email address and password.
Once you've done this, you can create a recipe. Let's create a recipe that will sent a notification to my phone when the temperature in a boiler room exceeds a threshold, measured by LabVIEW. Here's how:
- In the main screen of IFTTT click on 'my applets',
- Click 'new applet'
- click on '+this' in the applet maker to select the trigger
- As you can see there are dozens of triggers. In the 'search channel' type 'maker' and select the maker channel. The maker channel allows you to trigger IFTTT from almost any custom device or application.
- choose a trigger: click 'receive a web request'
- give the trigger event a name (which you will need to use in the LabVIEW application later); i.e. Boiler_Trigger
- now select 'that' to specify an action.
- there are many actions available, like creating a line in google docs, calling a phone, sending an TEXT/SMS message, turning on lights, but let's select 'notification' (type notification in the search window).
- Click 'sent a notification'
- Fill in the action field. Optionally add ingredients.
Click create action and finish.
You will also need the 'secret key'. It has been given to you along the process, but if you have missed it, navigate to 'my applets>maker>settings'. The page will show you your settings, along with a URL. Copy the URL and remove the part 'https://maker.ifttt.com/use/'
The LabVIEW example uses HTTP Post Multipart. Make sure you set the mime encoding to 'text/JSON' if you are sending additional ingredients.
Receiving Actions from IFTTT Maker Service
Receiving actions from recipes — the “that” of IFTTT — is quite straightforward. You need to provide and endpoint, a web address or URL in other words, for it to call. The recipe can take the form of a GET, POST or DELETE request, and can optionally contain variables and content. You can pass data — possibly the data provided by the triggering service, or device — to your remote web service.
The easiest way to get started is to open the web service example that ships with LabVIEW, or the one that is linked in the additional information section below. Put a breakpoint or popup in the code that is called by the web service. When you deploy the web service take note of the URL. If you're behind a firewall or router, you will need to map the port of the firewall to your device and setup port forwarding in the router, and use the IP address of the router in the IFTTT endpoint configuration.
More information on getting started with web services on real-time targets:
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
Great program and Simple Trigger works great. However, Trigger with Ingredients doesn't appear to pass on the values. The IFTTT applet reports "None" for all three values. The vi is locked so there is no way to check the text/JSON MIME type. The data fed into POSTMultipart.vi starts with {{Name => "value1", Value => "123", File => "", Filename => "", MIME type => "text/JSON"}, etc. Not sure if that is correct. The IFTT Maker Webhooks page lists a different string format for values. Any way to fix the IFTTT LabView vi?