Blog

WeMo Insight on Wot.io

Mar 2016/ Posted By: wotio team

<p>When looking around the smart home market, it's hard to miss the Belkin WeMo line of products. They've got many different kinds of compatible devices, from light bulbs to power sockets to space heaters. All of which have some sort of data associated with them, from the state of the device to the state of the surrounding environment. So why don't we integrate our devices into Wotio, just like we did with the <a href="/phillips-hue-on-wot-io/">Philips Hue</a>.</p>
<h1 id="whywot">Why Wot?</h1>
<p>What if the WeMo's light sensors, bulbs, and just about every other device was already pre-integrated into a single system, including devices on other platforms? What if the only thing needed to get them working together was a short script? What if you could then tack on other services from 3rd parties (maybe SQL storage, or tweeting specific events) with little extra effort? And someone else did all of the hosting and scaling work for you? Well, then you'd be using Wot. So in this post I'll be showing you how easy it is to integrate the WeMo system into Wotio, and how Wotio can be used to leverage it.</p>
<h1 id="theintegration">The integration</h1>
<p>WeMo devices can be controlled two ways - either via their Cloud API, or via the local Device Management Platform ( Unfortunately, their DMP doesn't have an open API and is (at least publicly) undocumented. So in this post we'll be seeing how to bypass their DMP and still retain control of our devices over the internet, and then in a future post, how to replace theirs with one on Wotio. If you're cringing right now, you've probably done some system integration before. But don't worry, that's what makes Wot so powerful - it makes these integrations so quick and easy that we don't have to worry about them anymore.</p>
<h3 id="prerequisites">Prerequisites</h3>
<p>To get started, you'll need the following:</p>
<ul>
<li>A Belkin WeMo device (in this demo, we'll use an <a href="http://www.belkin.com/us/p/P-F7C029/">Insight Switch</a>)</li>
<li>A computer, virtual machine, or cloud instance with Python 2.7 installed and a network connection to the Hue bridge</li>
<li>A Wotio access token and path</li>
</ul>
<h3 id="theintegration">The integration</h3>
<p>For this integration, we'll be using Python. Even if you don't know it it's fairly easy lanugage to read and understand what's going on.</p>
<p>You can find the code here:</p>
<p><a href="https://github.com/WoTio/wot-wemo">https://github.com/WoTio/wot-wemo</a></p>
<p>Download it, then from that directory run:</p>
<pre><code>sudo python setup.py install
wotwemo &lt;visit http://wot.io for your wot.io path&gt;
</code></pre>
<p>Where <code>&lt;UUID&gt;</code> is a random string you've generated to identify your application. If you're doing multiple integrations and want them to communicate, this should be kept as the same value.</p>
<p>And that's it! Your wemo devices are now integrated into Wotio. The trick here is in the <code>wotwrapper</code> library. What it does is it takes the functions in a python class (in this case the <code>WotWemo</code> class) and wraps them into Wot-style JSON commands.</p>
<pre><code>JSON Message received | Function Called
------------------------------------------------------------------
["list_devices"] | wemo.list_devices()
["help","&lt;device_name&gt;"] | wemo.help(device_name)
</code></pre>
<p>For detailed usage, see the code and documentation at <a href="https://github.com/WoTio/wot-wemo">WoTio/wot-wemo</a> on Github.</p>
<h3 id="thewotside">The Wot side</h3>
<p>Now that we've got our switch wrapped, let's check out it's data stream on Wot, and attempt to control it over the internet.</p>
<p>We can connect to Wotio using several different protocols, but for our purposes we're going to use websockets. Why? Because we can use any number of mechanisms to view the data streams we're generating in real-time. If you don't have a websocket shell installed, you can try <a href="https://github.com/progrium/wssh">progrium/wssh</a>. It's also based on Python 2.7, so if you've gotten this far in the integration it should work for you perfectly fine. So let's use it to open a websocket connection to our data stream on wotio:</p>
<pre><code>wssh &lt;visit http://wot.io for your wot.io path&gt;
</code></pre>
<p>And you should see the data stream coming from the insight switch! To control it, all you have to do is type a command:</p>
<pre><code>["set_state","&lt;device_name&gt;","off"]
["set_state","&lt;device_name&gt;","on"]
</code></pre>
<p>Notice how each time you send one of these commands, you not only toggle the switch, but change the data coming out of it as well? That's what gives Wot it's power. There are lots of pre-integrated services that can act on this data. You can even integrate another device (just as easily, mind you) and Wotio gives you the power to link them together so that they can communicate no matter where they are in the world; all they need is an internet connection. And all of this is production-ready, with no infrastructure for you to maintain, should you want to take your devices (or services) to market.</p>
<p>And if you've got another device connected as described on the blog, you should be able to send and receive commands on it as well!</p>
<h1 id="learnmore">Learn More</h1>
<p>If you'd like to see a sample of the power you can get out of Wotio, visit the <a href="http://wot.io/about-wot-io/contact-us/">wot.io website</a> and we'll call you to schedule a meeting.</p>