https://github.com/konsumer/kasa_control
use kasa-cloud to hit your TPLink bulbs in nodejs
https://github.com/konsumer/kasa_control
Last synced: 12 months ago
JSON representation
use kasa-cloud to hit your TPLink bulbs in nodejs
- Host: GitHub
- URL: https://github.com/konsumer/kasa_control
- Owner: konsumer
- Created: 2018-05-09T09:54:47.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-11-12T00:28:32.000Z (over 2 years ago)
- Last Synced: 2025-04-02T22:33:16.306Z (about 1 year ago)
- Language: JavaScript
- Size: 560 KB
- Stars: 10
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# kasa-control
This will let you use kasa-cloud to hit your TPLink bulbs in nodejs.
If you'd like to hit them directly, on your local network, use [tplink-lightbulb](https://github.com/konsumer/tplink-lightbulb). This library is for situations where you want to use a username/password (from [tplink cloud](https://www.tplinkcloud.com/).) It will allow you to acces them remotely.
## installation
```sh
npm i kasa_control
```
### example usage
```js
const KasaControl = require('kasa_control')
const kasa = new KasaControl()
const main = async () => {
await kasa.login('email', 'password')
const devices = await kasa.getDevices()
// turn off first device
await kasa.power(devices[0].deviceId, false)
}
main()
```
## api
-
send ⇒Promise -
Send a message to a lightbulb (for RAW JS message objects)
-
getDevices ⇒Promise -
Get a list of devices for your Kasa account
-
info ⇒Promise -
Get info about a device
-
power ⇒Promise -
Set power-state of lightbulb
## send ⇒ Promise
Send a message to a lightbulb (for RAW JS message objects)
**Returns**: Promise - Resolves with answer
| Param | Type | Description |
| --- | --- | --- |
| deviceId | string | The deviceId of the device in your kasa app |
| msg | Object | Message to send to bulb |
**Example**
```js
kasa.send('80126E22B048C76F341BEED1A3EA8E77177F3484', {
'smartlife.iot.smartbulb.lightingservice': {
'transition_light_state': {
'on_off': 1,
'transition_period': 0
}
})
.then(response => {
console.log(response)
})
.catch(e => console.error(e))
```
## getDevices ⇒ Promise
Get a list of devices for your Kasa account
**Returns**: Promise - Resolves to an array of device-objects
**Example**
```js
kasa.getDevices()
.then(devices => {
console.log(devices)
})
.catch(e => console.error(e))
```
## info ⇒ Promise
Get info about a device
**Returns**: Promise - Resolves to an info-pbject about your device
example
```js
kasa.info('80126E22B048C76F341BEED1A3EA8E77177F3484')
.then(info => {
console.log(info)
})
.catch(e => console.error(e))
```
| Param | Type | Description |
| --- | --- | --- |
| deviceId | string | The deviceId of the device in your kasa app |
## power ⇒ Promise
Set power-state of lightbulb
**Returns**: Promise - Resolves to output of command
| Param | Type | Description |
| --- | --- | --- |
| deviceId | string | The deviceId of the device in your kasa app |
| powerState | Boolean | On or off |
| transition | Number | Transition to new state in this time |
| options | Object | Object containing `mode`, `hue`, `saturation`, `color_temp`, `brightness` |
**Example**
```js
// turn a light on
kasa.power('80126E22B048C76F341BEED1A3EA8E77177F3484', true)
.then(status => {
console.log(status)
})
.catch(err => console.error(err))
```
## thanks
Thanks to itnerd for these 3 articles:
* [authenticate](http://itnerd.space/2017/06/19/how-to-authenticate-to-tp-link-cloud-api/)
* [deviceList](http://itnerd.space/2017/05/21/how-to-get-the-tp-link-hs100-cloud-end-point-url/)
* [passthrough](http://itnerd.space/2017/01/22/how-to-control-your-tp-link-hs100-smartplug-from-internet/)