TP-Link Smart Home API
| Model | Type |
|---|---|
| HS100, HS105, HS110, HS200 | Plug |
| LB100, LB110, LB120, LB130, LB200, LB230 | Bulb |
- TP-Link Smarthome Device Simulator - Useful for automated testing
- TP-Link Smarthome Crypto
- TP-Link Smarthome Homebridge Plugin
See more examples.
const { Client } = require('tplink-smarthome-api');
const client = new Client();
const plug = client.getDevice({host: '10.0.1.2'}).then((device)=>{
device.getSysInfo().then(console.log);
device.setPowerState(true);
});
// Look for devices, log to console, and turn them on
client.startDiscovery().on('device-new', (device) => {
device.getSysInfo().then(console.log);
device.setPowerState(true);
});Install the command line utility with npm install -g tplink-smarthome-api. Run tplink-smarthome-api --help for help.
For functions that send commands, the last argument is SendOptions where you can set the transport ('tcp','udp') and timeout.
Functions that take more than 3 arguments are passed a single options object as the first argument (and if its a network commmand, SendOptions as the second.)
-
Client ⇐
EventEmitter- new Client(options)
- .send(payload, host, [port], [sendOptions]) ⇒
Promise.<Object, Error> - .getSysInfo(host, [port], [sendOptions]) ⇒
Promise.<Object, Error> - .getBulb(deviceOptions) ⇒
Bulb - .getPlug(deviceOptions) ⇒
Plug - .getDevice(deviceOptions, [sendOptions]) ⇒
Promise.<(Plug|Bulb), Error> - .getCommonDevice(deviceOptions) ⇒
Device - .getDeviceFromSysInfo(sysInfo, deviceOptions) ⇒
Plug|Bulb - .getTypeFromSysInfo(sysInfo) ⇒
string - .startDiscovery(options) ⇒
Client - .stopDiscovery()
- "device-new"
- "device-online"
- "device-offline"
- "bulb-new"
- "bulb-online"
- "bulb-offline"
- "plug-new"
- "plug-online"
- "plug-offline"
- "discovery-invalid"
- "error"
-
- new Bulb(options)
- .cloud
- .getInfo([sendOptions]) ⇒
Promise.<Object, ResponseError> - .bind(username, password, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .unbind([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getFirmwareList([sendOptions]) ⇒
Promise.<Object, ResponseError> - .setServerUrl(server, [sendOptions]) ⇒
Promise.<Object, ResponseError>
- .getInfo([sendOptions]) ⇒
- .emeter
- .realtime ⇒
Object - .getRealtime([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getDayStats(year, month, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .getMonthStats(year, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .eraseStats([sendOptions]) ⇒
Promise.<Object, ResponseError>
- .realtime ⇒
- .lighting
- .lightState ⇒
Object - .getLightState([sendOptions]) ⇒
Promise.<Object, ResponseError> - .setLightState(options, [sendOptions]) ⇒
Promise.<boolean, ResponseError>
- .lightState ⇒
- .schedule
- .getNextAction([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getRules([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getRule(id, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .addRule(options, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .editRule([sendOptions]) ⇒
Promise.<Object, ResponseError> - .deleteAllRules([sendOptions]) ⇒
Promise.<Object, ResponseError> - .deleteRule(id, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .setOverallEnable(enable, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .getDayStats(year, month, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .getMonthStats(year, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .eraseStats([sendOptions]) ⇒
Promise.<Object, ResponseError>
- .getNextAction([sendOptions]) ⇒
- .time
- .getTime([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getTimezone([sendOptions]) ⇒
Promise.<Object, ResponseError>
- .getTime([sendOptions]) ⇒
- .sysInfo ⇒
Object - .supportsBrightness ⇒
boolean - .supportsColor ⇒
boolean - .supportsColorTemperature ⇒
boolean - .getColorTemperatureRange ⇒
Object - .alias ⇒
string - .deviceId ⇒
string - .description ⇒
string - .model ⇒
string - .name ⇒
string - .type ⇒
string - .deviceType ⇒
string - .softwareVersion ⇒
string - .hardwareVersion ⇒
string - .mac ⇒
string - .macNormalized ⇒
string - .getInfo([sendOptions]) ⇒
Promise.<Object, Error> - .getPowerState([sendOptions]) ⇒
Promise.<boolean, ResponseError> - .setPowerState(value, [sendOptions]) ⇒
Promise.<boolean, ResponseError> - .togglePowerState([sendOptions]) ⇒
Promise.<boolean, ResponseError> - .send(payload, [sendOptions]) ⇒
Promise.<Object, Error> - .sendCommand(command, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .startPolling(interval) ⇒
Device|Bulb|Plug - .stopPolling()
- .getSysInfo([sendOptions]) ⇒
Promise.<Object, ResponseError> - .setAlias(alias, [sendOptions]) ⇒
Promise.<boolean, ResponseError> - .setLocation(latitude, longitude, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .getModel([sendOptions]) ⇒
Promise.<Object, ResponseError> - .reboot(delay, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .reset(delay, [sendOptions]) ⇒
Promise.<Object, ResponseError> - "emeter-realtime-update"
- "lightstate-on"
- "lightstate-off"
- "lightstate-change"
- "lightstate-update"
-
- new Plug(options)
- .away
- .getRules([sendOptions]) ⇒
Promise.<Object, ResponseError> - .addRule(options, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .editRule(options, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .deleteAllRules([sendOptions]) ⇒
Promise.<Object, ResponseError> - .deleteRule(id, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .setOverallEnable(enable, [sendOptions]) ⇒
Promise.<Object, ResponseError>
- .getRules([sendOptions]) ⇒
- .cloud
- .getInfo([sendOptions]) ⇒
Promise.<Object, ResponseError> - .bind(username, password, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .unbind([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getFirmwareList([sendOptions]) ⇒
Promise.<Object, ResponseError> - .setServerUrl(server, [sendOptions]) ⇒
Promise.<Object, ResponseError>
- .getInfo([sendOptions]) ⇒
- .emeter
- .realtime ⇒
Object - .getRealtime([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getDayStats(year, month, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .getMonthStats(year, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .eraseStats([sendOptions]) ⇒
Promise.<Object, ResponseError>
- .realtime ⇒
- .schedule
- .getNextAction([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getRules([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getRule(id, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .addRule(options, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .editRule(options, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .deleteAllRules([sendOptions]) ⇒
Promise.<Object, ResponseError> - .deleteRule(id, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .setOverallEnable(enable, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .getDayStats(year, month, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .getMonthStats(year, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .eraseStats([sendOptions]) ⇒
Promise.<Object, ResponseError>
- .getNextAction([sendOptions]) ⇒
- .time
- .getTime([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getTimezone([sendOptions]) ⇒
Promise.<Object, ResponseError>
- .getTime([sendOptions]) ⇒
- .timer
- .getRules([sendOptions]) ⇒
Promise.<Object, ResponseError> - .addRule(options, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .editRule(options, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .deleteAllRules([sendOptions]) ⇒
Promise.<Object, ResponseError>
- .getRules([sendOptions]) ⇒
- .sysInfo ⇒
Object - .inUse ⇒
boolean - .relayState ⇒
boolean - .alias ⇒
string - .deviceId ⇒
string - .description ⇒
string - .model ⇒
string - .name ⇒
string - .type ⇒
string - .deviceType ⇒
string - .softwareVersion ⇒
string - .hardwareVersion ⇒
string - .mac ⇒
string - .macNormalized ⇒
string - .getInfo([sendOptions]) ⇒
Promise.<Object, Error> - .getInUse([sendOptions]) ⇒
Promise.<boolean, ResponseError> - .getLedState([sendOptions]) ⇒
Promise.<boolean, ResponseError> - .setLedState(value, [sendOptions]) ⇒
Promise.<boolean, ResponseError> - .getPowerState([sendOptions]) ⇒
Promise.<boolean, ResponseError> - .setPowerState(value, [sendOptions]) ⇒
Promise.<boolean, ResponseError> - .togglePowerState([sendOptions]) ⇒
Promise.<boolean, ResponseError> - .blink([times], [rate], [sendOptions]) ⇒
Promise.<boolean, ResponseError> - .send(payload, [sendOptions]) ⇒
Promise.<Object, Error> - .sendCommand(command, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .startPolling(interval) ⇒
Device|Bulb|Plug - .stopPolling()
- .getSysInfo([sendOptions]) ⇒
Promise.<Object, ResponseError> - .setAlias(alias, [sendOptions]) ⇒
Promise.<boolean, ResponseError> - .setLocation(latitude, longitude, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .getModel([sendOptions]) ⇒
Promise.<Object, ResponseError> - .reboot(delay, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .reset(delay, [sendOptions]) ⇒
Promise.<Object, ResponseError> - "power-on"
- "power-off"
- "power-update"
- "in-use"
- "not-in-use"
- "in-use-update"
- "emeter-realtime-update"
Client that sends commands to specified devices or discover devices on the local subnet.
- Contains factory methods to create devices.
- Events are emitted after #startDiscovery is called.
Kind: global class
Extends: EventEmitter
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object |
||
| [options.defaultSendOptions] | SendOptions |
||
| [options.defaultSendOptions.timeout] | Number |
5000 |
(ms) |
| [options.defaultSendOptions.transport] | string |
"tcp" |
'tcp' or 'udp' |
| [options.logLevel] | string |
level for built in logger ['error','warn','info','debug','trace'] |
Encrypts payload and sends to device.
- If
payloadis not a string, it isJSON.stringify'd. - Promise fulfills with parsed JSON response.
Devices use JSON to communicate.
For Example:
- If a device receives:
{"system":{"get_sysinfo":{}}}
- It responds with:
{"system":{"get_sysinfo":{ err_code: 0, sw_ver: "1.0.8 Build 151113 Rel.24658", hw_ver: "1.0", ... }}}
All responses from device contain an err_code (0 is success).
Kind: instance method of Client
| Param | Type | Default |
|---|---|---|
| payload | Object | string |
|
| host | string |
|
| [port] | number |
9999 |
| [sendOptions] | SendOptions |
Requests {system:{get_sysinfo:{}}} from device.
Kind: instance method of Client
Returns: Promise.<Object, Error> - parsed JSON response
| Param | Type | Default |
|---|---|---|
| host | string |
|
| [port] | number |
9999 |
| [sendOptions] | SendOptions |
client.getBulb(deviceOptions) ⇒ Bulb
Creates Bulb object.
See Device#constructor and Bulb#constructor for valid options.
Kind: instance method of Client
| Param | Type | Description |
|---|---|---|
| deviceOptions | Object |
passed to Bulb#constructor |
client.getPlug(deviceOptions) ⇒ Plug
Creates Plug object.
See Device#constructor and Plug#constructor for valid options.
Kind: instance method of Client
| Param | Type | Description |
|---|---|---|
| deviceOptions | Object |
passed to Plug#constructor |
Creates a Plug or Bulb after querying device to determine type.
See Device#constructor, Bulb#constructor, Plug#constructor for valid options.
Kind: instance method of Client
| Param | Type | Description |
|---|---|---|
| deviceOptions | Object |
passed to Device#constructor |
| [sendOptions] | SendOptions |
client.getCommonDevice(deviceOptions) ⇒ Device
Create Device object.
- Device object only supports common Device methods.
- See Device#constructor for valid options.
- Instead use #getDevice to create a fully featured object.
Kind: instance method of Client
| Param | Type | Description |
|---|---|---|
| deviceOptions | Object |
passed to Device#constructor |
Creates device corresponding to the provided sysInfo.
See Device#constructor, Bulb#constructor, Plug#constructor for valid options
Kind: instance method of Client
| Param | Type | Description |
|---|---|---|
| sysInfo | Object |
|
| deviceOptions | Object |
passed to device constructor |
Guess the device type from provided sysInfo.
Based on sys_info.[type|mic_type]
Kind: instance method of Client
Returns: string - 'plug','bulb','device'
| Param | Type |
|---|---|
| sysInfo | Object |
client.startDiscovery(options) ⇒ Client
Discover TP-Link Smarthome devices on the network.
- Sends a discovery packet (via UDP) to the
broadcastaddress everydiscoveryInterval(ms). - Stops discovery after
discoveryTimeout(ms) (if0, runs until #stopDiscovery is called).- If a device does not respond after
offlineTolerancenumber of attempts, event:Client#device-offline is emitted.
- If a device does not respond after
- If
deviceTypesare specified only matching devices are found. - If
macAddressesare specified only matching device with matching MAC addresses are found. - If
devicesare specified it will attempt to contact them directly in addition to sending to the broadcast address.devicesare specified as an array of[{host, [port: 9999]}].
Kind: instance method of Client
Returns: Client - this
Emits: error, device-new, device-online, device-offline, bulb-new, bulb-online, bulb-offline, plug-new, plug-online, plug-offline
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object |
||
| [options.address] | string |
address to bind udp socket | |
| [options.port] | number |
port to bind udp socket | |
| [options.broadcast] | string |
"255.255.255.255" |
broadcast address |
| [options.discoveryInterval] | number |
10000 |
(ms) |
| [options.discoveryTimeout] | number |
0 |
(ms) |
| [options.offlineTolerance] | number |
3 |
# of consecutive missed replies to consider offline |
| [options.deviceTypes] | Array.<string> |
'plug','bulb' | |
| [options.macAddresses] | Array.<string> |
MAC will be normalized, comparison will be done after removing special characters (:,-, etc.) and case insensitive |
|
| [options.deviceOptions] | Object |
{} |
passed to device constructors |
| [options.devices] | Array.<Object> |
known devices to query instead of relying on broadcast |
Stops discovery and closes UDP socket.
Kind: instance method of Client
First response from device.
Kind: event emitted by Client
Properties
| Type |
|---|
Device | Bulb | Plug |
Follow up response from device.
Kind: event emitted by Client
Properties
| Type |
|---|
Device | Bulb | Plug |
No response from device.
Kind: event emitted by Client
Properties
| Type |
|---|
Device | Bulb | Plug |
First response from Bulb.
Kind: event emitted by Client
Properties
| Type |
|---|
Bulb |
Follow up response from Bulb.
Kind: event emitted by Client
Properties
| Type |
|---|
Bulb |
No response from Bulb.
Kind: event emitted by Client
Properties
| Type |
|---|
Bulb |
First response from Plug.
Kind: event emitted by Client
Properties
| Type |
|---|
Plug |
Follow up response from Plug.
Kind: event emitted by Client
Properties
| Type |
|---|
Plug |
No response from Plug.
Kind: event emitted by Client
Properties
| Type |
|---|
Plug |
Invalid/Unknown response from device.
Kind: event emitted by Client
Properties
| Name | Type |
|---|---|
| rinfo | Object |
| response | Buffer |
| decryptedResponse | Buffer |
Error during discovery.
Kind: event emitted by Client
Properties
| Type |
|---|
Error |
Bulb ⇐ Device
Bulb Device.
TP-Link models: LB100, LB110, LB120, LB130.
Kind: global class
Extends: Device, EventEmitter
Emits: lightstate-on, lightstate-off, lightstate-change, lightstate-update, emeter-realtime-update
Created by Client - Do not instantiate directly.
See Device#constructor for common options.
| Param | Type |
|---|---|
| options | Object |
Kind: instance property of Bulb
- .cloud
- .getInfo([sendOptions]) ⇒
Promise.<Object, ResponseError> - .bind(username, password, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .unbind([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getFirmwareList([sendOptions]) ⇒
Promise.<Object, ResponseError> - .setServerUrl(server, [sendOptions]) ⇒
Promise.<Object, ResponseError>
- .getInfo([sendOptions]) ⇒
Gets device's TP-Link cloud info.
Requests cloud.get_info.
Kind: instance method of cloud
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Add device to TP-Link cloud.
Sends cloud.bind command.
Kind: instance method of cloud
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| username | string |
| password | string |
| [sendOptions] | SendOptions |
Remove device from TP-Link cloud.
Sends cloud.unbind command.
Kind: instance method of cloud
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Get device's TP-Link cloud firmware list.
Sends cloud.get_intl_fw_list command.
Kind: instance method of cloud
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Sets device's TP-Link cloud server URL.
Sends cloud.set_server_url command.
Kind: instance method of cloud
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type | Description |
|---|---|---|
| server | string |
URL |
| [sendOptions] | SendOptions |
Kind: instance property of Bulb
- .emeter
- .realtime ⇒
Object - .getRealtime([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getDayStats(year, month, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .getMonthStats(year, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .eraseStats([sendOptions]) ⇒
Promise.<Object, ResponseError>
- .realtime ⇒
Returns cached results from last retrieval of emeter.get_realtime.
Kind: instance property of emeter
Gets device's current energy stats.
Requests emeter.get_realtime. Older devices return current, voltage,... while newer devices return current_ma, voltage_mv...
This will return a normalized response including both old and new style properies for backwards compatibility.
Kind: instance method of emeter
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Get Daily Emeter Statisics.
Sends emeter.get_daystat command.
Kind: instance method of emeter
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| year | number |
| month | number |
| [sendOptions] | SendOptions |
Get Monthly Emeter Statisics.
Sends emeter.get_monthstat command.
Kind: instance method of emeter
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| year | number |
| [sendOptions] | SendOptions |
Erase Emeter Statistics.
Sends emeter.erase_runtime_stat command.
Kind: instance method of emeter
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Kind: instance property of Bulb
- .lighting
- .lightState ⇒
Object - .getLightState([sendOptions]) ⇒
Promise.<Object, ResponseError> - .setLightState(options, [sendOptions]) ⇒
Promise.<boolean, ResponseError>
- .lightState ⇒
Returns cached results from last retrieval of lightingservice.get_light_state.
Kind: instance property of lighting
Get Bulb light state.
Requests lightingservice.get_light_state.
Kind: instance method of lighting
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Sets Bulb light state (on/off, brightness, color, etc).
Sends lightingservice.transition_light_state command.
Kind: instance method of lighting
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object |
||
| [options.transition_period] | number |
(ms) | |
| [options.on_off] | boolean |
||
| [options.mode] | string |
||
| [options.hue] | number |
0-360 | |
| [options.saturation] | number |
0-100 | |
| [options.brightness] | number |
0-100 | |
| [options.color_temp] | number |
Kelvin (LB120:2700-6500 LB130:2500-9000) | |
| [options.ignore_default] | boolean |
true |
|
| [sendOptions] | SendOptions |
Kind: instance property of Bulb
- .schedule
- .getNextAction([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getRules([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getRule(id, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .addRule(options, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .editRule([sendOptions]) ⇒
Promise.<Object, ResponseError> - .deleteAllRules([sendOptions]) ⇒
Promise.<Object, ResponseError> - .deleteRule(id, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .setOverallEnable(enable, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .getDayStats(year, month, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .getMonthStats(year, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .eraseStats([sendOptions]) ⇒
Promise.<Object, ResponseError>
- .getNextAction([sendOptions]) ⇒
Gets Next Schedule Rule Action.
Requests schedule.get_next_action.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Gets Schedule Rules.
Requests schedule.get_rules.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Gets Schedule Rule.
Requests schedule.get_rules and return rule matching Id
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response of rule
| Param | Type |
|---|---|
| id | string |
| [sendOptions] | SendOptions |
Adds Schedule rule.
Sends schedule.add_rule command and returns rule id.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object |
||
| options.lightState | Object |
||
| options.start | Date | number |
Date or number of minutes | |
| [options.daysOfWeek] | Array.<number> |
[0,6] = weekend, [1,2,3,4,5] = weekdays | |
| [options.name] | string |
||
| [options.enable] | boolean |
true |
|
| [sendOptions] | SendOptions |
Edits Schedule rule.
Sends schedule.edit_rule command and returns rule id.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type | Default | Description |
|---|---|---|---|
| options.id | string |
||
| options.lightState | Object |
||
| options.start | Date | number |
Date or number of minutes | |
| [options.daysOfWeek] | Array.<number> |
[0,6] = weekend, [1,2,3,4,5] = weekdays | |
| [options.name] | string |
[description] | |
| [options.enable] | boolean |
true |
|
| [sendOptions] | SendOptions |
Deletes All Schedule Rules.
Sends schedule.delete_all_rules command.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Deletes Schedule Rule.
Sends schedule.delete_rule command.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| id | string |
| [sendOptions] | SendOptions |
Enables or Disables Schedule Rules.
Sends schedule.set_overall_enable command.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| enable | boolean |
| [sendOptions] | SendOptions |
Get Daily Usage Statisics.
Sends schedule.get_daystat command.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| year | number |
| month | number |
| [sendOptions] | SendOptions |
Get Monthly Usage Statisics.
Sends schedule.get_monthstat command.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| year | number |
| [sendOptions] | SendOptions |
Erase Usage Statistics.
Sends schedule.erase_runtime_stat command.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Kind: instance property of Bulb
- .time
- .getTime([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getTimezone([sendOptions]) ⇒
Promise.<Object, ResponseError>
- .getTime([sendOptions]) ⇒
Gets device's time.
Requests timesetting.get_time.
Kind: instance method of time
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Gets device's timezone.
Requests timesetting.get_timezone.
Kind: instance method of time
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Returns cached results from last retrieval of system.sys_info.
Kind: instance property of Bulb
Overrides: sysInfo
Returns: Object - system.sys_info
Cached value of sys_info.is_dimmable === 1
Kind: instance property of Bulb
Cached value of sys_info.is_color === 1
Kind: instance property of Bulb
Cached value of sys_info.is_variable_color_temp === 1
Kind: instance property of Bulb
Returns array with min and max supported color temperatures
Kind: instance property of Bulb
Returns: Object - range
Cached value of sys_info.alias.
Kind: instance property of Bulb
Cached value of sys_info.deviceId.
Kind: instance property of Bulb
Cached value of sys_info.[description|dev_name].
Kind: instance property of Bulb
Cached value of sys_info.model.
Kind: instance property of Bulb
Cached value of sys_info.alias.
Kind: instance property of Bulb
Cached value of sys_info.[type|mic_type].
Kind: instance property of Bulb
Type of device (or device if unknown).
Based on cached value of sys_info.[type|mic_type]
Kind: instance property of Bulb
Returns: string - 'plub'|'bulb'|'device'
Cached value of sys_info.sw_ver.
Kind: instance property of Bulb
Cached value of sys_info.hw_ver.
Kind: instance property of Bulb
Cached value of sys_info.[mac|mic_mac|ethernet_mac].
Kind: instance property of Bulb
Normalized cached value of sys_info.[mac|mic_mac|ethernet_mac]
Removes all non alphanumeric characters and makes uppercase
aa:bb:cc:00:11:22 will be normalized to AABBCC001122
Kind: instance property of Bulb
Requests common Bulb status details in a single request.
system.get_sysinfocloud.get_sysinfoemeter.get_realtimeschedule.get_next_action
Kind: instance method of Bulb
Returns: Promise.<Object, Error> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Gets on/off state of Bulb.
Requests lightingservice.get_light_state and returns true if on_off === 1.
Kind: instance method of Bulb
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Sets on/off state of Bulb.
Sends lightingservice.transition_light_state command with on_off value.
Kind: instance method of Bulb
| Param | Type | Description |
|---|---|---|
| value | boolean |
true: on, false: off |
| [sendOptions] | SendOptions |
Toggles state of Bulb.
Requests lightingservice.get_light_state sets the power state to the opposite of on_off === 1 and returns the new power state.
Kind: instance method of Bulb
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Sends payload to device (using send)
Kind: instance method of Bulb
Returns: Promise.<Object, Error> - parsed JSON response
| Param | Type |
|---|---|
| payload | Object | string |
| [sendOptions] | SendOptions |
Sends command(s) to device.
Calls #send and processes the response.
- If only one operation was sent:
- Promise fulfills with specific parsed JSON response for command.
Example:{system:{get_sysinfo:{}}}- resolves to:
{err_code:0,...}\ - instead of:
{system:{get_sysinfo:{err_code:0,...}}}(as #send would)
- resolves to:
- Promise fulfills with specific parsed JSON response for command.
- If more than one operation was sent:
- Promise fulfills with full parsed JSON response (same as #send)
Also, the response's err_code(s) are checked, if any are missing or != 0 the Promise is rejected with ResponseError.
Kind: instance method of Bulb
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| command | Object | string |
| [sendOptions] | SendOptions |
Polls the device every interval.
Returns this (for chaining) that emits events based on state changes.
Refer to specific device sections for event details.
Kind: instance method of Bulb
Returns: Device | Bulb | Plug - this
| Param | Type | Description |
|---|---|---|
| interval | number |
(ms) |
Stops device polling.
Kind: instance method of Bulb
Gets device's SysInfo.
Requests system.sys_info from device.
Kind: instance method of Bulb
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Change device's alias (name).
Sends system.set_dev_alias command.
Kind: instance method of Bulb
| Param | Type |
|---|---|
| alias | string |
| [sendOptions] | SendOptions |
Set device's location.
Sends system.set_dev_location command.
Kind: instance method of Bulb
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| latitude | number |
| longitude | number |
| [sendOptions] | SendOptions |
Gets device's model.
Requests system.sys_info and returns model name.
Kind: instance method of Bulb
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Reboot device.
Sends system.reboot command.
Kind: instance method of Bulb
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| delay | number |
| [sendOptions] | SendOptions |
Reset device.
Sends system.reset command.
Kind: instance method of Bulb
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| delay | number |
| [sendOptions] | SendOptions |
Bulb's Energy Monitoring Details were updated from device. Fired regardless if status was changed.
Kind: event emitted by Bulb
Properties
| Name | Type | Description |
|---|---|---|
| value | Object |
emeterRealtime |
Bulb was turned on (lightstate.on_off).
Kind: event emitted by Bulb
Properties
| Name | Type | Description |
|---|---|---|
| value | Object |
lightstate |
Bulb was turned off (lightstate.on_off).
Kind: event emitted by Bulb
Properties
| Name | Type | Description |
|---|---|---|
| value | Object |
lightstate |
Bulb's lightstate was changed.
Kind: event emitted by Bulb
Properties
| Name | Type | Description |
|---|---|---|
| value | Object |
lightstate |
Bulb's lightstate state was updated from device. Fired regardless if status was changed.
Kind: event emitted by Bulb
Properties
| Name | Type | Description |
|---|---|---|
| value | Object |
lightstate |
Plug ⇐ Device
Plug Device.
TP-Link models: HS100, HS105, HS110, HS200.
Emits events after device status is queried, such as #getSysInfo and #getEmeterRealtime.
Kind: global class
Extends: Device, EventEmitter
Emits: power-on, power-off, power-update, in-use, not-in-use, in-use-update, emeter-realtime-update
Created by Client - Do not instantiate directly.
See Device#constructor for common options.
| Param | Type | Default |
|---|---|---|
| options | Object |
|
| [options.inUseThreshold] | Number |
0 |
Kind: instance property of Plug
- .away
- .getRules([sendOptions]) ⇒
Promise.<Object, ResponseError> - .addRule(options, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .editRule(options, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .deleteAllRules([sendOptions]) ⇒
Promise.<Object, ResponseError> - .deleteRule(id, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .setOverallEnable(enable, [sendOptions]) ⇒
Promise.<Object, ResponseError>
- .getRules([sendOptions]) ⇒
Gets Away Rules.
Requests anti_theft.get_rules.
Kind: instance method of away
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Adds Away Rule.
Sends anti_theft.add_rule command and returns rule id.
Kind: instance method of away
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object |
||
| options.start | Date | number |
Date or number of minutes | |
| options.end | Date | number |
Date or number of minutes (only time component of date is used) | |
| options.daysOfWeek | Array.<number> |
[0,6] = weekend, [1,2,3,4,5] = weekdays | |
| [options.frequency] | number |
5 |
|
| [options.name] | string |
||
| [options.enable] | boolean |
true |
|
| [sendOptions] | SendOptions |
Edits Away rule.
Sends anti_theft.edit_rule command and returns rule id.
Kind: instance method of away
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object |
||
| options.id | string |
||
| options.start | Date | number |
Date or number of minutes | |
| options.end | Date | number |
Date or number of minutes (only time component of date is used) | |
| options.daysOfWeek | Array.<number> |
[0,6] = weekend, [1,2,3,4,5] = weekdays | |
| [options.frequency] | number |
5 |
|
| [options.name] | string |
||
| [options.enable] | boolean |
true |
|
| [sendOptions] | SendOptions |
Deletes All Away Rules.
Sends anti_theft.delete_all_rules command.
Kind: instance method of away
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Deletes Away Rule.
Sends anti_theft.delete_rule command.
Kind: instance method of away
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| id | string |
| [sendOptions] | SendOptions |
Enables or Disables Away Rules.
Sends anti_theft.set_overall_enable command.
Kind: instance method of away
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| enable | boolean |
| [sendOptions] | SendOptions |
Kind: instance property of Plug
- .cloud
- .getInfo([sendOptions]) ⇒
Promise.<Object, ResponseError> - .bind(username, password, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .unbind([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getFirmwareList([sendOptions]) ⇒
Promise.<Object, ResponseError> - .setServerUrl(server, [sendOptions]) ⇒
Promise.<Object, ResponseError>
- .getInfo([sendOptions]) ⇒
Gets device's TP-Link cloud info.
Requests cloud.get_info.
Kind: instance method of cloud
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Add device to TP-Link cloud.
Sends cloud.bind command.
Kind: instance method of cloud
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| username | string |
| password | string |
| [sendOptions] | SendOptions |
Remove device from TP-Link cloud.
Sends cloud.unbind command.
Kind: instance method of cloud
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Get device's TP-Link cloud firmware list.
Sends cloud.get_intl_fw_list command.
Kind: instance method of cloud
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Sets device's TP-Link cloud server URL.
Sends cloud.set_server_url command.
Kind: instance method of cloud
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type | Description |
|---|---|---|
| server | string |
URL |
| [sendOptions] | SendOptions |
Kind: instance property of Plug
- .emeter
- .realtime ⇒
Object - .getRealtime([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getDayStats(year, month, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .getMonthStats(year, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .eraseStats([sendOptions]) ⇒
Promise.<Object, ResponseError>
- .realtime ⇒
Returns cached results from last retrieval of emeter.get_realtime.
Kind: instance property of emeter
Gets device's current energy stats.
Requests emeter.get_realtime. Older devices return current, voltage,... while newer devices return current_ma, voltage_mv...
This will return a normalized response including both old and new style properies for backwards compatibility.
Kind: instance method of emeter
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Get Daily Emeter Statisics.
Sends emeter.get_daystat command.
Kind: instance method of emeter
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| year | number |
| month | number |
| [sendOptions] | SendOptions |
Get Monthly Emeter Statisics.
Sends emeter.get_monthstat command.
Kind: instance method of emeter
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| year | number |
| [sendOptions] | SendOptions |
Erase Emeter Statistics.
Sends emeter.erase_runtime_stat command.
Kind: instance method of emeter
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Kind: instance property of Plug
- .schedule
- .getNextAction([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getRules([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getRule(id, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .addRule(options, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .editRule(options, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .deleteAllRules([sendOptions]) ⇒
Promise.<Object, ResponseError> - .deleteRule(id, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .setOverallEnable(enable, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .getDayStats(year, month, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .getMonthStats(year, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .eraseStats([sendOptions]) ⇒
Promise.<Object, ResponseError>
- .getNextAction([sendOptions]) ⇒
Gets Next Schedule Rule Action.
Requests schedule.get_next_action.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Gets Schedule Rules.
Requests schedule.get_rules.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Gets Schedule Rule.
Requests schedule.get_rules and return rule matching Id
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response of rule
| Param | Type |
|---|---|
| id | string |
| [sendOptions] | SendOptions |
Adds Schedule rule.
Sends schedule.add_rule command and returns rule id.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object |
||
| options.powerState | boolean |
||
| options.start | Date | number |
Date or number of minutes | |
| [options.daysOfWeek] | Array.<number> |
[0,6] = weekend, [1,2,3,4,5] = weekdays | |
| [options.name] | string |
||
| [options.enable] | boolean |
true |
|
| [sendOptions] | SendOptions |
Edits Schedule rule.
Sends schedule.edit_rule command and returns rule id.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object |
||
| options.id | string |
||
| options.powerState | boolean |
||
| options.start | Date | number |
Date or number of minutes | |
| [options.daysOfWeek] | Array.<number> |
[0,6] = weekend, [1,2,3,4,5] = weekdays | |
| [options.name] | string |
[description] | |
| [options.enable] | boolean |
true |
|
| [sendOptions] | SendOptions |
Deletes All Schedule Rules.
Sends schedule.delete_all_rules command.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Deletes Schedule Rule.
Sends schedule.delete_rule command.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| id | string |
| [sendOptions] | SendOptions |
Enables or Disables Schedule Rules.
Sends schedule.set_overall_enable command.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| enable | boolean |
| [sendOptions] | SendOptions |
Get Daily Usage Statisics.
Sends schedule.get_daystat command.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| year | number |
| month | number |
| [sendOptions] | SendOptions |
Get Monthly Usage Statisics.
Sends schedule.get_monthstat command.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| year | number |
| [sendOptions] | SendOptions |
Erase Usage Statistics.
Sends schedule.erase_runtime_stat command.
Kind: instance method of schedule
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Kind: instance property of Plug
- .time
- .getTime([sendOptions]) ⇒
Promise.<Object, ResponseError> - .getTimezone([sendOptions]) ⇒
Promise.<Object, ResponseError>
- .getTime([sendOptions]) ⇒
Gets device's time.
Requests timesetting.get_time.
Kind: instance method of time
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Gets device's timezone.
Requests timesetting.get_timezone.
Kind: instance method of time
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Kind: instance property of Plug
- .timer
- .getRules([sendOptions]) ⇒
Promise.<Object, ResponseError> - .addRule(options, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .editRule(options, [sendOptions]) ⇒
Promise.<Object, ResponseError> - .deleteAllRules([sendOptions]) ⇒
Promise.<Object, ResponseError>
- .getRules([sendOptions]) ⇒
Get Countdown Timer Rule (only one allowed).
Requests count_down.get_rules.
Kind: instance method of timer
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Add Countdown Timer Rule (only one allowed).
Sends count_down.add_rule command.
Kind: instance method of timer
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object |
||
| options.delay | number |
delay in seconds | |
| options.powerState | boolean |
turn on or off device | |
| [options.name] | string |
"'timer'" |
rule name |
| [options.enable] | boolean |
true |
rule enabled |
| [options.deleteExisting] | boolean |
true |
send delete_all_rules command before adding |
| [sendOptions] | SendOptions |
Edit Countdown Timer Rule (only one allowed).
Sends count_down.edit_rule command.
Kind: instance method of timer
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object |
||
| options.id | string |
rule id | |
| options.delay | number |
delay in seconds | |
| options.powerState | number |
turn on or off device | |
| [options.name] | string |
"'timer'" |
rule name |
| [options.enable] | Boolean |
true |
rule enabled |
| [sendOptions] | SendOptions |
Delete Countdown Timer Rule (only one allowed).
Sends count_down.delete_all_rules command.
Kind: instance method of timer
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Returns cached results from last retrieval of system.sys_info.
Kind: instance property of Plug
Overrides: sysInfo
Returns: Object - system.sys_info
Determines if device is in use based on cached emeter.get_realtime results.
If device supports energy monitoring (HS110): power > inUseThreshold
Otherwise fallback on relay state: relay_state === 1
Kind: instance property of Plug
sys_info.relay_state === 1
Kind: instance property of Plug
Cached value of sys_info.alias.
Kind: instance property of Plug
Cached value of sys_info.deviceId.
Kind: instance property of Plug
Cached value of sys_info.[description|dev_name].
Kind: instance property of Plug
Cached value of sys_info.model.
Kind: instance property of Plug
Cached value of sys_info.alias.
Kind: instance property of Plug
Cached value of sys_info.[type|mic_type].
Kind: instance property of Plug
Type of device (or device if unknown).
Based on cached value of sys_info.[type|mic_type]
Kind: instance property of Plug
Returns: string - 'plub'|'bulb'|'device'
Cached value of sys_info.sw_ver.
Kind: instance property of Plug
Cached value of sys_info.hw_ver.
Kind: instance property of Plug
Cached value of sys_info.[mac|mic_mac|ethernet_mac].
Kind: instance property of Plug
Normalized cached value of sys_info.[mac|mic_mac|ethernet_mac]
Removes all non alphanumeric characters and makes uppercase
aa:bb:cc:00:11:22 will be normalized to AABBCC001122
Kind: instance property of Plug
Requests common Plug status details in a single request.
system.get_sysinfocloud.get_sysinfoemeter.get_realtimeschedule.get_next_action
Kind: instance method of Plug
Returns: Promise.<Object, Error> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Same as #inUse, but requests current emeter.get_realtime.
Kind: instance method of Plug
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Get Plug LED state (night mode).
Requests system.sys_info and returns true if led_off === 0.
Kind: instance method of Plug
Returns: Promise.<boolean, ResponseError> - LED State, true === on
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Turn Plug LED on/off (night mode).
Sends system.set_led_off command.
Kind: instance method of Plug
| Param | Type | Description |
|---|---|---|
| value | boolean |
LED State, true === on |
| [sendOptions] | SendOptions |
Get Plug relay state (on/off).
Requests system.get_sysinfo and returns true if relay_state === 1.
Kind: instance method of Plug
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Turns Plug relay on/off.
Sends system.set_relay_state command.
Kind: instance method of Plug
| Param | Type |
|---|---|
| value | boolean |
| [sendOptions] | SendOptions |
Toggles Plug relay state.
Requests system.get_sysinfo sets the power state to the opposite relay_state === 1 and return the new power state.
Kind: instance method of Plug
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Blink Plug LED.
Sends system.set_led_off command alternating on and off number of times at rate,
then sets the led to its pre-blink state.
Note: system.set_led_off is particulally slow, so blink rate is not guaranteed.
Kind: instance method of Plug
| Param | Type | Default |
|---|---|---|
| [times] | number |
5 |
| [rate] | number |
1000 |
| [sendOptions] | SendOptions |
Sends payload to device (using send)
Kind: instance method of Plug
Returns: Promise.<Object, Error> - parsed JSON response
| Param | Type |
|---|---|
| payload | Object | string |
| [sendOptions] | SendOptions |
Sends command(s) to device.
Calls #send and processes the response.
- If only one operation was sent:
- Promise fulfills with specific parsed JSON response for command.
Example:{system:{get_sysinfo:{}}}- resolves to:
{err_code:0,...}\ - instead of:
{system:{get_sysinfo:{err_code:0,...}}}(as #send would)
- resolves to:
- Promise fulfills with specific parsed JSON response for command.
- If more than one operation was sent:
- Promise fulfills with full parsed JSON response (same as #send)
Also, the response's err_code(s) are checked, if any are missing or != 0 the Promise is rejected with ResponseError.
Kind: instance method of Plug
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| command | Object | string |
| [sendOptions] | SendOptions |
Polls the device every interval.
Returns this (for chaining) that emits events based on state changes.
Refer to specific device sections for event details.
Kind: instance method of Plug
Returns: Device | Bulb | Plug - this
| Param | Type | Description |
|---|---|---|
| interval | number |
(ms) |
Stops device polling.
Kind: instance method of Plug
Gets device's SysInfo.
Requests system.sys_info from device.
Kind: instance method of Plug
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Change device's alias (name).
Sends system.set_dev_alias command.
Kind: instance method of Plug
| Param | Type |
|---|---|
| alias | string |
| [sendOptions] | SendOptions |
Set device's location.
Sends system.set_dev_location command.
Kind: instance method of Plug
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| latitude | number |
| longitude | number |
| [sendOptions] | SendOptions |
Gets device's model.
Requests system.sys_info and returns model name.
Kind: instance method of Plug
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| [sendOptions] | SendOptions |
Reboot device.
Sends system.reboot command.
Kind: instance method of Plug
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| delay | number |
| [sendOptions] | SendOptions |
Reset device.
Sends system.reset command.
Kind: instance method of Plug
Returns: Promise.<Object, ResponseError> - parsed JSON response
| Param | Type |
|---|---|
| delay | number |
| [sendOptions] | SendOptions |
Plug's relay was turned on.
Kind: event emitted by Plug
Plug's relay was turned off.
Kind: event emitted by Plug
Plug's relay state was updated from device. Fired regardless if status was changed.
Kind: event emitted by Plug
Properties
| Name | Type | Description |
|---|---|---|
| value | boolean |
Relay State |
Plug's relay was turned on or power draw exceeded inUseThreshold for HS110
Kind: event emitted by Plug
Plug's relay was turned off or power draw fell below inUseThreshold for HS110
Kind: event emitted by Plug
Plug's in-use state was updated from device. Fired regardless if status was changed.
Kind: event emitted by Plug
Properties
| Name | Type | Description |
|---|---|---|
| value | boolean |
In Use State |
Plug's Energy Monitoring Details were updated from device. Fired regardless if status was changed.
Kind: event emitted by Plug
Properties
| Name | Type | Description |
|---|---|---|
| value | Object |
emeterRealtime |
Send Options.
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| timeout | number |
(ms) |
| transport | string |
'tcp','udp' |
Represents an error result received from a TP-Link device.
Where response err_code != 0.
Kind: global class
Extends: Error
Thanks to George Georgovassilis and Thomas Baust for figuring out the HS1XX encryption. https://blog.georgovassilis.com/2016/05/07/controlling-the-tp-link-hs100-wi-fi-smart-plug/
Some design cues for Client based on node-lifx