# edimax-smartplug

> Node module to communicate with Edimax Smart Plugs

Latest version **0.0.24** (published 2019-03-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install edimax-smartplug
pnpm add edimax-smartplug
yarn add edimax-smartplug
bun add edimax-smartplug
```

## Health

**Score 5/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.24 |
| Published | 2019-03-28 |
| First published | 2015-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 80.2 KB |
| Known vulnerabilities | 0 (+16 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 29 |
| Author | Marcus Wittig |
| Maintainers | mwittig |
| Keywords | SmartHome, SmartPlug, Edimax, Metering |

## Links

- npm: https://www.npmjs.com/package/edimax-smartplug
- Repository: https://github.com/mwittig/edimax-smartplug
- Issues: https://github.com/mwittig/edimax-smartplug/issues
- npm.io page: https://npm.io/package/edimax-smartplug

## Dependencies (7)

- [xpath](https://npm.io/package/xpath.md) 0.0.27
- [xmldom](https://npm.io/package/xmldom.md) ^0.1.27
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.3
- [lodash.parseint](https://npm.io/package/lodash.parseint.md) ^4.0.2
- [es6-object-assign](https://npm.io/package/es6-object-assign.md) ^1.1.0
- [http-digest-client](https://npm.io/package/http-digest-client.md) git+https://github.com/mwittig/node-http-digest-client.git#b8551fe1a27e364d87b90f6a22117232f7683f71
- [lodash.isundefined](https://npm.io/package/lodash.isundefined.md) ^3.0.1

## Recent versions

- 0.0.24 (latest) — 2019-03-28
- 0.0.23 — 2018-02-17
- 0.0.22 — 2017-12-18
- 0.0.21 — 2017-12-04
- 0.0.20 — 2017-05-14
- 0.0.19 — 2017-05-04
- 0.0.18 — 2017-04-29
- 0.0.17 — 2017-01-18
- 0.0.16 — 2016-12-07
- 0.0.15 — 2016-08-31
- 0.0.14 — 2016-05-03
- 0.0.13 — 2016-05-02
- 0.0.12 — 2016-04-25
- 0.0.11 — 2016-03-05
- 0.0.10 — 2015-12-31
- … 8 more at https://npm.io/package/edimax-smartplug/versions

## README

# edimax-smartplug

[![Greenkeeper badge](https://badges.greenkeeper.io/mwittig/edimax-smartplug.svg)](https://greenkeeper.io/) [![Build Status](https://travis-ci.org/mwittig/edimax-smartplug.svg)](https://travis-ci.org/mwittig/edimax-smartplug)

Node module to communicate with Edimax Smart Plugs. The library utilizes Bluebird 
promises - https://github.com/petkaantonov/bluebird. Device requests will be executed sequentially. 
This is useful as the Smart Plug REST service does not properly chain incoming requests. It provides the 
following features:

* Device Discovery - Smart Plugs can be automatically discovered on a given network 
  (see section "Device Discovery" below for details)
* Switching - Apart from switching Smart Plugs on and off, it is possible to read the current switch state 
* Schedule - It is not possible to set the schedule for the Smart Plugs, but the current schedule is readable 
* Usage Metering - For 'SP2101W' Smart Plugs it is possible to access the current, accumulated, and historical
  energy usage metering data
* Support for digest authentication required with firmware versions SP-2101W v2.08 and SP-1101W v2.04

| Important Notice |
|------------------|
The recent firmware versions published for EdiSmart/Amazon Alexa Integration 
are currently *not supported* by edimax-smartplug:
* SP2101W: v2.09 and higher
* SP1101W: v1.05 and higher

Moreover, please note, the SP-2101W V2 plug is currently not supported. 
 [Issue #14](https://github.com/mwittig/edimax-smartplug/issues/14) contains a link thread with 
 untested and unsupported downgrade instructions. Use at your own risk!

If you have installed the new version and wish to downgrade you can use the 
[downgrade guide](https://github.com/mwittig/edimax-smartplug/blob/master/Downgrade.md) provided 
as part of the project.

## Usage Examples

    var smartplug = require('./index');
    var options = {
        timeout: 10000,
        name:'edimax',
        host:'192.168.178.65',
        username: 'admin',
        password: '1234'
    };
    
    
    smartplug.getDeviceInfo(options).then(function (info) {
        console.log(info);
    }).catch(function(e) {console.log("Request failed: ", e)});
    
    smartplug.getSchedule(options).then(function (schedule) {
        console.log(schedule);
    }).catch(function(e) {console.log("Request failed: ", e)});
    
    // set switch ON
    smartplug.setSwitchState(true, options).catch(function(e) {console.log("Request failed: ", e)});
    
    smartplug.getSwitchPower(options).then(function (power) {
        console.log("Current switch power", power, "Watts");
    }).catch(function(e) {console.log("Request failed: ", e)});
    
    smartplug.getSwitchEnergy(options).then(function (energy) {
        console.log("getSwitchEnergy result:", energy);
    }).catch(function(e) {console.log("Request failed: ", e)});
    
    smartplug.getStatusValues(true, options).then(function (all) {
        console.log("getStatusValues result:", all);
    }).catch(function(e) {console.log("Request failed: ", e)});
    
    // set switch OFF
    smartplug.setSwitchState(false, options).catch(function(e) {console.log("Request failed: ", e)});
    
    // get switch status
    smartplug.getSwitchState(options).then(function (state) {
        console.log("Switch status is", state?"ON":"OFF");
    }).catch(function(e) {console.log("Request failed: ", e)});

    // get schedule status
    smartplug.getScheduleState(options).then(function (state) {
        console.log("Schedule status is", state?"ON":"OFF");
    }).catch(function(e) {console.log("Request failed: ", e)});
    
    // get the daily history of power measured consumption for the given date range
    smartplug.getHistory('DAY', '20160825', '20160830', options).then(function (results) {
        console.log("getHistory result", results);
    }).catch(function(e) {console.log("Request failed: ", e)});
    
    // discover devices
    smartplug.discoverDevices({
        timeout: 3000,
        address: "192.168.178.255"
    }).then(function (results) {
        console.log("Discovery Result:", results);
    }).catch(function(e) {console.log("Request failed: ", e)});
    
## Device Discovery

The device discovery implementation is based on the findings summarized in a 
[blog post](http://blog.guntram.de/?p=45) (thanks, Guntram). As the discovery 
mechanism may also be used for other Edimax products, e.g. IP cameras, you should filter
by model name to make sure the found device is a smart plug ('SP1101W' and 'SP2101W'). 
The method `discoverDevices()` accepts the following options:

| Property  | Default           | Type    | Description                                 |
|:----------|:------------------|:--------|:--------------------------------------------|
| address   | "255.255.255.255" | String  | The broadcast address                       |
| timeout   | 3000              | Integer | The timeout in milliseconds for discovery   |

Note: Using the global broadcast address on Windows may yield unexpected results. On Windows, 
global broadcast packets will only be routed via the first network adapter which may cause problems
with multi-homed setups and virtual network adapters. If you want to use a broadcast address 
though, use a network-specific address, e.g. for `192.168.0.1/24` use `192.168.0.255`.

A discovery request returns a promise which yields an array with the discovery items on completion. An item is 
an object with the following properties:

| Property      | Type    | Example          | Description                    |
|:--------------|:--------|:-----------------|:-------------------------------|
| manufacturer  | String  | 'EDIMAX'         | The manufacturer of the device |
| model         | String  | 'SP2101W'        | The model name                 |
| version       | String  | '2.03'           | The firmware version           |
| displayName   | String  | 'edimax'         | The assigned device name       |
| addr          | String  | '192.168.178.65' | The IP address of the device   |
| dstAddr       | String  | '192.168.178.1'  | The IP address of the gateway  |
    
## TODO

* More Documentation
* Make request chaining optional. In some cases, request/response interleaving does not matter
* Add tests

## History

See [Release History](https://github.com/mwittig/edimax-smartplug/blob/master/HISTORY.md).

## License 

Copyright (c) 2015-2019, Marcus Wittig and contributors. All rights reserved.

[MIT License](https://github.com/mwittig/edimax-smartplug/blob/master/LICENSE)

---
_Source: https://npm.io/package/edimax-smartplug · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
