Playing with WeMo Insight Switch

I finally couldn’t resist getting my hands on a WeMo Insight Switch anymore. It’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’m the unlucky owner of a Thomson modem from the Danish ISP Stofa, and this thing consumes about 12.4 W, so I’ve been wanting to do something about that for a while, since I’m only using it for my backup internet connection (WAN 2) and for IP telephony.

Unpackaging
Just 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’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 RESTask for Tasker, which I just found for the job (since Tasker doesn’t seem to support setting custom headers in HTTP POST requests).

The hardware
Before jumping to my first project/solution, a few words on the hardware:

  • Power consumption: When the relay is off, it consumes approx. 1.5 W. When on, approx. 1.7 W.
  • Socket: 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 – they physically don’t fit in.

Controlling WeMo from Tomato
Since 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’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:

# Turn on WeMo when WAN is down, hoping for WAN2...
if ! ping >/dev/null -c 1 8.8.8.8; then
  curl -d '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetBinaryState xmlns:u="urn:Belkin:service:basicevent:1"><BinaryState>1</BinaryState></u:SetBinaryState></s:Body></s:Envelope>' -H 'SOAPACTION: "urn:Belkin:service:basicevent:1#SetBinaryState"' -H 'Content-Type: text/xml; charset="utf-8"' -X POST http://wemo.local:49153/upnp/control/basicevent1
fi

After switching over to WAN 2, DNS will still be unavailable for a while – and yes, this method will try to turn on the WeMo over and over again. However, this shouldn’t really cause any problems if it’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).

Next project
Next 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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.