npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tuya-smartlife-api

v0.8.4

Published

Library/CLI interface for Tuya IoT devices through the Smart Life API

Readme

Tuya Smart Life API + CLI

Tests Releases

Usage requirements

  • install package locally
npm install -S tuya-smartlife-api
  • import module (ESM or CJS)
/* ESM */
import { TuyaSmartLifeClient } from "tuya-smartlife-api";
/* CommonJS */
// const TuyaSmartLifeClient = require("tuya-smartlife-api").TuyaSmartLifeClient;

const client = new TuyaSmartLifeClient();
try {
	await client.init('[email protected]', 'password', 'eu');
	await client.discoverDevices();

	const tDevices = client.getAllDevices();
	console.log(tDevices);

	const myLightBulbs = await client.getDevicesByType('light');
	await myLightBulbs[0].turnOn();

} catch (e) {
	console.error('Failed because', e);
}

Note: Consider using an .env file with dotenv.

Note: check your Tuya region.

  • install package globally
npm install -g tuya-smartlife-api
  • verify installation
tuyacli
Usage: tuyacli [options] [command]

Options:
  -V, --version                   output the version number
  -h, --help                      display help for command

Commands:
  auth                            login with SmartLife
  test                            live test a selected device's functions set
  list [options]                  list devices and their state / attributes
  control [options] <name-or-id>  control a device's state
  help                            output usage information

Examples


# Authenticate /will be automatically called later if skipped the first time/
tuyacli auth

# List all devices
tuyacli list [--format={short|long}]

# Perform interactiv device tests
tuyacli test 

# Turn device ID on / off
tuyacli control <ID|Name> --state [1|on]
tuyacli control <ID|Name> --state [0|off]
tuyacli control <ID|Name> --toggle

# Set light brightness, color temp & color 
tuyacli control <ID|Name> --brightness 30 
tuyacli control <ID|Name> --temperature 3500 # set warm temp
tuyacli control <ID|Name> --hsl 78.34,1,100 # HSL chill green
tuyacli control <ID|Name> --hsl 324.77,1,42 # HSL chill purple
tuyacli control <ID|Name> --rgb 90,30,115 # RGB something

Note: Use node tuyacli in module's root folder if not installed globally.

Note: The <ID|Name> portion is treated as a filtering pattern rather than a full identifier. Conviniently, tuyacli control bulb -s off would turn off all devices with the pattern "bulb" in their names, but use with caution. ID would be used for large setups, where Name is not applicable.


Tests

npm test
tuyacli test

Note: Use node tuyacli in module's root folder if not installed globally.

Note: Tests might fail if attempted multiple times before LOGIN_INTERVAL seconds have passed since last run.


Roadmap

  • [x] port and optimize TuyaPy
  • [x] implement integration tests
  • [x] implement pure CLI
    • [x] list devices (short / long format)
    • [x] control a device's state
    • [x] control a device's custom attributes
  • [x] use Configstore for credentials & device cache (not session.json)
    • [ ] encrypt credentials at rest
  • [x] implement unit tests
  • [x] add support for CommonJS
  • [ ] document code & generate JSDoc
  • [ ] dockerize
  • [ ] implement classes for other IoT devices (climate, fan, lock, etc.)
  • [ ] ~~implement TUI with blessed-contrib~~

Credits License

Inspired by TuyaPy (backend) and SmartLife (web) interfaces to Tuya's SmartAtHome for IoT smart device control.

See also