Home

Awesome

cloudtuya

Tuya control over the cloud

This Node.js API allows you to control your Tuya / Smart Life Devices by just passing your email and password, that you are using in the Tuya/Smart Life app. This library is using an Tuya API endpoint, that was specially designed for Home Assistant.

A good reference of the capibilities is the tuyaha project, which actually is a library, written in python.

Get Started

This example will turn off the first device you've set up in Tuya / Smart Life. Also a devices.json file will get created with a list of all your devices and it's current state.

How to call the API

The following shows a basic script how you can turn on a lamp and set it's brightness

const api = new CloudTuya({
  userName: apiKeys.userName,
  password: apiKeys.password,
  bizType: apiKeys.bizType,
  countryCode: apiKeys.countryCode,
  region: apiKeys.region,
});
await api.login();

deviceId = devices[0].id;

var myLight =  new Light({ api: api, deviceId: deviceId});

myLight.turnOn();
myLight.setBrightness(80);
var brightness = await myLight.getBrightness();

Example Files

Example Script showing how to use cloudtuya

Take a look at the example.js file, to see how to call the cloudtuya API.

Example keys.json

{
  "userName": "YOURSMARTLIFEEMAIL",
  "password": "YOURSMARTLIFEPASSWORD",
  "bizType": "smart_life",
  "countryCode": "44",
  "region": "eu"
}

The following values are available