All Projects → codetheweb → Tuyapi

codetheweb / Tuyapi

Licence: mit
🌧 An easy-to-use API for devices that use Tuya's cloud services. Documentation: https://codetheweb.github.io/tuyapi.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Tuyapi

Waterius
Передача показаний воды по Wi-Fi. Watermeter Wi-Fi transmitter.
Stars: ✭ 295 (-71.72%)
Mutual labels:  smarthome, iot
Redmatic
Node-RED packaged as Addon for the Homematic CCU3 and RaspberryMatic 🤹‍♂️
Stars: ✭ 407 (-60.98%)
Mutual labels:  smarthome, iot
Hoobs
Build your Smart Home with HOOBS. Connect over 2,000 Accessories to your favorite Ecosystem.
Stars: ✭ 325 (-68.84%)
Mutual labels:  smarthome, iot
Tuya Convert
A collection of scripts to flash Tuya IoT devices to alternative firmwares
Stars: ✭ 3,338 (+220.04%)
Mutual labels:  smarthome, iot
Smarthome
Eclipse SmartHome™ project
Stars: ✭ 867 (-16.87%)
Mutual labels:  smarthome, iot
Awesome Smarthome
Curated list of awesome SmartHome/Home Automation things (open and leaving users in control)
Stars: ✭ 274 (-73.73%)
Mutual labels:  smarthome, iot
Mqtt Smarthome
Smart home automation with MQTT as the central message bus - Architectural proposal
Stars: ✭ 356 (-65.87%)
Mutual labels:  smarthome, iot
Wirehome.core
Wirehome.Core is a home automation system written in C# targeting .NET Core. It runs on Linux, Windows and macOS.
Stars: ✭ 180 (-82.74%)
Mutual labels:  smarthome, iot
Raspberrymatic
🏠 A lightweight, buildroot-based Linux operating system alternative for your CCU3, ELV-Charly or for running your IoT "HomeMatic CCU" as a virtual appliance (using ESXi, Proxmox, VirtualBox, Docker/OCI, Kubernetes/K8s, Home Assistant, etc.) or on your own RaspberryPi, Tinkerboard, etc. SBC devices...
Stars: ✭ 803 (-23.01%)
Mutual labels:  smarthome, iot
Smartir
Integration for Home Assistant to control climate, TV and fan devices via IR/RF controllers (Broadlink, Xiaomi, MQTT, LOOKin, ESPHome)
Stars: ✭ 677 (-35.09%)
Mutual labels:  smarthome, iot
ambianic-edge
The core runtime engine for Ambianic Edge devices.
Stars: ✭ 98 (-90.6%)
Mutual labels:  smarthome, local
Tp Link Smart Switch Web Client
Creating a web client for the tp-link series of smart switches (HS-100, HS-110, etc).
Stars: ✭ 31 (-97.03%)
Mutual labels:  smarthome, iot
Basecamp
An Arduino library to ease the use of the ESP32 in IoT projects
Stars: ✭ 251 (-75.93%)
Mutual labels:  smarthome, iot
Awesome Home Assistant
A curated list of amazingly awesome Home Assistant resources.
Stars: ✭ 3,487 (+234.32%)
Mutual labels:  smarthome, iot
Node Tradfri Client
Library to talk to IKEA Trådfri Gateways without external binaries
Stars: ✭ 193 (-81.5%)
Mutual labels:  smarthome, iot
Home Assistantconfig
🏠 Home Assistant configuration & Documentation for my Smart House. Write-ups, videos, part lists, and links throughout. Be sure to ⭐ it. Updated FREQUENTLY!
Stars: ✭ 3,687 (+253.5%)
Mutual labels:  smarthome, iot
Iobroker.docker
Official Docker Image for ioBroker
Stars: ✭ 133 (-87.25%)
Mutual labels:  smarthome, iot
Gladys
A privacy-first, open-source home assistant
Stars: ✭ 1,874 (+79.67%)
Mutual labels:  smarthome, iot
Assistant Relay
A Node.js server that allows for sending commands to Google Home/Assistant from endpoints
Stars: ✭ 638 (-38.83%)
Mutual labels:  smarthome, iot
Hodd
Homie Device Discovery
Stars: ✭ 21 (-97.99%)
Mutual labels:  smarthome, iot

TuyAPI 🌧 🔌

XO code style Build Status Coverage Status Node Version

A library for communicating with devices that use the Tuya cloud network. These devices are branded under many different names, but if your device works with the TuyaSmart app or port 6668 is open on your device chances are this library will work.

Installation

npm install codetheweb/tuyapi

Basic Usage

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

These examples should report the current status, set the default property to the opposite of what it currently is, then report the changed status. They will need to be adapted if your device does not have a boolean property at index 1 (i.e. it doesn't have an on/off property). Index 20 seems to be another somewhat common on/off property.

Asynchronous (event based, recommended)

const TuyAPI = require('tuyapi');

const device = new TuyAPI({
  id: 'xxxxxxxxxxxxxxxxxxxx',
  key: 'xxxxxxxxxxxxxxxx'});

let stateHasChanged = false;

// Find device on network
device.find().then(() => {
  // Connect to device
  device.connect();
});

// Add event listeners
device.on('connected', () => {
  console.log('Connected to device!');
});

device.on('disconnected', () => {
  console.log('Disconnected from device.');
});

device.on('error', error => {
  console.log('Error!', error);
});

device.on('data', data => {
  console.log('Data from device:', data);

  console.log(`Boolean status of default property: ${data.dps['1']}.`);

  // Set default property to opposite
  if (!stateHasChanged) {
    device.set({set: !(data.dps['1'])});

    // Otherwise we'll be stuck in an endless
    // loop of toggling the state.
    stateHasChanged = true;
  }
});

// Disconnect after 10 seconds
setTimeout(() => { device.disconnect(); }, 10000);

Synchronous

const TuyAPI = require('tuyapi');

const device = new TuyAPI({
  id: 'xxxxxxxxxxxxxxxxxxxx',
  key: 'xxxxxxxxxxxxxxxx',
  issueGetOnConnect: false});

(async () => {
  await device.find();

  await device.connect();

  let status = await device.get();

  console.log(`Current status: ${status}.`);

  await device.set({set: !status});

  status = await device.get();

  console.log(`New status: ${status}.`);

  device.disconnect();
})();

📝 Notes

  • Only one TCP connection can be in use with a device at once. If using this, do not have the app on your phone open.
  • Some devices ship with older firmware that may not work with tuyapi. If you're experiencing issues, please try updating the device's firmware in the official app.
  • Newer firmware may use protocol 3.3. If you are not using find(), you will need to manually pass version: 3.3 to the constructor.
  • TuyAPI does not support sensors due to the fact that they only connect to the network when their state changes. There are no plans to add support as it's out of scope to intercept network requests.
  • The key parameter for devices changes every time a device is removed and re-added to the TuyaSmart app. If you're getting decrypt errors, try getting the key again - it might have changed.

📓 Documentation

See the docs.

Contributing

See CONTRIBUTING.

Contributors

(If you're not on the above list, open a PR.)

Related

Flash alternative firmware

  • tuya-convert a project that allows you to flash custom firmware OTA on devices

Ports

Clients for Tuya's Cloud

Projects built with TuyAPI

To add your project to either of the above lists, please open a pull request.

forthebadge forthebadge

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].