Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including tplink-smartplug-node with all npm packages installed. Try it out:

var tplinkSmartplugNode = require("tplink-smartplug-node")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

tplink-smartplug-node v2.1.0

Port of tplink-smartplug.py

TP-Link Smartplug Control for Node

Functionality ported from https://github.com/softScheck/tplink-smartplug to Node.js.

This library allows you to control HS100 and HS110 devices from TP-Link from Node.

Installation

npm i tplink-smartplug-node

Usage

Simple example:

const TPLinkSmartPlug = require('tplink-smartplug-node');

let tp = new TPLinkSmartPlug("192.168.1.100");

tp.turnOn().then(resp => {
    // resp should be { system: { set_relay_state: { err_code: 0 } } }
});

An example of all methods can be found in test.js.

Methods

TPLinkSmartPlug

constructor(ip)
Creates a new instance of the API. This does not connect to the plug yet.

turnOn()
Turns the plug on. Returns a promise resolving to the reply from the plug.

turnOff()
Turns the plug off. Returns a promise resolving to the reply from the plug.

query()
Queries the state of the plug. Returns a promise resolving to the reply from the plug.

getEmeterRealtime()
Get the readings from the Emeter (only supported on HS110).

raw(query)
Send a raw query object to the plug. A list of valid query objects can be found here.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free