Welcome to our final blog from the eBay Internet of Things collections series!
In our penultimate post in this series, we were showing you how to implement a low-tech version of home automation using NFC and the EVRYTHNG engine.
This time we’ll look at the bleeding-edge version of our connected home! A home where appliances can be piped together easily to create a dynamically reconfigurable home. Just like you can use IFTTT or Yahoo Pipes to create smart workflows for your data (e.g. if I tweet this, post this to my LinkedIn profile and update this Google Spreadsheet) you should be able to configure the real world just as it suits you. This is what we call: Physical Mashups, i.e. the fast and easy composition of the services of physical devices to create unforeseen applications that meet our needs! Sorry for getting over-excited here but Physical Mashups were a big chunk of my PhD 🙂
The Web is mashable mainly because of APIs (Application Programming Interfaces). This is a little revolution that started a few years ago whereby Websites slowly but steadily started to get APIs, making them Web apps rather than plain sites, the Programmable Web directory is here to witness it! So, the first step in building our futuristic house is to make sure all our devices are accessible via an API (a REST API Link), either directly or indirectly through a gateway or online service like the EVRYTHNG API.
While we won’t be able to review all appliances you have in your home here let us discuss three cases to see how they fit in the picture:
1) First, appliances that come directly with a Web API like the Hue Lamps we talked about in another recipe. These are very easy to integrate to Physical Mashups as they basically tick all the boxes: they are accessible on the IP network and offer a REST API!
2) Secondly, appliances that are hooked up to or proxied by a Web of Things Cloud service such as the EVRYTHNG API. As an example, consider the Smart Coffee Machine we created in a previous post in this series. These are also easy to integrate because the cloud service offers a Web API for the devices.
3) Thirdly, devices that are neither offering a Web API directly, nor through a Cloud service (how dare they in 2014? ;-)). A good example would be all the not-so-smart devices that you have at home like your plain-old-lamps, fans, kettles, old-school-TVs, etc. Well, for those not all hope is lost: we can still make them smart at least at the basic level (on/off) without too much effort. For this we will hack an 433Mhz AM power-switch transmitter, no clue what this is? Well it is a set usually containing a remote control and a number of radio powered power-switches like the one in our collection.
Then, thanks to the following tutorial we connect a $5 RF transmitter to an Arduino then connect these to a Raspberry Pi turning it into a 433Mhz RF remote control!
We finally need to Web-enable this so that we can trigger the Raspberry PI “remote control” by means of REST calls. There are several ways of doing this like the very neat heimcontrol.js or the more featureful Webiopi.
Regardless of which one you pick you should now be able to turn on and off literally any device connected to your RF power-sockets!
Last but not least, the mashability comes into play: “How do you wire all these devices together in the same way that you would create Web Mashups?” Well this is where Physical Mashup editors come handy: they let you rewire your home visually! Let me introduce you to two of them: WoT-a-Mashup is a prototyping tool that lets you create your mashups in a snap, directly from your browser (currently only Firefox is supported). It is built on ClickScript, an IDE and great visual language designed to teach kids the art of programming, so it is quite easy to grasp.
Basically each resource you want to integrate into your mashup (including the physical ones!) is a little box that accepts a number of inputs and has 0 or 1 output.
We created two simple EVRYTHNG modules, one that lets you read a property of a Thng (see here) and one that lets you update the property of a Thng.
Now, we can use these two simple modules and combine them with the default modules to create a workflow – workflow below is an example of combining modules. It fetches temperature data that you’ve pushed to the EVRYTHNG API. You can find code examples of how to do this with an OpenPicus Flyport (here) or an Arduino (here).
Then, we check if the temperature is greater than 10; if it is, we send an off command to a device controlled by the EVRYTHNG API (e.g., a heater).
We can also create the same type of workflow to include our Raspberry Pi remote controlled devices. All we need to do is to create our own mashup module. Let’s look at the code of the simple EVRYTHNG module I created as an example.
This tool is great for quick-prototyping but because it runs your workflows in the browser, it isn’t really a viable option for long-running mashups and real-world use cases.
This is when the great Node-RED enters the game! Node-RED provides a browser-based mashup editor that makes it easy to wire together flows using the wide range nodes in the palette, but it actually runs the mashups on Node.js which means that even when closing your browser they’ll still run!
Node-RED is slightly more complicated to use than the Clickscript language, but it offers a lot more options and is truly tailored for the IoT. To interact with the EVRYTHNG API you could simply use the provided HTTP module, but to make it even easier, we created a Node-RED library for the EVRYTHNG API which you can download and install from here. Note that it currently only offers the option to read and update EVRYTHNG Properties, but we’ll add more features soon!
You can see a sample workflow below where we connected our EVRYTHNG-connected Smart Coffee Machine to Twitter so that if we send a tweet with a special hashtag, we get our favorite coffee served straight away!
Adding our Raspberry Pi remote controlled devices is as easy as pi(e)! Indeed, because they are behind a REST API, all we need to do is to use the HTTP module to issue the REST calls. Finally, we need a place for our workflows to run. Fortunately, Node-RED runs can be installed on a Rasberry Pi as well (see here), so we can actually push it to our Pi where the workflows will be running until we terminate them.
Here we go, we closed the loop and can now start rewiring our home, thanks to the Web of Things and Physical Mashups!