IFTTT and Edison, Part 2: Twilio and Texting Your House

Have you ever been out and began to worry about the state your home was in? Did you leave the door open? Is the oven or lights on? Do your plants need to be watered? 

In days of yore you might call up your neighbor to pop over and check up on things. Now using the Intel Edison, IFTTT, Twilio, and a home sensor package you can simply send a text to your house to ask how its doing. 

In this post I will provide not only step by step instructions on creating this project for yourself, but also provide an overview of how I developed it. By documenting the development process I hope to help those interested understand the steps is developing a new project. For those that just want to replicate the project, or use it for inspiration feel free to skip to the end where I will outline the steps. 


First Steps    

My first steps in developing this project are to collect previous work I've done as well as work that others have done that might be useful. Since this project is going to be a continuation of my previous IFTTT / Edison project (http://martinkronberg.com/new-blog/2015/6/30/ifttt-and-intel-edison) collecting my work is easy.

After a few quick google searches for things like "smart home text updates" and "intel edison smart home" I did not find any projects that are quite what I have in mind. The closest I found is a project on Hackster.io that uses a Rasperry Pi as a hub connected to Azure to monitor all the smart devices in your home. https://www.hackster.io/anthony-ngu/open-source-home-hub

Designing the Stack

One of the issues with the last project that I am hoping to address is a more streamlined stack for communicating to the Intel Edison. In order to send a text to the Edison I used the IFTTT app on my phone to pick up incoming texts, send those to the IFTTT server which would then push the text as a message to Pushbullet. The Edison would be listening on a Websockets stream for changes on my Pushbullet message stream and then pull the latest text.

This approach caused quite a bit of lag and added in what seems like unnecessary complications. Also I want someway to setup a number to be used as the "house number" to receive incoming texts. 

To set up a number and send out responses I will use the Twilio SMS service on IFTTT. This will make it so the user will not have to set up an IFTTT app on their phone and have a unique number to send messages to. 

To get around the Pushbullet message stream approach I will try to set up a public http server on the Intel Edison that can receive POSTs from the Maker channel on IFTTT. In theory I should be able to POST the text message I send to IFTTT via Twilio as a JSON object to the Edison server and then use something like Express.js to pull the body of the message out and parse it. 

Since I think flow diagrams are cool here is a flow diagram of the proposed stack:


The black arrows represent the path for sending a text to your house, the red arrows represent the path for receiving a text from your house.

The black arrows represent the path for sending a text to your house, the red arrows represent the path for receiving a text from your house.

Looking at this it seems that you could just create a HTML front page running on the Edison server and log into it from your phone. However texting might be quicker, and not have a need for a 4G connection. I might write a front end server later on to give the user multiple ways to interact with their home sensors. 

Set up IFTTT SMS Channel

First  of all I set up the SMS channel on IFTTT.com. I entered my phone number and then put in the code they sent out. Simple enough. I want to set up a recipe to test this trigger with a POST event from the Maker channel. I made a recipe with incoming SMS message to the number provided as the trigger and a Maker web request as the event. I found  http://requestb.in/ after Googling "test receive web request"  and hope to use this to test the recipe before I get the Edison server set up.  Cool, it works. I set up a request bin url and sent it a test text from my phone using the Maker channel. When I set up the Edison server I will just change the URL in the Maker channel event and it should be good to go. 

Setting up Edison Server

I started by Googling "node.js web request server"