tplink-bulbs
v1.2.1
Published
TypeScript library to control TP-Link Tapo devices via cloud and local network.
Maintainers
Readme
tplink-bulbs
🚀 A modern TypeScript library to control TP-Link Tapo smart devices (like bulbs, plugs, cameras) via cloud API and local LAN.
📦 Installation
npm install tplink-bulbsor if using from local project:
npm installPlease make sure to ping your lamp once. To do this, you should get all your registered deviced and look for the IP address:
import * as TPLink from 'tplink-bulbs';
const email = '[email protected]';
const password = 'your-password';
async function run() {
const cloudApi = await TPLink.API.cloudLogin(email, password);
const devices = await cloudApi.listDevicesByType('SMART.TAPOBULB');
console.log(devices);
}
run().catch(console.error);Afterwards, ping the lamp. You can do this with tools like curl.
🚀 Quickstart Example
import * as TPLink from 'tplink-bulbs';
const email = '[email protected]';
const password = 'your-password';
const deviceId = 'your-device-id'; // Instead of working with the device ID, you can also use the device IP.
async function run() {
const cloudApi = await TPLink.API.cloudLogin(email, password);
const devices = await cloudApi.listDevicesByType('SMART.TAPOBULB');
console.log(devices);
const targetDevice = devices.find(device => device.deviceId === deviceId);
if (!targetDevice) {
console.error(`Device with ID "${deviceId}" not found.`);
return;
}
const device = await TPLink.API.loginDevice(email, password, targetDevice);
// If you already know the devices IP address, please use this:
// const device = await TPLink.API.loginDeviceByIp(email, password, deviceIp);
const info = await device.getDeviceInfo();
console.log('Device Info:', info);
await device.turnOn();
await device.setColor('violet');
await TPLink.API.delay(500);
await device.setColor('red');
await TPLink.API.delay(500);
await device.setColor('orange');
await TPLink.API.delay(500);
// colours can also be set using hex codes
await device.setColor('#00ff00');
await TPLink.API.delay(500);
// or by providing an RGB object
await device.setColor({ r: 0, g: 0, b: 255 });
await TPLink.API.delay(500);
// you can change only the brightness (or hue/saturation)
await device.setBrightness(50);
await TPLink.API.delay(500);
//...
}
run().catch(console.error);Note:
loginDeviceresolves the device's IP address via your local network. Ensure the machine running this code is connected to the same network as the Tapo device. If you already know the IP address or ARP discovery fails, callloginDeviceByIp(email, password, deviceIp)instead.
💡 Features
- Cloud login
- List devices from TP-Link Cloud
- Set color by name, hex, temperature and now also by HSL, HSV, CMYK or RGB
- A lot of color presets included
- Full TypeScript strict typing
- Easy to use
🌈 Available Color Presets
blue, red, yellow, green, cyan, magenta, orange, pink, turquoise, violet, lavender, coral, mint, teal, navy, olive, maroon, grey, white, daylightwhite, warmwhite
(And you can set any hex color like #ff0000 too!)
📄 License
ISC License
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Credits
Credits go to:
- https://github.com/dickydoouk/tp-link-tapo-connect
- https://github.com/fishbigger/TapoP100
- https://github.com/K4CZP3R/tapo-p100-java-poc
- https://gist.github.com/chriswheeldon/3b17d974db3817613c69191c0480fe55
