Skip to main content

IFTTT

Latest Version: 1.0.0

IFTTT (If This Then That) is a service that allows you to easily connect triggers to actions across a plethora of products and services. This class allows an Electric Imp agent to trigger events on the IFTTT Maker Channel.

You can view the library’s source code on GitHub. Click here to see information on the available versions of this library.

To add this library to your project, add #require "IFTTT.class.nut:1.0.0" to the top of your agent code.

Class Usage

The IFTTT class provides three methods to send events to your IFTTT Maker Channel:

Constructor: IFTTT(secretKey)

To get a secret key, sign into your IFTTT account and then click "Connect" on the Maker Channel page. You will then be directed to a page that contains your secret key. Copy just this key as a string into the constructor.

#require "IFTTT.class.nut:1.0.0"

const SECRET_KEY = "YOUR SECRET KEY";
ifttt <- IFTTT(SECRET_KEY);

Class methods

Every method takes as its first parameter a name that is linked to a specific IFTTT recipe.

Each method may also take a callback that requires two parameters of its own: err and response. The response will always be the response object returned by httprequest.sendasync() and err will be non-null on HTTP errors.

sendEvent(eventName[, callback])

This method triggers an IFTTT event with no argument values.

// Trigger an event with no values and a callback
ifttt.sendEvent("something_happened", function(err, response) {
    if (err) {
        server.error(err);
        return;
    }

    server.log("Success!");
});

sendEvent(eventName, value[, callback])

Triggers an IFTTT event with one argument value.

// Trigger an event with one value and a callback
ifttt.sendEvent("something_happened", "red", function(err, response) {
    if (err) {
        server.error(err);
        return;
    }

    server.log("Success!");
});

sendEvent(eventName, valueArray[, callback])

Triggers an IFTTT event with up to three argument values, passed as an array. To leave a particular value blank, leave it out of the array or set it to null (see example below).

This method will throw an IFTTT.ERR_TOO_MANY_VALUES exception if more than three elements are placed in the valueArray parameter.

// Trigger an event with three parameters and a callback
// value1: red
// value2: **don't send**
// value3: banana
ifttt.sendEvent("something_happened", ["red", null, "banana"], function(err, response) {
    if (err) {
        server.error(err);
        return;
    }

    server.log("Success!");
});

Release History

The Electric Imp Dev Center documents the latest version of the library. For past versions, please see the Electric Imp public GitHub repos listed below.

Version Source Code Notes
1.0.0 GitHub Initial release

License

The IFTTT class is licensed under the MIT License.