TP-Link Smarthome API
| Model | Type |
|---|---|
| HS100, HS103, HS105, HS107, HS110, HS200, HS210, HS220, HS300, KP303, KP400 ES20M, EP40, ...etc. |
Plug |
| KS240, KS225, S500D ...etc. |
Plug (SMART, experimental) |
| LB100, LB110, LB120, LB130, LB200, LB230, KL50, KL120, KL125 ...etc. |
Bulb |
| KL430 ...etc. |
Bulb (light strip) |
Many other TP-Link Plug and Bulb models may work as well. Note that Tapo devices are not supported.
- Child-scoped operations (
childId) are supported for plug modules such asaway,schedule,timer,emeter, anddimmer. - For child channels that expose brightness in child sysinfo (for example dimmer + fan combinations), dimmer capability is detected from child data when a
childIdis selected. - This project primarily targets the legacy TP-Link Smart Home protocol (
IOT.*on port9999), and now includes experimental authenticated HTTP transports:klapandaes(credential orcredentialsHashbased). - If
sysInfoincludes encryption metadata (mgt_encrypt_schm.encrypt_typeand optionalhttp_port), device defaults are inferred automatically (klap/aestransport and port) unless you explicitly override them. - For SMART requests over authenticated transports, use
client.sendSmart(...),device.sendSmartCommand(...), anddevice.sendSmartRequests(...)(including child-scopedcontrol_childwrapping). - Initial SMART switch support includes SMART power/LED paths and high-level helpers for
fan,lightPreset,lightTransition, andoverheatProtection(including child-scoped KS240 channels). - SMART switch support now also includes:
- dimmer brightness/switch-state (
set_device_info) - timer mapping to SMART
auto_off - away/schedule mapping (
get_antitheft_rules,get_schedule_rules,get_next_event, plus SMART write/delete/enable calls) - SMART emeter realtime mapping (
get_emeter_datawithget_energy_usagefallback) - SMART emeter periodic stats compatibility (
get_runtime_statwhen available, fallback synthesis fromget_energy_usage) - SMART time/cloud read paths (
get_device_time,get_connect_cloud_state) - SMART cloud admin/write attempts (
bind,unbind,getFirmwareList,setServerUrl) using method candidates for device-family differences
- dimmer brightness/switch-state (
- Some SMART write/admin methods vary by firmware/model; this library uses best-effort SMART method candidates and throws when the device does not expose a compatible method.
- SMART switch capabilities now use component negotiation (
component_nego, child component lists) for module gating. You can callawait plug.negotiateSmartComponents()explicitly;getSysInfo()over SMART transport performs this lazily on first use. - Full python-kasa parity is still in progress; not every SMART component has a dedicated module yet.
- 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', 'klap', 'aes') and timeout, etc.
Functions that take more than 3 arguments are passed a single options object as the first argument (and if its a network command, SendOptions as the second.)
Example SMART over KLAP:
const client = new Client({
credentials: { username: 'user@example.com', password: 'secret' },
});
const device = client.getPlug({ host: '10.0.1.2', sysInfo });
const info = await device.sendSmartCommand('get_device_info');
const multi = await device.sendSmartRequests([
{ method: 'get_device_info' },
{ method: 'get_device_time' },
]);Thanks to George Georgovassilis and Thomas Baust for figuring out the HS1XX encryption.
Some design cues for Client based on node-lifx