![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
An easy-to-use API for devices that use Tuya's cloud services (currently only supports smart plugs)
A library for communicating with devices that use the Tuya cloud network. These devices are branded under many different names, but if port 6668 is open on your device chances are this library will work with it. Currently only supports smart plugs, but it should be fairly trivial to add other types of devices.
npm install @codetheweb/tuyapi
const TuyaDevice = require('tuyapi');
var tuya = new TuyaDevice({
type: 'outlet',
ip: 'xxx.yyy.0.zzz',
id: 'xxxxxxxxxxxxxxxxxxxx',
uid: 'xxxxxxxxxxxxxxxxxxxx',
key: 'xxxxxxxxxxxxxxxx'});
tuya.getStatus(function(error, status) {
if (error) { return console.log(error); }
console.log('Status: ' + status);
tuya.setStatus(!status, function(error, result) {
if (error) { return console.log(error); }
console.log('Result of setting status to ' + !status + ': ' + result);
tuya.getStatus(function(error, status) {
if (error) { return console.log(error); }
console.log('New status: ' + status);
});
});
});
This should report the current status, set the device to the opposite of what it currently is, then report the changed status.
The id
, uid
, and key
must be found by sniffing the app that came with your device. Your tool must be able to sniff HTTPS traffic for this to work. For macOS, Charles is probably the best option.
Represents a Tuya device.
Parameters
options
Object options for constructing a TuyaDevice
options.type
string type of device (optional, default 'outlet'
)options.ip
string IP of deviceoptions.port
number port of device (optional, default 6668
)options.id
string ID of device (called devId
or gwId
)options.uid
string UID of deviceoptions.key
string encryption key of device (called localKey
)options.version
number protocol version (optional, default 3.1
)Gets the device's current status.
Parameters
callback
function (error, result)Sets the device's status.
Parameters
on
boolean true
for on, false
for offcallback
function (error, result) returns true
if the command succeedednpm test
(runs the xo style linter)
homebridge-tuya: a Homebridge plugin for Tuya devices
FAQs
An easy-to-use API for devices that use Tuya's cloud services
The npm package tuyapi receives a total of 2,223 weekly downloads. As such, tuyapi popularity was classified as popular.
We found that tuyapi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.