This tutorial describes how to install Tuya official Homebridge plugin on macOS to connect smart devices and develop Homebridge plugins.
HomeKit is Apple’s smart home platform introduced in 2014. It allows users of Apple devices to securely and easily control any devices with Works with Apple HomeKit badges, such as lights, door locks, thermostats, outlets, and many more.
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 official Homebridge docs before getting started with Homebridge plugins.
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.
Used to install plugins and start Homebridge service.
It can be iPhone, iPad, and Apple Watch, used to control HomeKit-enabled devices.
It can be a smart light, switch, or socket, used to demonstrate device integration and control.
Used to install the Device Manager app to pair devices.
See the section Before use in tuya-iot-app-sdk-python, register an account on the Tuya IoT Platform, and get the required information. Basically, you need to create a Cloud project and complete the configuration of asset, user, and application. Then, you will get the username, password, Access ID, and Access Secret.
Hardware | Description |
---|---|
A computer, 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 | Description |
---|---|
Command line interface | Use the one you like. We use the built-in Terminal on macOS. |
Pairing tool | Device Manager app or WeChat Mini Program (mainland China only). |
Open the Terminal.
See the official Homebridge docs and install Homebridge on your system.
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.
Before use, you need to configure the config.json
file in the Homebridge plugin.
Go to the directory homebridge-tuya-platform
.
cd ./node_modules/homebridge-tuya-platform
Go to the directory config
.
cd ./config
Edit the config.json
file.
vim config.json
In options
, enter the username
, password
, accessId
, and accessKey
that you get from the Tuya IoT Platform. The lang
defaults to en
. The endPoint
is the domain name of the currently used Tuya Open API.
Region | endPoint |
---|---|
America | https://openapi.tuyaus.com |
China | https://openapi.tuyacn.com |
Europe | https://openapi.tuyaeu.com |
India | https://openapi.tuyain.com |
Eastern America | https://openapi-ueaz.tuyaus.com |
Western Europe | https://openapi-weaz.tuyaeu.com |
Save and exit.
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.
Fork Tuya’s Homebridge repo in GitHub and follow the step-by-step tutorial to start the plugin service.
—-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"
The entry file index.js
. Add your desired accessory type to the addAccessory()
function and create the xx_accessy.js
file.
The xx_accessory.js
file. In this file, traverse your newly created function in refreshAccessoryServiceIfNeed()
and get the Characteristic
corresponding to a service.
The tuyaopenapi.js
file contains device related APIs.
The tuyamqttapi.js
file supports the MQTT service.
For more information about Homebridge installation, see the Common Issues in the Homebridge repo.
login(username, password)
: Login to the Tuya IoT Platform.getDeviceList()
: Gets all the devices under an account’s asset. (The term device corresponds to the term accessory in the HomeKit ecosystem)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 a single device.getDeviceListInfo(devIds = [])
: Gets the information of multiple devices.getDeviceStatus(deviceID)
: Gets the status of a single device.getDeviceListStatus(devIds = [])
: Gets the status of multiple devices.sendCommand(deviceID, params)
: Sends commands to a device.start()
: Starts MQTT.stop()
: Stops MQTT.addMessageListener(listener)
: Adds callbacks.removeMessageListener(listener)
: Removes callbacks.Is this page helpful?
YesSuggestions