tplink-lightbulb 1.8.0
Control TP-Link smart-home devices from nodejs
Scan for lightbulbs on your network
Name | Type | Description | |
---|---|---|---|
filter | string |
[none] Only return devices with this class, (ie 'IOT.SMARTBULB') | |
broadcast | string |
['255.255.255.255'] Use this broadcast IP |
// turn first discovered light off
const scan = TPLSmartDevice.scan()
.on('light', light => {
light.power(false)
.then(status => {
console.log(status)
scan.stop()
})
})
EventEmitter
Emitlight
events when lightbulbs are found
Scans the wifi networks in range of the device
// scan for available wifi
const light = new TPLSmartDevice('10.0.0.200')
light.listwifi()
.then(info => {
console.log(info)
})
Promise
Resolves to output of command
Connects the device to the access point in the parameters
Name | Type | Description | |
---|---|---|---|
ssid | {String} Your wifi SSID | ||
password | {String} Your wifi secret | ||
keyType | {Number} The type of key (WPA 2 is 3, no key is 0) | ||
cypherType | {Number} The type of cypher (WPA2 is 2) |
// command a device to join a wifi network
const light = new TPLSmartDevice('10.0.0.200')
light.connectwifi("SSID", "PASSWORD", 3, 2)
.then(info => {
console.log(info)
})
Promise
Resolves to output of command
Get info about the TPLSmartDevice
// get info about a light
const light = new TPLSmartDevice('10.0.0.200')
light.info()
.then(info => {
console.log(info)
})
Promise
Resolves to info
Send a message to a lightbulb (for RAW JS message objects)
Name | Type | Description | |
---|---|---|---|
msg | Object |
Message to send to bulb |
const light = new TPLSmartDevice('10.0.0.200')
light.send({
'smartlife.iot.smartbulb.lightingservice': {
'transition_light_state': {
'on_off': 1,
'transition_period': 0
}
}})
.then(response => {
console.log(response)
})
.catch(e => console.error(e))
Promise
Resolves with answer
Set power-state of lightbulb
Name | Type | Description | |
---|---|---|---|
powerState | Boolean |
On or off | |
transition | Number |
Transition to new state in this time | |
options | Object |
Object containing mode , hue , saturation , color_temp , brightness |
// turn a light on
const light = new TPLSmartDevice('10.0.0.200')
light.power(true)
.then(status => {
console.log(status)
})
.catch(err => console.error(err))
Promise
Resolves to output of command
Set led-state of lightbulb
Name | Type | Description | |
---|---|---|---|
ledState | Boolean |
On or off |
// turn the LED status light on
const light = new TPLSmartDevice('10.0.0.200')
light.led(true)
.then(status => {
console.log(status)
})
.catch(err => console.error(err))
Promise
Resolves to output of command
Set the name of lightbulb
Name | Type | Description | |
---|---|---|---|
newAlias | String |
// change the name of a light
const light = new TPLSmartDevice('10.0.0.200')
light.setName("New Name")
.then(status => {
console.log(status)
})
.catch(err => console.error(err))
Promise
Resolves to output of command
Get schedule info
Name | Type | Description | |
---|---|---|---|
month | Number |
Month to check: 1-12 | |
year | Number |
Full year to check: ie 2017 |
// get the light's schedule for 1/2017
const light = new TPLSmartDevice('10.0.0.200')
light.schedule(1, 2017)
.then(schedule => {
console.log(schedule)
})
.catch(e => console.error(e))
Promise
Resolves to schedule info
Get cloud info from bulb
// get the cloud info for the light
const light = new TPLSmartDevice('10.0.0.200')
light.cloud()
.then(info => {
console.log(info)
})
.catch(e => console.error(e))
Promise
Resolves to cloud info
Get schedule from bulb
// get the bulb's schedule
const light = new TPLSmartDevice('10.0.0.200')
light.schedule()
.then(schedule => {
console.log(schedule)
})
.catch(e => console.error(e))
Promise
Resolves to schedule info
Get operational details from bulb
// get some extra details about the light
const light = new TPLSmartDevice('10.0.0.200')
light.details()
.then(details => {
console.log(details)
})
.catch(e => console.error(e))
Promise
Resolves to operational details
Reboot the device
// get some extra details about the light
const light = new TPLSmartDevice('10.0.0.200')
light.reboot()
.then(status => {
console.log(status)
})
.catch(e => console.error(e))
Promise
Resolves to output of command
Badly encrypt message in format bulbs use
Name | Type | Description | |
---|---|---|---|
buffer | Buffer |
Buffer of data to encrypt | |
key | Number |
Encryption key (default is generally correct) |
const encrypted = TPLSmartDevice.encrypt(Buffer.from('super secret text'))
Buffer
Encrypted data
Badly decrypt message from format bulbs use
Name | Type | Description | |
---|---|---|---|
buffer | Buffer |
Buffer of data to decrypt | |
key | Number |
Encryption key (default is generally correct) |
const decrypted = TPLSmartDevice.decrypt(encrypted)
Buffer
Decrypted data
Documentation generated with doxdox.