New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tuyapi

Package Overview
Dependencies
Maintainers
2
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tuyapi

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

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
824
decreased by-67.94%
Maintainers
2
Weekly downloads
 
Created
Source

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.

The id, uid, and key must be found by sniffing the app that came with your device.

Docs

TuyaDevice

Represents a Tuya device.

Parameters

  • options Object options for constructing a TuyaDevice
    • options.type string type of device (optional, default 'outlet')
    • options.ip string IP of device
    • options.port number port of device (optional, default 6668)
    • options.id string ID of device (called devId or gwId)
    • options.uid string UID of device
    • options.key string encryption key of device (called localKey)
    • options.version number protocol version (optional, default 3.1)
getStatus

Gets the device's current status.

Parameters

  • callback function (error, result)
setStatus

Sets the device's status.

Parameters

  • on boolean true for on, false for off
  • callback function (error, result) returns true if the command succeeded

Tests

npm test (runs the xo style linter)

TODO

  1. Either reuse a TCP connection between requests, keeping it alive by sending a packet every few seconds, or add a delay between subsequent commands.
  2. Figure out what the hex-encoded 'padding' is.
  3. Autodiscovery of devices?

Contributors

Keywords

FAQs

Package last updated on 27 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc