Blog

Home Integration Tutorial

June 24, 2015 / Posted By: wotio team

IoT solutions have many moving parts. Devices, connectivity, device management, and data services. So we've taken all of these components, wrapped them all up into one unified environment, and provided them for you to try out. We're going to take a look at one of our core data services, scriptr.

scriptr

Scriptr, on it's own, is a cloud-based javascript web API framework. It gives you an interface to write some javascript code, and then makes that available at an HTTP endpoint in the cloud. At wot.io, we've taken that interface and wrapped it into our environment. So now, any messages that your devices send can automatically get parsed in scriptr, giving you a tool to create your business logic out of those messages.

Getting Started

To get started, check out the tutorial on getting the Philips Hue system integrated with wot.io here. Once you have that running, get the path for the Blink Demo from the email you received when signing up, or contact us for help.

In this demo, we're going to use scriptr to automatically turn on and off a lightbulb.

In your scriptr account, create a new script and call it connectedhome/blink. To find out how, please refer to the scriptr documentation. Then type in the following code and save it:

var lights = JSON.parse(request.rawBody).data[0].lights; // Retrieve the data that we are putting onto the wot.io bus  
return '["phue","set_light",3,"on",' + !(lights["3"]["state"]["on"]) + ']'; // Send a message that either turns off the light if it is on or vice versa.  

Now, run your Philips Hue integration from the previous step, using the path from the email

python hue.py <bridge ip> <wot path>  

And that's it! Your light bulb should now turn on and off every few seconds. If you want to adjust the speed, simply change the delay in hue.py.

Demo two - color change

Let's try another simple script, where the color of the bulb changes. This time, create a script called connectedhome/changecolor, type in the following code, and save it:

return '["phue","set_light",3,"hue",' + Math.floor((Math.random()*65000)) + ']'; // Send a command to change the light bulb color  

Connect with the hue.py script again, and voila! That's all that it takes to create a production-ready deployment. There's no need to set up any servers or anything else.