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:
- Activating an IFTTT trigger when a smart home device is activated.
Example. When a smart door lock opens, an email notification is sent.
- 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.
Working with IFTTT requires iRidi Server and a continuous Internet connection.
Activating an IFTTT trigger when a smart home device is activated
Configuring Webhook
- Open the IFTTT website and sign in
- After signing in, click your account and select New Applet from the menu

- The standard form appears. Click +this

- Find and select Webhooks in the list that appears

- To create a trigger, select Receive a web request

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

In this example, when the door_opened event occurs, we receive an email notifying us of the event.
- To do this, select Gmail

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

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

Then open the Documentation page

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.
This page also shows your unique key, which you will need later to configure the iRidi project.
Configuring the iRidi Pro project
- Create a server project
- Add the AV&Custom Systems (HTTP) driver to it

- Configure it as shown below

- Add a virtual channel named Event
- 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);
});
});
-
In IFTTT_Token, enter the key you obtained on the Webhook documentation page
-
Add and configure the drivers you will use (this example uses Modbus TCP)
- Configure status feedback for the devices
- Create a rule that triggers the Webhook event:
When=> the driver tag receives a signal that the door is open
Then=> send text containing the event name to the virtual channel
Enter the same event name as in the Webhook trigger
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
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
- Open Google Apps Script
- Click Start Scripting

- Click New script

- 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));
}
- 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.
- Save it by clicking the
icon or pressing Ctrl+S, and give it any name
- Gmail API must be enabled. To do this, open Resources/Advanced Google services...

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

- Complete the form and click ACCEPT.

- On the page that appears, click ENABLE APIS AND SERVICES
- Find and select Gmail API in the list

- Enable it

- In the window that appears, click CREATE CREDENTIALS

- Complete the form as shown below

- The system requests permission to access your data.

- 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

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

- Complete the form as shown below

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

Configuring the iRidi Pro project
- Create a server project
- Add the AV&Custom Systems (HTTP) driver to it

- Configure it as shown below

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

- Add a virtual channel named Event and a virtual tag named Event_Out
- 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);
}
}
});
});
- In IFTTT_Token, enter the key you obtained on the documentation page for Webhook;
- In Script_google_URL, enter the URL you obtained in the last step of Gmail configuration;
- In Event, enter the name of the event that should activate the device.
- Event names must be specified in the subject of the email sent to Gmail.
- Add and configure the drivers you will use (this example uses Modbus TCP)
- Create a rule:
When=> the virtual tag Event_out receives the event name from Gmail
- Enter the event name you will use in the email subject
Then=> send a command to the device

download:
Testing
- Upload the project to the server
- Send an email to the Gmail address where the Google script is configured

- 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.

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.
- Working with IFTTT requires an Internet connection and a Google account.
- Using iRidi Server is recommended.
Consider 2 examples of using this service:
- Sending an email notification when a smart home device is activated.
**Example. ** When a leak sensor is activated, send an email notification.
- 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
- Add the Gmail for Server module to the project.

- Set the interval at which the module checks Gmail for new emails. Tap Add.
- Open the module and sign in.


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

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:
In the actions, configure sending an email through the Gmail module:
Specify the destination email address, subject and message body
The completed rule looks as follows:

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:
In the subject, specify the event name and, if necessary, a secret key known only to the user:
In the actions, specify the heater temperature or mode.
The completed rule looks as follows:

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.