Making IFTTT (If This Then That) talk to Node-RED

IFTTT (short for “If This Then That”) is a popular service which lets you trigger actions based on certain events that occur around the Internet. It is missing an important functionality (IMHO), namely WebHooks. A WebHook is an HTTP callback: an HTTP POST that occurs when something happens; a simple event-notification via HTTP POST. I explain this missing functionality with their business model as they make money from the vendors that want their products connected there. Such functionality has been requested for ages now, but won’t be made available anytime soon, in my view.

There is a nice work-around though (shhh), a webhook middleware for the IFTTT service, made possible by simulating a WordPress blog channel. IFTTT uses wordpress-xmlrpc to communicate with the WordPress blog. It presents a fake-xmlrpc interface on the web address, which causes IFTTT to be fooled into thinking of this as a genuine WordPress blog. The only action that IFTTT allows for WordPress is posting, which is used for powering WebHooks. All the other fields (title, categories) are passed along by the WebHook.

I’ve set up my WordPress channel and couple IFTTT recipes to try it out:wordpress ifttt

 

The recipe is set as follows, below is an example of geofencing via the “Android location” channel, but it could be any other IFTTT channel as long as you supply unique identifier in the ‘category’ property so that Node-RED can parse it out:

wordpress ifttt recipe

 

The recipe basically says that if I enter or leave the outlined area, IFTTT should make a HTTP POST to my home automation system running Node-RED. That could be even simpler, for example making a HTTP API POST to switch on / off my WiFi connected relay board for example, but lets make it more fancy.

The real world is more complex than “If This Then That” and this is the weakest point of IFTTT. Without some scripting and more complex conditions, it is just an eye-candy service for newbies. For example, I’d like to switch Internet connected thermostat on or off based on my and wifey’s location. If both of us aren’t at home (more than 1 km away), we could decrease room thermostats by couple degrees; Upon re-entering the geo fenced area, the thermostats could be turned up. If both of us are more than 50km away from home, thermostats and heating/cooling can be switched off completely. This sort of conditions can only be triggered by more complex logic, and this is where Node-RED comes in.

Below is a Node-RED template that captures incoming IFTTT posts, routes them based on recipe’s  ‘category’ property and acts upon the geofencing event (entry/exit):

wordpress ifttt node-red

[{"id":"1bcd1a89.e432e5","type":"http in","name":"","url":"/iftt","method":"post","x":138,"y":194,"z":"289137bb.d76ec8","wires":[["b3f11a1.f4c0ee8","b038baf8.4fc748","1628045a.e9d7fc"]]},{"id":"b3f11a1.f4c0ee8","type":"http response","name":"","x":316,"y":181,"z":"289137bb.d76ec8","wires":[]},{"id":"1628045a.e9d7fc","type":"switch","name":"Route by event type","property":"payload.categories","rules":[{"t":"eq","v":"area"}],"checkall":"true","outputs":1,"x":329,"y":244,"z":"289137bb.d76ec8","wires":[["5ebd113c.a142f"]]},{"id":"b038baf8.4fc748","type":"debug","name":"","active":true,"console":"false","complete":"false","x":610,"y":146,"z":"289137bb.d76ec8","wires":[]},{"id":"2a05b045.d5fa5","type":"comment","name":"Capture IFTTT HTTP post","info":"","x":189,"y":77,"z":"289137bb.d76ec8","wires":[]},{"id":"5ebd113c.a142f","type":"function","name":"Breakdown location change payload","func":"var tmp=msg.payload.title.split(\"|\");\nmsg.action=tmp[0];\nmsg.occuredat=tmp[1];\nreturn msg;","outputs":"1","valid":true,"x":385,"y":299,"z":"289137bb.d76ec8","wires":[["1e9f59f1.e160a6","b038baf8.4fc748"]]},{"id":"1e9f59f1.e160a6","type":"switch","name":"","property":"action","rules":[{"t":"eq","v":"entered"},{"t":"eq","v":"exited"}],"checkall":"true","outputs":2,"x":296,"y":355,"z":"289137bb.d76ec8","wires":[["9c9c8908.636378"],["c2a8da6c.3d5728"]]},{"id":"c2a8da6c.3d5728","type":"function","name":"Act upon area exit","func":"msg.url=\"http://*****/control/relay.cgi?relay1=0\"\nreturn msg;","outputs":1,"valid":true,"x":483,"y":425,"z":"289137bb.d76ec8","wires":[["28952f7e.d76ad"]]},{"id":"9c9c8908.636378","type":"function","name":"Act upon area entry","func":"msg.url=\"http://*****/control/relay.cgi?relay1=1\"\nreturn msg;","outputs":1,"valid":true,"x":489,"y":360,"z":"289137bb.d76ec8","wires":[["28952f7e.d76ad"]]},{"id":"28952f7e.d76ad","type":"http request","name":"Make HTTP API request","method":"GET","ret":"txt","url":"http://","x":727,"y":384,"z":"289137bb.d76ec8","wires":[[]]}]

The flow can be extended to act upon different incoming triggers, those need to be set in the ‘category’ property so it can differentiate and apply different rules.

In conclusion, while I am  mostly negative about IFTTT, it can be used to easily interface with other connected things.

Page views: 38280

2 thoughts on “Making IFTTT (If This Then That) talk to Node-RED

    • IFTT is cloud based solution, has some advantages, whereas Tasker runs on your device and is more flexible.. I guess it boils down to the specific need you are trying to address

Comments are closed.