Electronics · raspberry pi

Raspberry PI for Controlling Wemo Power

The previous article: TP-Link POWER covered TP-link devices.  They’ve become a little difficult to get ahold of this holiday season, but Wemo devices by Belkin are all over the place.

511ciyeuh5l-_sl1000_

WEMO Switch Outlet

So, I took a little time to figure out how to automate those little puppies.

Its pretty simple, once you track down the right library.  In this case you want: wemo-client

A slight modification to the example code gives us blink!  The wemos are a little slow – so you have to give them a 2 second interval.

var Wemo = require('wemo-client');
var wemo = new Wemo();

wemo.discover(function(deviceInfo) {
  console.log('Wemo Device Found: %j', deviceInfo);

  // Get the client for the found device
  var client = wemo.client(deviceInfo);

  // Handle BinaryState events
  client.on('binaryState', function(value) {
    console.log('Binary State changed to: %s', value);
  });

  // Turn the switch on and off at a 2 second interval
  var state = 1;
  setInterval(() => {
    state = !state;
    client.setBinaryState(state ? 0 : 1);
    console.log("State: " + state);
   }, 2000);
});

Now… to tie them into the remote control wand and make sure it runs forever!