Integrating Belkin’s WeMo switch and motion with Openremote

WeMo-Sw+MoBelkin offers WiFi enabled power switch and motion sensor for less than $80 http://www.belkin.com/. They connect with home WiFi network and are visible on LAN. Furthermore, they use the UPnP (Universal Plug and Play) protocol which details are easy to find with a Google search. At this moment UPnP protocol is not directly available within Openremote therefore for this integration I’ve used the Shell execution protocol to run curl in order to turn the switch position and also to sensor motion and switch state. It is possible to switch the socket through generic TCP/IP protocol, however reading back a status is unreliable. This is due to the fact that the reply is frequently split into 2 TCP/IP messages, the first part with an HTTP UPnP header and the second one with the message body itself. The TCP/IP implementation in Openremote receives only the first packet frequently missing the second part with an actual status. Nevertheless, it works good with the Shell execution protocol with the only disadvantage that a caution must be taken when porting this code on a different platform. For this integration example I’ve used the professional OpenRemote eBox which is running the Linux Voyage OS. I assume that WeMo switches are already connected with the home WiFi LAN which is achieved by following the standard installation procedure as provided by Belkin. Next I’ve used Android Fing app to scan my network and discover WeMo IP addresses which will be needed when configuring Openremote commands. Apparently WeMo devices’ ethernet address starts with EC:1A:59 and this information simplifies locating them within a crowded LAN environment like mine is. After discovering the IP addresses of WeMo devices please use the following steps to use them in the Openremote designer.

  1. create following files on the OR controller:
    root@orb:/root/wemo# ls -l
    -rw-r--r-- 1 root root 272 Feb  4 13:17 get.xml
    -rw-r--r-- 1 root root 300 Feb  4 13:17 off.xml
    -rw-r--r-- 1 root root 301 Feb  4 13:17 on.xml
    -rwxr-xr-x 1 root root 737 Feb  4 17:39 post.sh
    -rwxr-xr-x 1 root root 737 Feb  4 19:58 post_get.sh
    
    root@orb:~/wemo# cat get.xml
    
    
    root@orb:~/wemo# cat off.xml 
    0
    
    root@orb:~/wemo# cat on.xml 
    1
    
    root@orb:~/wemo# cat post.sh 
    #!/bin/sh
    curl -0 -A '' -v -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#SetBinaryState\"" --data @`dirname $0`/$3.xml http://$1:$2/upnp/control/basicevent1 
    
    root@orb:~/wemo# cat post_get.sh 
    #!/bin/sh
    curl -0 -A '' -v -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#GetBinaryState\"" --data @`dirname $0`/$3.xml http://$1:$2/upnp/control/basicevent1 
    

    For my integration I’ve put these files in /root/wemo directory on my eBox. For doing this you need to use ssh login. Of course you can place these files in any desired location as long as you adjust parameters of the Shell execution command.

  2. Create following openremote commands in the designer:
    WeMo.mo.shell.get

    WeMo.sw.shell.get

    WeMo.sw.shell.off

    WeMo.sw.shell.on

    As you can see my WeMo devices are at IP addresses 192.168.1.10 (switch) and 192.168.1.11 (motion).

  3. Crate 2 sensors: WeMo.mo (command WeMo.mo.shell.get, type Custom) and WeMo.sw (command WeMo.sw.shell.get, type Custom)

Now WeMo devices should be available in the Openremote designer.

4 thoughts on “Integrating Belkin’s WeMo switch and motion with Openremote

  1. Hi, Thank you for putting this together. I pretty much have it working but I seem to have a problem with my sensor. It is not detecting the on or off state of the switch. I think it might be a problem with the custom value. Should the value be 0 for off and 1 for on? Right now I have nothing in the name and value fields of the custom sensor.

    Thank you,

    Mike

  2. Hi Michal. The openremote designer is good tool. Pero ¿No hay otra manera de crear un “command” en el openremote designer más sencilla ? No puedo crear un switch para encender y apagar el Wemo Belkin que tengo.

    El api del ouimeaux es muy dificil de instalar en ms windows. ¿Hay otro camino?

    Thanks

    Raúl

Leave a Reply