Wemos talk funny

I know enough about Tasker to make me want to pull my own hair out, but still I love it. Sometimes.

I wouldn’t say I’m the kind of Tasker user to try to complicatedly “automate” every little thing I do every day, but there are a few things I’d just like to happen, without me needing to press five different buttons on my Android smartphone to do it.

For example, when I get in my car, I turn on my phone’s bluetooth and it automatically adjusts its own volume level if the connection to my bluetooth stereo adapter is successful and starts up Google Play Music right where I left off last. I’ll admit that it took some trial and error to get all of that working the way I want, but Tasker does all of that for me, every time.

Tasker does a few other things for me, like adjusting my phone’s ringer volume settings based on my location, but that’s all I really needed it to do–until I got my first Wemo switch.

There are quite a few home automation gadgets out there, but I specifically picked Wemo because of the native integration with IFTTT. Unfortunately, IFTTT will never be a complete replacement for Tasker for me, nor Tasker for IFTTT. Ideally, I’d like to be able to mash them together into one app that would do all of the things I want, but I don’t think either is listening when I yell at them.

Regardless, the Wemo/IFTTT relationship was very interesting to me, so I got involved with them both.

Side note: IFTTT also has some pretty cool integration with Google OnHub, too.

What is this ramble about again? Oh yeah, Tasker and Wemo. Here’s the scenario: my phone is my alarm clock, so it’s on my nightstand charging while I sleep. I already created a Tasker profile to adjust my ringer and notification volumes for sleepy-time whenever my phone is charging face-down, at home, from 10p to 6a. When I got my first Wemo light switch I thought, “Wouldn’t it be cool if I could make Tasker turn off the lights in the bedroom, too?”

I’m relatively lazy when it comes to inventing wheels, so I figured for sure that I could find someone else who’d already figured out how to do something similar and had put together a how-to on the internet somewhere. Sure enough, I quickly found several articles about using Tasker to send IFTTT an SMS message to turn off a Wemo switch. It’s not at all hard to get Tasker to send an SMS message–unless you want it sent with your Google Voice number–and it’s not hard to get IFTTT to react to receiving the SMS message by turning on/off a Wemo device. Those things are built in to the apps and are pretty standard.

The problem for me is that it seems overly-complicated and it’s often very slow. I can see in Tasker’s log that it reacts to the conditions I set very quickly by sending the SMS message, but in practice, it’s often 30 seconds or more before IFTTT switches the lights off.

Some of you may be thinking, “Dude, just use the Wemo app on your phone”, but where’s the fun in that? Sure, there are some other “wemo” apps in the Google Play store, but they either have no Tasker integration, are just as slow as IFTTT, or cost several dollars. Did I mention that I’m impatient and cheap?

While trying to find a faster, more direct way to turn the dang light switch off, I happened upon Ouimeaux, which I tried out on my Raspberry Pi this afternoon. Unfortunately, I couldn’t get the web interface to work, though the command line seemed just fine. It doesn’t seem like much of a time savings to ssh to my RPi to run commands that way, though.

What originally brought me to Ouimeaux was the idea of interacting directly with the Wemo switch’s web interface via XML. I think I’d read somewhere previously that’s what the official Wemo apps do and a little research suggested I’d remembered correctly.

One problem: I’m not a programmer. At all.

ARC, working

ARC, working

I do work with programmers enough to know that what I wanted to do was send a command to the Wemo switch via a POST and that the XML would need to be formatted in a specific way that I’d have to figure out.

Brendon showed how he made his discoveries using Groovy, but I don’t know anything about Groovy and really didn’t want to have to install a bunch of stuff I’d never use again to solve this silly Tasker problem. Instead, I went looking for a Chrome extension that would let me POST Brendon’s examples. I found ARC, but it took me a little while to figure out where all of the pieces go to make it work.

http://your-ip-here:49153/upnp/control/basicevent1

Content-type: text/xml
SOAPACTION: "urn:Belkin:service:basicevent:1#SetBinaryState"

<?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>0</BinaryState>
    </u:SetBinaryState>
  </s:Body>
</s:Envelope>

Once I got all of the pieces in the right place, I was able to turn the lights off and on, just by changing this

<BinaryState>0</BinaryState>

to this

<BinaryState>1</BinaryState>
ARC, headers form

ARC, headers form

Moving on to Tasker, I found that it does have an HTTP POST function, but I frankly had no idea where to put all of the words and symbols to make it work. I turned to Ms. Google again, and found others who’d used RESTask successfully for similar HTTP POSTs. No knock against the developer, but I really had no idea what I was looking at–again–and where all the words were supposed to go wasn’t especially clear. Had I known a lot more about XML and APIs, maybe it would have been really easy.

I tried multiple different combinations of “custom body”, “headers”, and “parameters” in RESTask, but I either got an error or nothing happened at all when I tested them. That’s when I went back for another look at ARC. Just clicking through the tabs I saw the pattern/syntax I needed and was able to configure RESTask correctly.

Note that I changed the actual IP in the URLs to “your-ip-here”. If you give this a try, you’ll need to update the URLs.

I’m happy to report that the Tasker tasks I created work very quickly and reliably. Now I can go find something important to do.

mbr_light_switch_off

mbr_light_switch_off

RESTask config

RESTask config

RESTask post

RESTask post

RESTask custom body

RESTask custom body

RESTask headers

RESTask headers

Leave a Reply