Skip to content
forked from codetheweb/tuyapi

An easy-to-use API for devices that use Tuya's cloud services (currently only supports smart plugs)

License

Notifications You must be signed in to change notification settings

jepsonrob/tuyapi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TuyAPI 🌧 🔌 XO code style

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. Currently only supports smart plugs, but it should be fairly trivial to add other types of devices.

Installation

npm install codetheweb/tuyapi

Basic Usage

const TuyaDevice = require('tuyapi');

var tuya = new TuyaDevice({
  type: 'outlet',
  ip: 'xxx.yyy.0.zzz',
  id: 'xxxxxxxxxxxxxxxxxxxx',
  uid: 'xxxxxxxxxxxxxxxxxxxx',
  key: 'xxxxxxxxxxxxxxxx'});

tuya.getStatus(function(error, status) {
  if (error) { return console.log(error); }
  console.log('Status: ' + status);

  tuya.setStatus(!status, function(error, result) {
    if (error) { return console.log(error); }
    console.log('Result of setting status to ' + !status + ': ' + result);

    tuya.getStatus(function(error, status) {
      if (error) { return console.log(error); }
      console.log('New status: ' + status);
    });
  });
});

This should report the current status, set the device to the opposite of what it currently is, then report the changed status.

See the setup instructions for how to find the needed parameters.

Docs

See the docs. IMPORTANT: Only one TCP connection can be in use with a device at once. If testing this, do not have the app on your phone open.

TODO

  1. Reuse a TCP connection between subsequent commands, instead of creating a new one every time.
  2. Figure out what the hex-encoded 'padding' is.
  3. Autodiscovery of devices?

Contributors

Related

homebridge-tuya: a Homebridge plugin for Tuya devices

About

An easy-to-use API for devices that use Tuya's cloud services (currently only supports smart plugs)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%