![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.
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.
npm install codetheweb/tuyapi
const device = new TuyAPI({
id: 'xxxxxxxxxxxxxxxxxxxx',
key: 'xxxxxxxxxxxxxxxx',
ip: 'xxx.xxx.xxx.xxx',
persistentConnection: true});
device.on('connected',() => {
console.log('Connected to device.');
});
device.on('disconnected',() => {
console.log('Disconnected from device.');
});
device.on('data', data => {
console.log('Data from device:', data);
const status = data.dps['1'];
console.log('Current status:', status);
device.set({set: !status}).then(result => {
console.log('Result of setting status:', result);
});
});
device.on('error',(err) => {
console.log('Error: ' + err);
});
device.connect();
// Disconnect after 10 seconds
setTimeout(() => { device.disconnect(); }, 10000);
const TuyAPI = require('tuyapi');
const device = new TuyAPI({
id: 'xxxxxxxxxxxxxxxxxxxx',
key: 'xxxxxxxxxxxxxxxx',
ip: 'xxx.xxx.xxx.xxx'});
device.get().then(status => {
console.log('Status:', status);
device.set({set: !status}).then(result => {
console.log('Result of setting status to ' + !status + ': ' + result);
device.get().then(status => {
console.log('New status:', status);
return;
});
});
});
This should report the current status, set the device to the opposite of what it currently is, then report the changed status. The above examples will work with smart plugs; they may need some tweaking for other types of devices.
See the setup instructions for how to find the needed parameters.
tuyapi
. If you're experiencing issues, please try updating the device's firmware in the official app.See the docs.
To add your projects to either of the above lists, please open a pull request.
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.