Interact with devices connected to the Tuya IOT platform through Python
EasyTuya - Making IOT Control With Python Easy
EasyTuya is a module containing nearly all needed functionality for interacting with your Tuya powered IOT devices through Python. This is done using Tuya's web API, meaning that for this module to work you will need a cloud developer account on Tuya's website. Full instructions for this and general setup can be found below. If you have not already, to use this you must also download the TuyaSmart app on your phone and add your compatible devices.
pip3 install EasyTuya
Tuya Account Setup - IMPORTANT!!
- Make a developer account on Tuya's site
- Once signed in click on "Cloud Development" (or go to https://iot.tuya.com/cloud/)
- Create a project
- Click on your new project, you should see a screen similar to this
- Note your client ID and access secret
- Go to "Link Devices" under device management, then select the tab titled "Link devices by App Account"
- Follow instructions on the site to add your Tuya app account and connected devices
- Click "API Group" in the left sidebar, then click "Apply" on the groups: "Authorization Management", "Device Management", and "Device Control"
- Open other API group as needed by your usage
from EasyTuya import TuyaAPI from EasyTuya.devices import Lights if __name__ == "__main__": api = TuyaAPI("9ea9sk54a0k2978837d6", "d6034d97286c4b049ee16874a5a2d92d") l1 = Lights.Light("64304636a4cf12d76aad", "Light 1") l2 = Lights.Light("55008855483fdac28931", "Light 2") api.addDevices([l1, l2], "BRLIGHTS") while(True): toDo = input() if toDo == "on": api.sendGroupCommand("BRLIGHTS", Lights.onCommand()) elif toDo == "off": api.sendGroupCommand("BRLIGHTS", Lights.offCommand()) elif toDo == "white": api.sendGroupCommand("BRLIGHTS", Lights.colorCommand("white")) elif toDo == "rainbow": api.sendGroupCommand("BRLIGHTS", Lights.gorgCommand(255, 191)) elif toDo.split() == "bright": api.sendGroupCommand("BRLIGHTS", Lights.brightCommand(int(toDo.split()))) elif toDo == "onoff": api.sendGroupCommand("BRLIGHTS", api.devices['BRLIGHTS'].toggleOnOff()) elif toDo == "refresh": api.refreshAccessToken()
Finding Device IDs
To find your device IDs, go to: Tuya developer site -> Device Management -> Device List Select your correct country from the drop down near the center of the page, then your devices should show up each with their name displayed above their device id, as shown in the following image.
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for EasyTuya-0.1.1-py2.py3-none-any.whl