Git Product home page Git Product logo

tuya-cloud-api's Introduction

Tuya Cloud API

API for Tuya Cloud

No dependencies ๐Ÿ’ช


Installation

npm i tuya-cloud

Example (test.js)

const tuyaCloud = require('tuya-cloud');

tuyaCloud.connect({
  region: 'eu', // eu (Default) / us / cn / in
  clientID: 'xxxxxxxxxxxxxxxxxxxx',
  secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
}).then(async (tuya) => {
  console.log('Logged !')

  const tempSensor = tuya.device('xxxxxxxxxxxxxxxxxxxxxx');

  setInterval(async () => {
    console.log(await tempSensor.getInfos());
    console.log(await tempSensor.getStatus());
  }, 10000);

  const light = tuya.device('xxxxxxxxxxxxxxxxxxxxxx');

  console.log(await light.getFunctions());
  console.log(await light.getStatus());

  light.sendCommands([
    {
      code: 'colour_data',
      value: {
        h: 120, // Green
        s: 1000,
        v: 1000,
      },
    },
  ]);

}).catch((error) => {
  console.error(error.message);
});

Problems

If you have errors in console or unwanted behavior, just reload the page. If the problem persists, please create an issue here.

tuya-cloud-api's People

Contributors

mathieu2301 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dkpkr89

tuya-cloud-api's Issues

Error: "Can't login to API: sign invalid"

Hello
When connecting with the api I get this error, I don't really understand where the problem comes from, normally everything is well configured on iot.tuya.com because I already use the python api

Thank u

Suggestion for new method: userDevices

There is an interesting function to list users' devices.
If you like it, here's the change.
Thanks for your class.

--- node_modules/tuya-cloud/main.js	2021-12-01 14:55:16.840267542 +0100
+++ main.js	2021-12-01 14:56:50.377182428 +0100
@@ -61,7 +61,8 @@
       const t = Date.now();
       const sign = calcSign(t, session.token);
 
-      return request(method, `devices/${deviceId}${path}`, {
+      if(deviceId) path=`devices/${deviceId}${path}`;
+      return request(method, path, {
         client_id: clientID,
         t, sign,
         access_token: session.token,
@@ -110,6 +111,9 @@
             },
           }
         },
+        async userDevices(uuid) {
+	    return (await requester.rq(null,`users/${uuid}/devices`,'GET'));
+        }
       });
     });
   },

Allow choosing other regions

hostname: 'openapi.tuyaeu.com',

Currently, the library appears to be hard-coded to the EU datacenter for Tuya Cloud.

Perhaps add an option to the constructor to allow choosing other datacenters like China or North America?

Thanks for a great library!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.