Skip to content

dhleong/wemore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wemore

A more awesome library for Belkin WeMo interactions. With acknowledgements to wemo.js for protocol reference.

Usage

NPM

Toggle the first device found:

var wemore = require('wemore')

// with no args, a Discovery object is returned
//  that emits device events as they're discovered
var discovery = wemore.Discover()
.on('device', function(device) {
    device.toggleBinaryState();
    discovery.close(); // stop discovering
});

Toggling a device by its friendly name:

var wemore = require('wemore')

// when the friendly name is provided, a Promise is returned
wemore.Discover('Lights')
.then(function(device) {
    return device.toggleBinaryState();
})
.then(function() {
    console.log("Success!");
})
.fail(function(err) {
    console.error("Couldn't find device", err);
});

Emulate Devices

Wemore also provides a facility for emulating devices, allowing you to transparently respond to toggle events from another device on the network, like perhaps the Amazon Echo.

var wemore = require('wemore');

// note that each device needs a separate port:
var tv = wemore.Emulate({friendlyName: "TV", port: 9001}); // choose a port
var stereo = wemore.Emulate({friendlyName: "Stereo"}); // automatically assigned

tv.on('state', function(binaryState) {
    console.log("TV set to=", binaryState);
    tv.close(); // stop advertising the device
});

// also, 'on' and 'off' events corresponding to binary state
stereo.on('on', function() {
    console.log("Stereo turned on");
});

stereo.on('off', function() {
    console.log("Stereo turned off");
});

Binary

Installing with -g provides the wemore-toggle executable:

usage: wemore-toggle <friendlyName>

It's simply a wrapper around the "toggle by friendly name" example above.

About

A more awesome library for Belkin WeMo interactions

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •