A NodeJS wrapper for Tuya's API.
At the moment, only the mobile/app API 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
Step-by-step instructions for acquiring keys to use with the old API can be found here.
Obtaining keys for new API (additional parameters
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.
npm i @tuyapi/cloud
old API (register/login and create token):
const Cloud = ;let api = key: 'your-api-app-key' secret: 'your-api-app-secret';api;
new API (listing all devices in all groups):
const Cloud = ;let api = key: apiKeyskeysecret: apiKeyssecretsecret2: apiKeyssecret2certSign: apiKeyscertSignapiEtVersion: '0.0.1'region: 'EU';api;
- After cloning, run
- 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. Since
.gitignore, it won't be committed.
- To run tests, run
- To output coverage, run
npm run cover(it will exit with an error).
- To build documentation, run
npm run document.