Cloud
๐จ ๐ A NodeJS wrapper for Tuya's cloud API. Documentation: https://tuyaapi.github.io/cloud/.
Install / Use
/learn @TuyaAPI/CloudREADME
tuyapi/cloud

A NodeJS wrapper for Tuya's API.
At the moment, only the mobile/app API (as captured by web.archive.org) is supported as it covers the vast majority of use cases.
There are two modes of operation:
- the 'old' API - described in the docs, using MD5 as a sign mechanism
- the 'new' API - reverse-engineered from the TuyaSmart Android app, using HMAC-SHA256 as a sign mechanism
If you can, use the old API. Unfortunately, for some clientId/key's you must use the new API (eg. clientId used by TuyaSmart app). To use the the new API, specify apiEtVersion as an option in constructor (currently '0.0.1').
Step-by-step instructions for acquiring keys to use with the old API can be found here.
Obtaining keys for new API (additional parameters secret2 and certSign are required) involves disassembling obtained an APK file (either official app or generated "demo" app from iot.tuya.com). For details see tuya-sign-hacking repo.
Installation
npm i @tuyapi/cloud
Usage
old API (register/login and create token):
const Cloud = require('@tuyapi/cloud');
let api = new Cloud({key: 'your-api-app-key', secret: 'your-api-app-secret'});
api.register({email: 'example@example.com', password: 'example-password'}).then(async sid => {
let token = await api.request({action: 'tuya.m.device.token.create', data: {'timeZone': '-05:00'}});
console.log(token) // => { secret: '0000', token: '01010101' }
});
new API (listing all devices in all groups):
const Cloud = require('@tuyapi/cloud');
let api = new Cloud({key: apiKeys.key,
secret: apiKeys.secret,
secret2: apiKeys.secret2,
certSign: apiKeys.certSign,
apiEtVersion: '0.0.1',
region: 'EU'});
api.loginEx({email: myEmail, password: myPassword}).then(async sid => {
console.log(sid);
api.request({action: 'tuya.m.location.list'}).then(async groups => {
for (const group of groups) {
api.request({action: 'tuya.m.my.group.device.list', gid: group.groupId}).then(async devicesArr => {
for (const device of devicesArr) {
console.log('group: "%s"\tdevice: "%s"\tdevId: "%s"', group.name, device.name, device.devId);
}
});
}
});
});
Development
- After cloning, run
npm i. - Add a file called
keys.jsonwith the contents
{
"key": "your-api-key",
"secret": "your-api-secret"
// for new API: add also secret2 and certSign
}
- Create a file called
dev.jsas a playground. Sincedev.jsis in.gitignore, it won't be committed. - To run tests, run
npm test. - To output coverage, run
npm run cover(it will exit with an error). - To build documentation, run
npm run document.
Related Skills
node-connect
344.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
99.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.4kQQBot ๅฏๅชไฝๆถๅ่ฝๅใไฝฟ็จ <qqmedia> ๆ ็ญพ๏ผ็ณป็ปๆ นๆฎๆไปถๆฉๅฑๅ่ชๅจ่ฏๅซ็ฑปๅ๏ผๅพ็/่ฏญ้ณ/่ง้ข/ๆไปถ๏ผใ
