Monday, November 10, 2014

Wemo Light Switches and Intermittent Failures ... Found it!

I have four Wemo light switches operating around the house on outside lights.  You know the ones.  They're the switches that you remember after you get in bed and have the covers pulled up.  In my case, I just grab a phone and turn the darn things off from the bed ... except ...

Every once in a while they don't respond.  This has driven me nuts ever since I got the switches and I'm not alone.  There are other folk out there that have been annoyed by this behavior.  After I simplified my code running the switches <link>, and the problem was still there; I set out to see what the heck was going on.  At first the code would hang waiting for a response from the switches, so I put a timeout on the socket read.

When the inevitable timeout came, I at least had a clue; the switch just quit responding.  So, I caught the timeout and printed the URL that was involved.  A few days later, it timed out again and I discovered that the IP address was ok, but the port number the Wemo was listening to had changed.  There's simply no reason for the port number to change ... unless the switch had done it intentionally.  Naw, no one would do that.

Then, the power failed to my house and everything rebooted.  Fine, I'd wait until it happened again.

One evening, one of the switches failed.  I got an email telling me the switch had gone off line.  Yes, an email.  One of the great things about working on a Pi is that it can do things like this.  I had put code in to send me an email when one of the switches got into this state.  I checked the logs (another great thing) and sure enough, the port number had changed.  A little while later, another switch failed, then the other two as well.  The period of working was roughly three days, and then, the switches would change the port number they responded to.

I don't have definitive proof, but I firmly believe they reboot the switches every three days.  Over time I could probably accumulate evidence to support this, but I don't want evidence; I want the darn switches to work.

What I had done in the code was to set a timeout on the socket receive from a polling request to the switch.  When it timed out, it would send me mail and then my process would exit.  Since the process is controlled by upstart (google it), it would start right back up and rediscover the switches.  Everything should be fine then because the new port number would be recorded and control would be set up correctly.  I actually rebooted the control process to just start over.  Not very elegant, but it worked.  When the four switches went south, the process restarted each time and got control back.

Ha, take that Belkin.

Of course there's a downside.  During the time the process is restarting, there could be a command to the switches missed.  It takes about 30 seconds to discover the switches and get all set up so the window is small, but it's there.  I think I can live with that.  I removed the code that sends mail to keep the changes I make to Miranda to an absolute minimum and have the changes running right now.  After a couple of weeks, I'll know how well it worked out.

It's very important to me to avoid relying on an external service to control something around my house, so things like If This Then That, are not an option.  Sure, I like the Wemo app for checking the lights from town, but I don't want to rely on it.  The Internet is just too flaky, companies change policies, and people like to muck with other people's stuff.  I want control inside my own house.

I'm getting closer now.


  1. Yeah, WeMo sucks big time and IMHO Belkin understanding of IoT is completely wrong. I've started myself with TCP/HTTP/SOAP calls but when noticed after few days that WeMo switches are not responding reliably I've installed Ouimeaux server and I'm resetting it every 15 min. At this moment my WeMo switches are more reliable this way than through the own Belkin's WeMo app, i.e. I can switch it through Ouimeaux while WeMo app tells me 'Switch not found'. Go figure this! Anyway, I use also different technologies for my home automation and till now the most robust for me are EnOcean smart plugs. The latest baby I'm testing is this one PSC236 smart EnOcean socket. What I like the most about it is its size. Now I'm able to plug 2 smart plugs into double socket what is impossible with WeMo's due to their bulkiness.

    1. I moved away from Ouimeaux recently. It was nice, but too darn big. I have posts on what I did and how it works on this blog. My solution has held up really well and was simple enough that I was able to find the problem that has been bothering me for months.

      That smart plug won't work for me and the enocean stuff hasn't really surfaced here in the US. I've seen some work done on the protocol, but not enough for me to want to dive in. Heck, I haven't gotten my feet wet in z-wave yet.

    2. You're going to like Z-Wave.....

    3. Z-wave is pretty cool. The only problem is that the darn things are expensive. I'm sure they'll keep coming down though.

  2. Way cool! Some very valid points! I appreciate you writing this
    write-up and also the rest of the website is very good.