Wednesday, June 24, 2015

Controlling my Air Purifier using IFTTT Maker and my Web server

Now that IFTTT Maker was released, I will be switching away from my original method of using Dropbox for home automation requests. IFTTT Maker allows you to create IFTTT recipes that interact with a web server of your choosing. In this article I will describe how I replaced my old method in automating my air purifier with IFTTT Maker, which allows it to be faster and more reliable.




For this to work you will need a web server running on your network. I am using my Synology NAS setup for this. I made a php file called interface.php which will be used from now on to interface all my home automation projects to IFTTT. If you look at the file you can see it just executes an ssh to my Raspberry Pi which runs the script to turn on my air purifier. The only part you would need to edit is the TOKEN value, which you can set to anything random that you would like (think of it as like a password).

Now we create a new recipe on IFTTT using the IFTTT Maker channel. The parts of the web request action you need to set are:
  • URL: Point to where the interface.php file is accessible on the web.
  • METHOD: Set this to POST
  • Content Type: We will have this as application/json
  • BODY: Here is the JSON data that we will send to the php file to parse. The method I am using is:
    • {"token":"YOUR_TOKEN", "type":"purifier","action":"toggle"}

Let's break down how it works. In the BODY you are sending an array of data in JSON format which are "KEY":"VALUE" segments separated with a comma. In the PHP file, we capture this data packet using file_get_contents('php://input') and store it in the variable $input. We then access the key values like any other array using $input['key'].

I wanted to use HTTPS with IFTTT Maker so that the connection is secure. Unfortunatenly, IFTTT does not support self-signed certificates. I tweeted IFTTT about using self-signed certificates and they replied that they might add it as a feature request. So I decided to buy the Comodo Positive SSL for a few bucks to get it working.

Now you, too, can begin to use IFTTT Maker to change the way you do home automation. I am really happy that IFTTT has implemented this. Look forward to more articles on home automation with IFTTT!

No comments:

Post a Comment