{"id":225,"date":"2017-12-11T16:22:22","date_gmt":"2017-12-11T15:22:22","guid":{"rendered":"http:\/\/techblog.vindvejr.dk\/?p=225"},"modified":"2017-12-12T22:10:36","modified_gmt":"2017-12-12T21:10:36","slug":"playing-with-wemo-insight-switch","status":"publish","type":"post","link":"https:\/\/techblog.vindvejr.dk\/?p=225","title":{"rendered":"Playing with WeMo Insight Switch"},"content":{"rendered":"<p>I finally couldn&#8217;t resist getting my hands on a WeMo Insight Switch anymore. It&#8217;s a kind of expensive gadget, considering how clumsy it is and that all it can do is turn one thing on or off. Also, I read in some specifications that it was consuming a considerable amount of energy itself. However, I&#8217;m the unlucky owner of a Thomson modem from the Danish ISP Stofa, and this thing consumes about 12.4 W, so I&#8217;ve been wanting to do something about that for a while, since I&#8217;m only using it for my backup internet connection (WAN 2) and for IP telephony.<\/p>\n<p><strong>Unpackaging<\/strong><br \/>\nJust kidding. After connecting the switch you have to install the 33 MB app from Belkin to get it up running. After this I searched the net for API&#8217;s and alternate ways to control it. Half an hour later I had a working curl command to turn it on or off, as well as a working Tasker configuration using <a href=\"https:\/\/play.google.com\/store\/apps\/details?id=com.freehaha.restask\" rel=\"noopener\" target=\"_blank\">RESTask for Tasker<\/a>, which I just found for the job (since <a href=\"https:\/\/play.google.com\/store\/apps\/details?id=net.dinglisch.android.taskerm\" rel=\"noopener\" target=\"_blank\">Tasker<\/a> doesn&#8217;t seem to support setting custom headers in HTTP POST requests).<\/p>\n<p><strong>The hardware<\/strong><br \/>\nBefore jumping to my first project\/solution, a few words on the hardware:<\/p>\n<ul>\n<li><strong>Power consumption:<\/strong> When the relay is off, it consumes approx. 1.5 W. When on, approx. 1.7 W.<\/li>\n<li><strong>Socket:<\/strong> The socket is a Schuko socket, which is problematic for the Danish market, since you cannot plug in the traditional Danish flat and round connectors &#8211; they physically don&#8217;t fit in.<\/li>\n<\/ul>\n<p><strong>Controlling WeMo from Tomato<\/strong><br \/>\nSince my Tomato router firmware (by Shibby) comes with curl preinstalled, controlling WeMo from the router is not a problem. What I wanted to do was having my router turn on the modem for WAN 2 when WAN 1 is down. I decided to ping the DNS server to check if I&#8217;m connected to the internet, and to do this once a minute. So in Administration\/Scheduler I added this custom script to run every minute:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# Turn on WeMo when WAN is down, hoping for WAN2...\r\nif ! ping &gt;\/dev\/null -c 1 8.8.8.8; then\r\n  curl -d '&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;s:Envelope xmlns:s=&quot;http:\/\/schemas.xmlsoap.org\/soap\/envelope\/&quot; s:encodingStyle=&quot;http:\/\/schemas.xmlsoap.org\/soap\/encoding\/&quot;&gt;&lt;s:Body&gt;&lt;u:SetBinaryState xmlns:u=&quot;urn:Belkin:service:basicevent:1&quot;&gt;&lt;BinaryState&gt;1&lt;\/BinaryState&gt;&lt;\/u:SetBinaryState&gt;&lt;\/s:Body&gt;&lt;\/s:Envelope&gt;' -H 'SOAPACTION: &quot;urn:Belkin:service:basicevent:1#SetBinaryState&quot;' -H 'Content-Type: text\/xml; charset=&quot;utf-8&quot;' -X POST http:\/\/wemo.local:49153\/upnp\/control\/basicevent1\r\nfi\r\n<\/pre>\n<p>After switching over to WAN 2, DNS will still be unavailable for a while &#8211; and yes, this method will try to turn on the WeMo over and over again. However, this shouldn&#8217;t really cause any problems if it&#8217;s already turned on. On the other hand, it might actually save the day, if the first packet is lost (WeMo is on Wi-Fi).<\/p>\n<p><strong>Next project<\/strong><br \/>\nNext project will be to set up openHAB on a Raspberry Pi (for starters) and try to teach it when at least one person is at home. Then I can have back my IP telephony (requiring the modem on) when arriving at home and until going to bed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I finally couldn&#8217;t resist getting my hands on a WeMo Insight Switch anymore. It&#8217;s a kind of expensive gadget, considering how clumsy it is and that all it can do is turn one thing on or off. Also, I read &hellip; <a href=\"https:\/\/techblog.vindvejr.dk\/?p=225\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,10,12],"tags":[],"class_list":["post-225","post","type-post","status-publish","format-standard","hentry","category-android","category-iot","category-tomato"],"_links":{"self":[{"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/posts\/225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=225"}],"version-history":[{"count":16,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/posts\/225\/revisions"}],"predecessor-version":[{"id":243,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/posts\/225\/revisions\/243"}],"wp:attachment":[{"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}