# tplink-smarthome-api

> TP-Link Smart Home API

Latest version **5.0.0** (published 2023-11-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install tplink-smarthome-api
pnpm add tplink-smarthome-api
yarn add tplink-smarthome-api
bun add tplink-smarthome-api
```

Provides the command `tplink-smarthome-api`.

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2023-11-15 |
| First published | 2017-10-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=16 |
| Dependencies | 11 |
| Unpacked size | 374.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1058 |
| Author | Patrick Seal |
| Maintainers | plasticrake |
| Keywords | tplink, kasa, home, smartplug, smartswitch, smartbulb, api |

## Links

- npm: https://www.npmjs.com/package/tplink-smarthome-api
- Repository: https://github.com/plasticrake/tplink-smarthome-api
- Homepage: https://github.com/plasticrake/tplink-smarthome-api#readme
- Issues: https://github.com/plasticrake/tplink-smarthome-api/issues
- npm.io page: https://npm.io/package/tplink-smarthome-api

## Dependencies (11)

- [loglevel](https://npm.io/package/loglevel.md) ^1.8.1
- [commander](https://npm.io/package/commander.md) ~11.1.0
- [lodash.get](https://npm.io/package/lodash.get.md) ^4.4.2
- [lodash.clone](https://npm.io/package/lodash.clone.md) ^4.5.0
- [promise-queue](https://npm.io/package/promise-queue.md) ^2.2.5
- [lodash.groupby](https://npm.io/package/lodash.groupby.md) ^4.6.0
- [lodash.isequal](https://npm.io/package/lodash.isequal.md) ^4.5.0
- [lodash.castarray](https://npm.io/package/lodash.castarray.md) ^4.4.0
- [lodash.defaultto](https://npm.io/package/lodash.defaultto.md) ^4.14.0
- [tplink-smarthome-crypto](https://npm.io/package/tplink-smarthome-crypto.md) ^4.0.0
- [@commander-js/extra-typings](https://npm.io/package/@commander-js/extra-typings.md) ~11.1.0

## Recent versions

- 5.0.0 (latest) — 2023-11-15
- 3.0.0-beta.2 (next) — 2020-10-12
- 4.2.0 — 2022-02-14
- 4.1.0 — 2022-02-03
- 4.0.0 — 2022-02-02
- 3.3.0 — 2021-03-01
- 3.2.1 — 2021-02-28
- 3.2.0 — 2021-02-28
- 3.1.0 — 2020-10-13
- 3.0.0 — 2020-10-13
- 3.0.0-beta.1 — 2020-10-11
- 3.0.0-beta.0 — 2020-08-27
- 3.0.0-beta — 2020-06-29
- 2.0.0 — 2020-01-01
- 1.3.0 — 2019-12-16
- … 8 more at https://npm.io/package/tplink-smarthome-api/versions

## README

<!-- markdownlint-disable MD007 MD012 MD033 -->

# tplink-smarthome-api

[![NPM Version](https://img.shields.io/npm/v/tplink-smarthome-api.svg)](https://www.npmjs.com/package/tplink-smarthome-api)
[![Build Status](https://github.com/plasticrake/tplink-smarthome-api/workflows/CI/badge.svg?branch=main)](https://github.com/plasticrake/tplink-smarthome-api/actions?query=workflow%3ACI+branch%3Amain)
[![Coverage Status](https://coveralls.io/repos/github/plasticrake/tplink-smarthome-api/badge.svg?branch=master)](https://coveralls.io/github/plasticrake/tplink-smarthome-api?branch=master)

TP-Link Smarthome API

**[Changelog](https://github.com/plasticrake/tplink-smarthome-api/tree/main/CHANGELOG.md)**

## Known Supported Devices

| Model                                                                                                    | Type               |
| -------------------------------------------------------------------------------------------------------- | ------------------ |
| HS100, HS103, HS105, HS107, HS110,<br/>HS200, HS210, HS220, HS300, KP303, KP400<br/>ES20M, EP40, ...etc. | Plug               |
| LB100, LB110, LB120, LB130, LB200, LB230, KL50, KL120, KL125<br/>...etc.                                 | Bulb               |
| KL430<br/>...etc.                                                                                        | Bulb (light strip) |

Many other TP-Link Plug and Bulb models may work as well. Note that Tapo devices are not supported.

## Related Projects

- [TP-Link Smarthome Device Simulator](https://github.com/plasticrake/tplink-smarthome-simulator) - Useful for automated testing
- [TP-Link Smarthome Crypto](https://github.com/plasticrake/tplink-smarthome-crypto)
- [TP-Link Smarthome Homebridge Plugin](https://github.com/plasticrake/homebridge-tplink-smarthome)

## Examples

See more [examples](https://github.com/plasticrake/tplink-smarthome-api/tree/main/examples).

```javascript
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);
});
```

## CLI

Install the command line utility with `npm install -g tplink-smarthome-api`. Run `tplink-smarthome-api --help` for help.

## API

[API docs can be found here.](https://plasticrake.github.io/tplink-smarthome-api/)

For functions that send commands, the last argument is `SendOptions` where you can set the `transport` ('tcp','udp') 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.)

## Credits

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](https://github.com/MariusRumpf/node-lifx/)

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