Skip to main content

Interact with devices connected to the Tuya IOT platform through Python

Project description

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.

Installation

pip3 install EasyTuya

Requirements

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 thisThe project page
  • 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

Usage

Full documentation can be found at here

Usage example: A simple program to control a group of lights through command line input

from EasyTuya import TuyaAPI
from EasyTuya.devices import Lights

if __name__ == "__main__":
    api = TuyaAPI("your_client_id", "your_access_secret")
    l1 = Lights.Light("your_device_id_1", "Light 1")
    l2 = Lights.Light("your_device_id_2", "Light 2")
    api.addDevices([l1, l2], "LIGHTS")
    while(True):
        toDo = input()
        if toDo == "on":
            api.sendCommands("LIGHTS", Lights.onCommand())
        elif toDo == "off":
            api.sendCommands("LIGHTS", Lights.offCommand())
        elif toDo == "white":
            api.sendCommands("LIGHTS", Lights.workModeCommand("white"))
        elif toDo == "color":
            api.sendCommands("LIGHTS", Lights.workModeCommand("colour"))
        elif toDo == "red":
            api.sendCommands("LIGHTS", Lights.colorCommand(Lights.redHSV))
        elif toDo == "blue":
            api.sendCommands("LIGHTS", Lights.colorCommand(Lights.blueHSV))
        elif toDo == "rainbow":
            api.sendCommands("LIGHTS", Lights.sceneCommand(4))
        elif toDo.split()[0] == "bright":
            api.sendCommands("LIGHTS", Lights.brightnessCommand(int(toDo.split()[1])))
        elif toDo == "onoff":
            api.sendCommands("LIGHTS", api.devices['LIGHTS'][0].toggleOnOff())
        elif toDo == "status":
            print(api.getStatus("LIGHTS"))

Other Notes

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. The device list page

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

EasyTuya-0.1.371.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

EasyTuya-0.1.371-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file EasyTuya-0.1.371.tar.gz.

File metadata

  • Download URL: EasyTuya-0.1.371.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.4

File hashes

Hashes for EasyTuya-0.1.371.tar.gz
Algorithm Hash digest
SHA256 b4c17288159b94fe90f54c8247d5733555fce0855b7e5925640c2efe558c80ae
MD5 6ab5f7bf22e75dd179fcafa2d806867f
BLAKE2b-256 f1080b5c1cb35c8e94ce9eebc09291e3f7029d45d7eb27b942502d4e127ea747

See more details on using hashes here.

File details

Details for the file EasyTuya-0.1.371-py3-none-any.whl.

File metadata

  • Download URL: EasyTuya-0.1.371-py3-none-any.whl
  • Upload date:
  • Size: 19.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.4

File hashes

Hashes for EasyTuya-0.1.371-py3-none-any.whl
Algorithm Hash digest
SHA256 3e756023c077b7b09344d7b520ff4b4314ac4178daa0a34556610b6207152fc0
MD5 e6c5558a06e8818d65798a71a8e47ccd
BLAKE2b-256 401713cbf94b7757386f2ac2e2adaed3a06f00029442a52e4c779e78ee377af4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page