The IFTTT (ang. If This Then That) offers plenty of useful applets, that allows to automate daily routines by creating simple logic rules. The webhooks applet paid our special atten- tion. What is the functionality of this applet? It’s really impressive! Based on the we- bhooks applet, the DOMIQ has been opened up to a whole new dimension of integration. This applet allows to send HTTP requests from the Base module to the IFTTT server and thus run created applets. There is also reversed functionality – the applet can send a HTTP request to the Base module and in result invoke any event. How does this affect Base functonality? Let’s just list a few of the most interesting features and new arrivals are still coming up:
- Invoking events in the Base module based on location of your mobile device.
- Integration with new devices, such as Philips Hue, Amazon Alexa, Nest thermostat andmany more.
- Integration with Google account, for example exporting any data available in the Base module to a spreadsheet, sending emails based on smart home events.
- Invoking events in the Base based on weather information.
- Integration with native functionality of the iOS/Android (calendar, contacts)
- Integration with Skype – sending messages as reaction to events in the DOMIQ system.
In this tutorial we will present how to send requests to the IFTTT server in order to trigger created applet. We will also show how to handle request sent from the IFTTT server.NOTE! Software version 1.9.0.1 or newer is required to realize funcitonality presented in this tutorial.
1. Integration with the IFTTT in the DOMIQ
As mentioned in the introduction, integration with the IFTTT is bi-directional. Base can re-ceive requests sent by IFTTT and also can send requests to the IFTTT server.
1.1. Sending request to the IFTTT serverFor this purpose we created a new identifier with the following syntax: IFTTT=ap- plet_name?optional_data.
As the applet_name, pass the name of the IFTTT applet to be called. The optional_data
part as name suggest is optional and can be omitted if the applet does not require any additional data. Based on the data provided, Base will automatically create and send a HTTP request to the IFTTT server.
1.2. Receiving HTTP requests from the IFTTT
To receive HTTP requests from the IFTTT server, public IP address is required. If you only have a dynamic public IP address, then use dynamic DNS. You’ll also need to redirect port in router settings to point local IP address of your Base module and port number that matches value of the Web Port parameter (default is 80) set in Base’s configuration (the Settings tab).
Requests received from the IFTTT will be dispatched as events: E.IFTTT.request = data. Data passed in the request can be any – it can be a string, a number, etc. The event can execute any sequence of commands in Base. Later in this tutorial we will show how to use the location applet to trigger an event in Base.
In the next step you need to set admin access in Base’s configurator. To do this open the Users tab and set the Admin Access option to Whole internet.
2. IFTTT account
First necessary step is registration in the IFTTT (it’s free of charge). After that you will re-
ceive unique user key that will be used to call applets.
After receiving the key, log in to the Base’s configurator and go to the Settings tab. Then find the IFTTT section, select the Active checkbox and paste the received key in the box below. Finally, save the Settings tab and restart the Base module. Upon restart, Base is ready to work with the IFTTT.
3. Creating applets
Creating applets is very intuitive and follows the principle “If This, Then That”, exactly as the service name suggests. First step is to select an event that will trigger the applet and then action that will be executed as result of running the applet.
OK, it’s time to create the first applet. The applet will be invoked when the IFTTT server receives a HTTP request sent by a DOMIQ/Base module. The request will be sent perio- dically using a timer set in Base. As an example, we will show how to send data from the outdoor temperature sensor connected to the recuperator. Data will be sent to a Google Drive spreadsheet for archiving and presentation on a graph.
1. Log in to your IFTTT account and click on the MyApplets, then click the NewApplet. Next, click the +this to define an event that will run the applet.
2. You’ll see long list of applets that can serve as an initiating event. We need the we- bhooks applet, so in the search box start typing webhooks. The IFTTT will begin to fil- ter matching results based on entered text.
3. In the next step select the only available option: Receive a web request. This option assures that the applet will be triggered when the IFTTT server receives valid HTTP request.
4. In the Event Name enter unique applet name. This name will be used later for calling the applet. So use as short and simple name as possible. In our case we used the temperature.
5. Click on the +that to define an action that will be executed as a result of running of the applet.
6. In the search box enter google and then choose the Google Drive.
7. In the next step choose the Add row to spreadsheet.
8. In the next step define the details of adding data to a spreadsheet. In the Spread- sheet name field, enter the name of the spreadsheet. This name will be used to create a file on your Google Drive. In the Formatted row box enter the format that will be used to format data saved in the spreadsheet. Click on the Add ingredient button to see the list of available parameters:
- OccuredAt-dateandtimeofaddinganewentryinthefollowingformat:Septem- ber 1, 2017 at 08:45AM
- EventName – The name of the event in the IFTTT service. In our example temperature.
- Value1, Value2, Value3 – values that can be passed as parameters of a HTTP re- quest. In our case we use only the Value1 parameter to pass temperature.
In the Drive folder path enter the path in the Google Drive where the spreadsheet should be saved. Finally, click Create action to confirm the settings.
9. In the last step, you can review the summary of the applet you are creating. If every- thing is set correctly, then create the applet by pressing the Finish button. If you want to receive a notification each time the applet is executed, set the Receive notifica- tions when this Applet runs enabled. You need to install the IFTTT app on your iOS or Android device to receive notifications.
4. Invoking IFTTT applets in the DOMIQ
In order to invoke the IFTTT applet use the following command: IFTTT=ap- plet_name?optional_data
Let’s go back to our example of sending temperature to a Google Drive spreadsheet. As the next step we will define a timer in Base that periodically sends data to IFTTT. In our case, the timer will send data every hour.
- Add a timer.
- In the Minute field enter: 0 (calling every full hour).
- In the Actions section click on the Add command… button.
- In the Name field enter: C.IFTTT. In the Value field enter: temperature?value1={MOD- BUS.int.vent.outtemp}
At this point we will stop for a while and discuss each part of the command. The tem- perature part is the name of the applet that the timer will invoke.The question mark se- parates the optional data part. In our case we need to pass temperature value and we will use the optional parameter to do that. The following expression does the job: ?va- lue1={MODBUS.int.vent.outtemp}. The MODBUS.int.vent.outtemp is the name of the MODBUS register that stores current value of outdoor temperature.The {identifier} syntax is new functionality in the DOMIQ, which was introduced in the system update to version 1.9.0.1. This new functionality is called dynamic bin-ding of identifiers. In software version 1.9.0.1, it was added to the Events and Ti- mers tabs and will be systematically added to the other tabs of the configurator. The {identifier} expression should be understood as a dynamic reference to a identi- fier in Base to retrieve its current value. In our example we want to pass current valueof outdoor temperature each time the timer is executed. Until now, it would require writing the code in the Logic tab. From now on, you can easily reference any identifier to dynamically pass its value to the timer or event you are creating.Example: Suppose the outside temperature is 18.9°C and it’s stored in the MOD- BUS.int.vent.outtemp identifier. The ?value1={MODBUS.int.vent.outtemp} expression will be automatically converted by the Base at the time the timer is called to: temperature?value1=18.9. - Save the Timers tab to apply changes.
5. Handling IFTTT applets in DOMIQ
As mentioned in the chapter 1, the Base module can receive requests sent from the IFTTT server. It’s dispatched as event in the following format: E.IFTTT.request=data. As an example of this functionality, we will present the Location applet, that can be called when user enters or leaves given location. In our example, we will use this applet to initia- lize an event for residents returning home.
5.1. Applet configuration
1. LogintoyourIFTTTaccountandclickontheMyApplets,thenclicktheNewApplet.
Next, click the +this to define an event that will run the applet.
2. In the search box type: location.
3. In the next step, choose the You enter an area, as the event is to be triggered when user enters the location.
4. Specify the location.
From our experience, we recommend to install the IFTTT app for mobile devices to fine- tune the location once the applet is created. The mobile app allows you to pinpoint a lo- cation based on the current location of your mobile device. This way you can, for exam- ple, you can define the applet to run when you enter the property.
5. Click on the +that to define an action that will be executed as a result of running of the applet.
6. In the search box enter webhooks.
7. Choose the only available option – Make a web request, which means that each time the applet is called, it will send a HTTP request to a given address.
8. In the next step define the address to which the request will be sent. In our example, we entered: http://example.com/call/ifttt/home. The example.com has to be replaced with the public IP address of the Base or dynamic DNS address. The /call/ifttt/ part is mandatory and must be included in every request sent from the IFTTT to the Base module. The last part of the address, in our case home, is the data that will be passed to the Base module. The data will be passed within the E.IFTTT.request
event (see description of event definition in next subsection). Leave the GET value in the Method field. The rest of the options can be omitted.
9. In the last step, you can review the summary of the applet you are creating. If every- thing is set correctly, then create the applet by pressing the Finish button. If you want to receive a notification each time the applet is executed, set the Receive notifica- tions when this Applet runs enabled. You need to install the IFTTT app on your iOS or Android device to receive notifications.
5.2. Event configuration
Finally we can define event for returning home.
- Navigate to the Events tab and add an event.
- In the Channel field enter: E.IFTTT.request.
- In the Data field enter the name that used in applet definition. In our example: home.
- To avoid multiple (unwanted) event calls (eg when another resident returns home), a condition must be added to prevent this. If a Satel control panel is present in your in- stallation, you can use the state of the an alarm zone to determine the presence of re- sidents. However, if you do not have a Satel control panel in your installation, then you can choose one of the alternatives:
- Set a MEM variable or a virtual LCN relay based on motion sensor ( no motion detected for a specified time would be interpreted as the absence of re- sidents at home). In this case, any number of sensors can be used to set a MEM or a virtual relay.
- Define a wall button, which when pressed when leaving the house will set a virtual LCN relay or a MEM variable.
- Finally, in the Actions section, define the sequence of actions you want to perform as a procedure for returning home.
In this tutorial we have just presented two examples of many possible applicaitons of inte- gration with the IFTTT. We hope that with this functionality, your smart home will be even more tailored to your needs.