Wednesday, February 21, 2018

If This Than That – Cloud service orchestration

IFTTT and other (Microsoft Flow, Zapier, Integromat) easily enable anyone to combine many cloud sIFTTTervices for task automation.
IFTTT is free and integrates many public cloud services, but it might seem limited in the combinations that can be created with it. Nevertheless I was surprised to see some nice examples that allow smart integration.

Control lights with planning:

I wanted to control my lights around the house, using a easy to manage planning (could be used to control central heating too). By combining the Google Calendar services and eWeLink IoT services, this was very easy and cheap, since only a Sonoff wifi relay had to be bought.
Within Google Calendar, I created a new calendar ‘Light-control’ with daily repeating events every evening to turn on the lights. Giving it a nice yellow color makes it very easy to get a clear overview.
Within IFTTT add a new applet with ‘if’ trigger Google Calendar ‘Any event starts’. The ‘then’ trigger can be set to eWeLink to switch on your Sonoff channel. Similar, another IFTTT applet can be created triggered on ‘Any event ends’ to switch off you Sonoff channel via the eWeLink Smart Home service.
By just updating your calendar events you can now very easily manage your IoT device planning. You can even ‘invite’ your lights to participate in a ‘meeting'. Just enable the Google Calendar option ‘Auto accept invites’ and put your calendar id (eg 123456789abcdefg@group.calendar.google.com) as a guest for your meeting and the light will switch on and off for your planned event.

Complex combinations

Sometime the one-on-one link that can be used for the service orchestration within IFTTT can be too limited. To enable complex combinations, apilio.io or switchur can be used.
As an example, using apilio.io, I wanted to be warned if frost would be expected tomorrow, to make sure I would protect my car windshield in time. But I want to get warned when arriving at home in the evening, to make sure I get notified while still in my car, while by default the Weather Underground service would provide the Weather forecast of tomorrow, early in the mornings.
First create you apilio.io account and register your IFTTT WebHooks settings.
Next, within apilio.io, I create 3 boolean variables:
  1. arriving_home
  2. evening
  3. frost_tomorrow
For each of these boolean variables, URL’s will be provided by apilio to set the value of the boolean to true or false using a unique webservice url.
Next, within IFTTT I created several applets:
1. IFTTT Location service:
  • applet if ‘You enter an areathen call the webhook url to set to ‘true’ the ‘arriving_home’ boolean
  • applet if ‘You exit an areathen call the webhook url to set to ‘false’ the ‘arriving_home’ booelan
  • applet if 17:00 (5pm) then call the webhook url to set to ‘true’ the ‘evening’ boolean
  • applet if 00:00 (0am) then call the webhook url to set to ‘false’ the ‘evening’ boolean
  • applet if ‘Tomorrow’s low drops below’ 4°C then call the webhook url to set to ‘true’ the ‘frost_tomorrow’ boolean
  • applet if ‘Tomorrow’s forecast calls for’ snow then call the webhook url to set to ‘true’ the ‘frost_tomorrow’ boolean
  • Since no trigger is available to set the boolean value ‘frost_tomorrow’ back on false, we will include in the apilio condition this value needs to be ‘changed’ at least within the last 24h. Weather Underground will typically provide the next day forecast at 7am.
4. IFTTT Webhook service (callback):
  • This webhook applet will be called by apilio to trigger a desired action when all conditions are met. The name of the applet is important, as it will need to be registered within apilio in order to call the right applet. If the applet is called, then a desired action can be triggered, eg showing a notification on your mobile.
Again within apilio.io, I created 3 conditions:
  1. at_home_condition –> linked to value of variable ‘arriving_home’
  2. evening_condition –> linked to value of variable ‘evening’
  3. frost_tomorrow_condition –> linked to value of variable ‘frost_tomorrow’ including the timestamp restriction the value has to be modified within 72000seconds.
Now, within apilio.io, a logic block can be created, linked to the 3 conditions created above. When all conditions are met, the IFTTT webhook can be called by apilio. The name of the IFTTT webhook callback applet created before needs to be provided. Enable the ‘Automatic evaluation’ to evaluate the conditions defined in the logic block whenever any of the condition values changes.
To test the complete setup, the different apilio URL’s to set the boolean values can be called manually to see if the resulting IFTTT webhook appled is called as soon as all conditions are met.
In this example, only boolean variables have been used, which makes the link between a variable and the condition within apilio very straightforward. But whenever needed string or numeric variables can be defined as well. The conditions related to these variables can get more complex evaluations, such as containing some values or smaller, equal, etc.
Feel free to comment or add extra ideas of interesting combinations that would be possible.
Update 19/12/2019: Since Apilio.io will soon become a paid only service, we're looking into moving all the logic to an alternative platform. sequematic.com and switchur are possible options.

Uodate 12/05/2021: As IFTTT started to ask much more money to their connected manufacturers and even high monthly fees to their users on top, I decided to completely move away from IFTTT. Too bad for the nice community they build up, but alternatives seem to have become very mature in the mean time. I wrote a long detailed post about my move towards the excellent free Home Assistant alternative.