Skip to content

Homebridge custom plugin for controlling Powered by Tuya (PBT) devices in HomeKit. This plugin is officially maintained by the Tuya Developer Team.

License

Notifications You must be signed in to change notification settings

rcoletti116/tuya-homebridge

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tuya Homebridge Plugin


npm npm verified-by-homebridge

Homebridge custom plugin for controlling Powered by Tuya (PBT) devices in HomeKit, it's based on Tuya Open API. The plugin is officially maintained by the Tuya Developer Team.

https://www.npmjs.com/package/homebridge-tuya-platform

Supported Tuya Device Types

The following Tuya Device types are currently supported by this plugin:

  • Light: Supports Tuya Wi-Fi light devices.
  • Outlet: Supports Tuya Wi-Fi Outlet devices.
  • Smoke Sensor: Supports Tuya smoke sensor devices.
  • Switch: Supports Tuya switch devices.
  • Heater: Support Tuya heater devices.
  • Garage Door: Support Tuya smart garage door devices.
  • Fan: Support Tuya fan devices.
  • Air Purifier: Support Tuya air purifier devices.

Tuya Homebridge Integration User Guide

For more information, please check How to Use Tuya Homebridge Plugin.

Preparation

Registration

Create a cloud project of Smart Home PaaS on the Tuya IoT Platform and linked devices with this project. For more information, see Tuya IoT Platform Configuration Guide Using Smart Home PaaS.

Hardware Preparation

Hardware Description
A Mac/PC, Raspberry Pi, or server Install plugins and start Homebridge service. This demonstration runs on macOS.
Smart devices Demonstrate device integration and control.
An iOS device with the Home app installed Control HomeKit-enabled devices.

Software Preparation

Software Description
Command line interface Use the one you like. We use the built-in Terminal on macOS.
Pairing tool Tuya Device Manager App or WeChat Mini Program (mainland China only).

Quick Start

1. Open the Terminal.

Terminal

2. Check the Homebridge and install Homebridge in your system.

3. Install Tuya Homebridge plugin.

Note: If you encounter any problems with the installation, you may need to preface this command with sudo to make it run as an administrator.

  1. Install plugins.
    npm install homebridge-tuya-platform
    
  2. Wait for the plugin to install and check whether the installation is successful. For more information, see the video below.

Configuration

You need to configure the config.json file in the Homebridge plugin.

  1. Go to the directory homebridge-tuya-platform.

    cd ./node_modules/homebridge-tuya-platform
    
  2. Go to the directory config.

    cd ./config 
    
  3. Edit the config.json file.

    vim config.json
    
  4. Specify values for options.

  • username and password: The user name and password of your Tuya Smart App or Tuya Smart Life App account.

  • accessId and accessKey: The AccessID and Access Secret of your cloud project respectively. Go to the Tuya IoT Platform and select your cloud project. Navigate to the Project Overview tab and find the Authorization key.

Edit registration information

  • lang: Keep the default value en.

  • projectType: "Custom Development" is 1, "Smart Home PaaS" is 2. Here we choose 2.

  • appSchema: Use "tuyaSmart" for Tuya Smart App. Use "smartlife" for Tuya Smart Life App.

  • endPoint: Set it to the address of your location.

    1. America:
     https://openapi.tuyaus.com
    
    1. China:
     https://openapi.tuyacn.com
    
    1. Europe:
     https://openapi.tuyaeu.com
    
    1. India:
     https://openapi.tuyain.com
    
    1. EasternAmerica:
     https://openapi-ueaz.tuyaus.com
    
    1. WesternEurope:
     https://openapi-weaz.tuyaeu.com
    

5. Save and close the file.

Start Tuya Homebridge Plugin

  1. Go back to the directory homebridge-tuya-platform.

    cd ..
    
  2. Start the plugin.

    homebridge -D -U ./config/ -P ./ 
    

Bridge to HomeKit

Open the Home app on your Apple device. Pair with Homebridge by scanning the QR code printed in the step of starting the plugin, or entering the 8-digit PIN code. You can find the PIN code in the config.json file.

Contribution guide

Fork Tuya's Homebridge repo in GitHub and follow the step-by-step tutorial to start the plugin service.

Set up the development environment

—-VSCode
—-engines
    "node": “>=0.12.0”
    "homebridge": ">=0.2.0"
—-dependencies
    "axios": “^0.21.1",
    "crypto-js": “^4.0.0”, 
    "mqtt": “^4.2.6",
    "uuid": "^8.3.2"

Support more accessory types

How to implement plugins

Plugin development

Pay attention to several JSON files

  • The entry file index.js. Add your desired accessory type to the addAccessory() function and create the xx_accessy.js file.

JSON file

  • The xx_accessory.js file. In this file, traverse your newly created function in refreshAccessoryServiceIfNeed() and get the Characteristic corresponding to a service.

JSON file

  • The tuyaopenapi.js file contains device related APIs.
  • The tuyamqttapi.js file supports the MQTT service.

Common issues

For more information about Homebridge installation, see the Common Issues in the Homebridge repo.

Tuya Open API

  • login(username, password): Login to the Tuya IoT Platform.
  • getDeviceList(): Gets all the devices under an account's asset. (Devices correspond to accessories)
  • get_assets(): Gets the available assets.
  • getDeviceIDList(assetID): Queries the list of device IDs under an asset.
  • getDeviceFunctions(deviceID): Gets the instruction set.
  • getDeviceInfo(deviceID): Gets the information of single device.
  • getDeviceListInfo(devIds = []): Gets the information of multiple devices.
  • getDeviceStatus(deviceID): Gets the status of single device.
  • getDeviceListStatus(devIds = []): Gets the status of multiple devices.
  • sendCommand(deviceID, params): Sends commands to a device.

For more info, please check the Tuya Open API docs.

MQTT

  • start(): Starts MQTT.
  • stop(): Stops MQTT.
  • addMessageListener(listener): Adds callbacks.
  • removeMessageListener(listener): Removes callbacks.

What is HomeKit?

HomeKit is Apple's smart home platform introduced in 2014. It allows users of Apple devices to securely and easily control any devices with a 'Works with Apple HomeKit' badge, such as lights, door locks, thermostats, outlets, and many more.

What is Homebridge?

Homebridge is a lightweight NodeJS server you can run on your home network that emulates the iOS HomeKit API. It supports plugins that provide a basic bridge from HomeKit to various third-party APIs provided by manufacturers of smart home devices. We recommend you check the Homebridge before getting started with Homebridge plugins.

Users

If you are a smart home geek and have a bundle of devices from different platforms, this step-by-step tutorial will help you make devices HomeKit-enabled and then develop Tuya Homebridge plugins.

Feedback

You can use the GitHub Issue or tickets to provide feedback on any problems you encounter.

LICENSE

For more information, see the LICENSE file.

About

Homebridge custom plugin for controlling Powered by Tuya (PBT) devices in HomeKit. This plugin is officially maintained by the Tuya Developer Team.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • JavaScript 100.0%