Skip to main content

Using iRidi with IFTTT

General instructions for configuring iRidi to work with IFTTT

IFTTT lets you connect two cloud services. There are many examples of using this platform to control smart home devices remotely.

Consider the 2 most commonly used ways to work with IFTTT:

  1. Activating an IFTTT trigger when a smart home device is activated.

Example. When a smart door lock opens, an email notification is sent.

  1. Activating a device when an IFTTT trigger fires.

Example. When a new email arrives, a light should turn on.

The examples below describe how to configure these methods.

Important

Working with IFTTT requires iRidi Server and a continuous Internet connection.

Activating an IFTTT trigger when a smart home device is activated​

Configuring Webhook​

  1. Open the IFTTT website and sign in
  2. After signing in, click your account and select New Applet from the menu

IFTTT_1.png

  1. The standard form appears. Click +this

IFTTT_2.png

  1. Find and select Webhooks in the list that appears

IFTTT_3.png

  1. To create a trigger, select Receive a web request

IFTTT_4.png

  1. Specify an event, for example, door_opened, and create the trigger
  2. Click +that and select what should happen when the door_opened event occurs

IFTTT_5.png

In this example, when the door_opened event occurs, we receive an email notifying us of the event.

  1. To do this, select Gmail

IFTTT_6.png

  1. Select Send yourself an email. An overview of the trigger appears. Review it and click Finish to complete setup

IFTTT_7.png

You can test the trigger. To do so, open Webhooks

IFTTT_8.png

Then open the Documentation page

IFTTT_9.png

On this page, you can create a request. In the {event} field, enter the event name (door_opened in this example) and run the test using the test button.

IFTTT_10.png

Note

This page also shows your unique key, which you will need later to configure the iRidi project.

Configuring the iRidi Pro project​

  1. Create a server project
  2. Add the AV&Custom Systems (HTTP) driver to it

IFTTT_11.png

  1. Configure it as shown below

IFTTT_12.png

  1. Add a virtual channel named Event

IFTTT_13.png

  1. Create a new script in the project and add the following
IR.AddListener(IR.EVENT_START,0,function(){

var IFTTT_Token = "your key"; //сюда вписываем секретный ключ Webhook (берем его из раздела документации к Webhook)
var IFTTT = IR.GetDevice("IFTTT (Custom HTTP (TCP))"); //имя драйвера

IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(in_sName, in_nValue){
IFTTT.Send(["GET,/trigger/"+in_nValue+"/with/key/"+IFTTT_Token+"/"]);
});
IR.SubscribeTagChange("Server.Channels.Event"); //имя виртуального канала

IR.AddListener(IR.EVENT_RECEIVE_TEXT, IFTTT, function(text) {
IR.Log(text);
});

});
  1. In IFTTT_Token, enter the key you obtained on the Webhook documentation page

  2. Add and configure the drivers you will use (this example uses Modbus TCP)

IFTTT_14.png

  1. Configure status feedback for the devices

IFTTT_14_1.png

  1. Create a rule that triggers the Webhook event:

When=> the driver tag receives a signal that the door is open

IFTTT_15.png

Then=> send text containing the event name to the virtual channel

IFTTT_16.png


Note

Enter the same event name as in the Webhook trigger

IFTTT_17.png

Now, when the door opens and the tag receives a value, the rule runs and informs Webhook that the door_opened event has occurred. An email notification is then sent.

Activating a device from an email in Gmail​

Note

Like the first method, this method can also use Webhook

To activate a device, you can create an IFTTT trigger that sends an email to Gmail with the event name in its subject.

For example, the light should turn on when an email with the subject light_on arrives, and turn off when an email with the subject light_off arrives.

Configuring Gmail​

  1. Open Google Apps Script
  2. Click Start Scripting

IFTTT_18.png

  1. Click New script

IFTTT_19.png

  1. Insert the following script:
function doGet(in_sResponse) 
{
var l_sToken = ""; //впишите сюда ключ, который будете знать только Вы
var l_aEvents = in_sResponse.parameter.name.split(' ');
var l_nMailCount = 0;
var l_Object={};
var l_Response = Gmail.Users.Messages.list('me');

// Go through all the messages
for(var iMsg in l_Response.messages)
{
l_nMailCount++;
var l_nMessageID = l_Response.messages[iMsg].id;

var l_Message = Gmail.Users.Messages.get('me',l_nMessageID);

if(l_Message)
{
// Go through all the message headers
for(var iHeaders in l_Message.payload.headers)
{
if(l_Message.payload.headers[iHeaders].name == "Subject")
{
// Check for the presence of headers in events
for(var i = 0;i < l_aEvents.length;i++)
{
if(l_aEvents[i] == l_Message.payload.headers[iHeaders].value)
{
if(!l_Object[l_aEvents[i]])
l_Object[l_aEvents[i]] = l_nMessageID;

Gmail.Users.Messages.trash('me',l_nMessageID)
}
}
}
}

// Work with a maximum of 5 letters
if(l_nMailCount==5){break}
} else
break;
}
return ContentService.createTextOutput(JSON.stringify(l_Object));
}
Note
  • Create a unique key and enter it in the var l_sToken variable so that nobody else can use this functionality. You will need to include it in the email body later.
  1. Save it by clicking the IFTTT_20.png icon or pressing Ctrl+S, and give it any name
  2. Gmail API must be enabled. To do this, open Resources/Advanced Google services...

IFTTT_21.png

  1. In the list that appears, find Gmail API and enable it.
  2. A notice below the list says that this service must also be enabled in the dashboard. Follow the link

IFTTT_22.png

  1. Complete the form and click ACCEPT.

IFTTT_23.png

  1. On the page that appears, click ENABLE APIS AND SERVICES

IFTTT_24.png

  1. Find and select Gmail API in the list

IFTTT_25.png

  1. Enable it

IFTTT_26.png

  1. In the window that appears, click CREATE CREDENTIALS

IFTTT_27.png

  1. Complete the form as shown below

IFTTT_28.png

  1. The system requests permission to access your data.

IFTTT_29.png

  1. Click Review Permissions to open a new window. Select your account, click Advanced, and follow the link to the app at the bottom of the message

IFTTT_30.png IFTTT_31.png

  1. Click Allow
  2. Now that the script has permission to access Gmail data, publish it. To do this, open Publish/Deploy as web app...

IFTTT_32.png

  1. Complete the form as shown below

IFTTT_33.png

Note

A window then appears showing a URL. You will need it for further work in iRidi Pro. Copy it starting from /macros .

IFTTT_34.png

Configuring the iRidi Pro project​

  1. Create a server project
  2. Add the AV&Custom Systems (HTTP) driver to it

IFTTT_11.png

  1. Configure it as shown below

IFTTT_12.png

  1. Add another AV&Custom Systems (HTTP) driver. Configure it as shown below

IFTTT_35.png

  1. Add a virtual channel named Event and a virtual tag named Event_Out

IFTTT_36.png

  1. Create a new script in the project and add the following
IR.AddListener(IR.EVENT_START,0,function(){

var IFTTT_Token = "your key"; // сюда вписываем секретный ключ Webhook (берем его из раздела документации к Webhook)
var Script_google_URL = "/macros/____________"; // URL из последнего шага настройки Gmail
var Event = "light_on+light_off"; // название событий (прописывается в теме письма)
var Interval = 10000; // интервал между запросами к Gmail

//-------------------------------------------------------------------------
var IFTTT = IR.GetDevice("IFTTT (Custom HTTP (TCP))");
var Script_google = IR.GetDevice("script_google");

IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(in_sName, in_nValue){
IFTTT.Send(["GET,/trigger/"+in_nValue+"/with/key/"+IFTTT_Token+"/"]);
});
IR.SubscribeTagChange("Server.Channels.Event");

IR.SetInterval(Interval, function (){
if(Script_google_URL!=""){
Script_google.Send(["GET,"+Script_google_URL+"?name="+Event]);
}
})

IR.AddListener(IR.EVENT_RECEIVE_TEXT, IFTTT, function(text) {
IR.Log("IFTTT "+text);
});
IR.AddListener(IR.EVENT_RECEIVE_TEXT, Script_google, function(text) {
if(text.substr(0,1)=="{"){
var oText = JSON.Parse(text);
for(key in oText){
IR.SetVariable("Server.Tags.Event_Out", key);
IR.Log('Successful: '+key);
}
}
});
});
  1. In IFTTT_Token, enter the key you obtained on the documentation page for Webhook;
  2. In Script_google_URL, enter the URL you obtained in the last step of Gmail configuration;
  3. In Event, enter the name of the event that should activate the device.
Note
  • Event names must be specified in the subject of the email sent to Gmail.
  1. Add and configure the drivers you will use (this example uses Modbus TCP)

IFTTT_14.png

  1. Create a rule:

When=> the virtual tag Event_out receives the event name from Gmail

IFTTT_37.png

Note
  • Enter the event name you will use in the email subject

Then=> send a command to the device

IFTTT_38.png

IFTTT_39.png

Tip

download:

Testing​

  1. Upload the project to the server
  2. Send an email to the Gmail address where the Google script is configured

IFTTT_40_1_1.png

Note
  • Specify the event name, for example, light_on, in the email subject.
  • In the email body, enter the unique key you specified in the var l_sToken variable in the Google script.

Wait for the event to occur according to the interval set in your project script. A notification appears in the server window indicating that the event has occurred, and the device executes the command.

IFTTT_40.png

Using IFTTT in iRidi lite​

You can configure iRidi lite to work with IFTTT through the Gmail module. The Gmail module lets you set up email notifications for various events and create a scenario for controlling equipment by email. You then only need to connect Gmail to any other cloud service available in IFTTT.

Note
  • Working with IFTTT requires an Internet connection and a Google account.
  • Using iRidi Server is recommended.

Consider 2 examples of using this service:

  1. Sending an email notification when a smart home device is activated.

**Example. ** When a leak sensor is activated, send an email notification.

  1. Activating a device when an email arrives.

**Example. ** When a new email arrives, turn on the heating/air conditioning system.

The following examples describe how to configure an iRidi lite project.

Configuring the Gmail module​

  1. Add the Gmail for Server module to the project.

IFTTT_41.png

  1. Set the interval at which the module checks Gmail for new emails. Tap Add.

IFTTT_42.png

  1. Open the module and sign in.

IFTTT_43.png

IFTTT_44.png

In the browser window that opens, click Advanced and, in the information that appears, follow Go to iridiummobile.net (unsafe)

IFTTT_45.png

In the window that appears, click Allow .

Module setup is now complete, and you can proceed to configure scenarios.

Sending a notification when a smart home device is activated​

Consider the first example: sending an email notification when a leak sensor is activated.

To do this, open the Routines section and create a new server rule. (Working with rules)

Under WHEN, configure activation of the leak sensor:

IFTTT_46.png

In the actions, configure sending an email through the Gmail module:

Specify the destination email address, subject and message body

IFTTT_47.png

IFTTT_48.png

The completed rule looks as follows:

IFTTT_49.png

Setup is now complete, and you can test the rule. When the sensor contacts close, an email notification is sent to the specified address.

Activating a device when an email arrives​

Consider the second example: turning on the heating system when a new email with a specific subject arrives.

To do this, open the Routines section and create a new server rule. (Working with rules)

Under WHEN, configure the Gmail module to check for new emails with a specific subject:

IFTTT_50.png

In the subject, specify the event name and, if necessary, a secret key known only to the user:

IFTTT_51.png

IFTTT_52.png

In the actions, specify the heater temperature or mode.

IFTTT_53.png

The completed rule looks as follows:

IFTTT_54.png

Setup is now complete, and you can test the rule. When an email with a specific subject is sent to the account authorized in the Gmail module, the rule runs and activates the device.