New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

kasa_control

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kasa_control

Use kasa-cloud to hit your TPLink bulbs in nodejs

latest
Source
npmnpm
Version
0.1.2
Version published
Maintainers
1
Created
Source

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. This library is for situations where you want to use a username/password (from tplink cloud.) It will allow you to acces them remotely.

installation

npm i kasa_control

example usage

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

sendPromise

Send a message to a lightbulb (for RAW JS message objects)

getDevicesPromise

Get a list of devices for your Kasa account

infoPromise

Get info about a device

powerPromise

Set power-state of lightbulb

send ⇒ Promise

Send a message to a lightbulb (for RAW JS message objects)

Returns: Promise - Resolves with answer

ParamTypeDescription
deviceIdstringThe deviceId of the device in your kasa app
msgObjectMessage to send to bulb

Example

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

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

kasa.info('80126E22B048C76F341BEED1A3EA8E77177F3484')
  .then(info => {
    console.log(info)
  })
  .catch(e => console.error(e))
ParamTypeDescription
deviceIdstringThe deviceId of the device in your kasa app

power ⇒ Promise

Set power-state of lightbulb

Returns: Promise - Resolves to output of command

ParamTypeDescription
deviceIdstringThe deviceId of the device in your kasa app
powerStateBooleanOn or off
transitionNumberTransition to new state in this time
optionsObjectObject containing mode, hue, saturation, color_temp, brightness

Example

// 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:

FAQs

Package last updated on 16 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts