Skip to main content

[![Build Status](https://travis-ci.org/clach04/python-tuya.svg?branch=master)](https://travis-ci.org/clach04/python-tuya)

NOTE I’m no longer using these devices so this is not actively maintained. https://github.com/codetheweb/tuyapi node.js based is active and being updated on a regular basis.

Python 2.7 and Python 3.6.1 interface to ESP8266MOD WiFi smart devices from Shenzhen Xenon.

If you are using the Jinvoo Smart App, this allows local control over the LAN.

NOTE requires the devices to have already been activated by Jinvoo Smart App (or similar).

## Key extraction

https://github.com/clach04/python-tuya/wiki has background information for how to get device id and local key.

(the device id can be seen in Jinvoo Smart App, under “Device Info”).

Known to work with:

Demo:

import pytuya

d = pytuya.OutletDevice(‘DEVICE_ID_HERE’, ‘IP_ADDRESS_HERE’, ‘LOCAL_KEY_HERE’)

data = d.status() # NOTE this does NOT require a valid key

print(‘Dictionary %r’ % data)

print(‘state (bool, true is ON) %r’ % data[‘dps’][‘1’]) # Show status of first controlled switch on device

# Toggle switch state

switch_state = data[‘dps’][‘1’]

data = d.set_status(not switch_state) # This requires a valid key

if data:

print(‘set_status() result %r’ % data)

# on a switch that has 4 controllable ports, turn the fourth OFF (1 is the first)

data = d.set_status(False, 4)

if data:

print(‘set_status() result %r’ % data)

print(‘set_status() extrat %r’ % data[20:-8])

TODO demo timer (with comment not all devices support this, one way to check, is to check Jinvoo Smart App and see if there is a clock icon that is not dimmed out).

### Encryption notes

These devices uses AES encryption, this is not available in Python standard library, there are three options:

  1. PyCrypto

  2. PyCryptodome

  3. pyaes (note Python 2.x support requires https://github.com/ricmoo/pyaes/pull/13)

### Related Projects

### Acknowledgements

  • Major breakthroughs on protocol work came from https://github.com/codetheweb/tuyapi from the reverse engineering time and skills of codetheweb and blackrozes, additional protocol reverse engineering from jepsonrob and clach04.

  • nijave pycryptodome support and testing

  • Exilit for unittests and docstrings

  • mike-gracia for improved Python version support

  • samuscherer for RGB Bulb support

  • magneticflux- for improved Python version support

  • sean6541 - for initial PyPi package and Home Assistant support <https://github.com/sean6541/tuya-homeassistant>

  • ziirish - for resolving a dependcy problem related to version numbers at install time

Keywords: home automation Platform: any Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: Topic :: Home Automation Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.6 Classifier: Topic :: Home Automation

Metadata

Release files for pytuya 7.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytuya 7.0.6
File Size Uploaded
pytuya-7.0.6.zip 11.6 kB Details

Release files / pytuya-7.0.6.zip

Download URL pytuya-7.0.6.zip
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
847b51fec055751f9d90f0798b56eaf8aadd45f512bdc556fc9597eeb966e68e
BLAKE2b-256 checksum
How to use checksums
3582a10d977c4a0879c37275e2793d983a8b7ac0f6738e937cdc159d4f3a15c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/18.0.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/2.7.10

Release history Release notifications | RSS feed

This release

7.0.6 This release

1 release file

7.0.5

1 release file

7.0.4

1 release file

7.0.2

1 release file

7.0.1

1 release file

7.0

1 release file

6.0

1 release file

5.0

1 release file

4.0

1 release file

3.0

1 release file

2.0

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page