Skip to main content

Python interface to ESP8266MOD WiFi smart devices from Shenzhen Xenon

Project description

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

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>

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

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

pytuya-7.0.4.zip (11.2 kB view details)

Uploaded Source

File details

Details for the file pytuya-7.0.4.zip.

File metadata

  • Download URL: pytuya-7.0.4.zip
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

File hashes

Hashes for pytuya-7.0.4.zip
Algorithm Hash digest
SHA256 357a06db4ded37b624c356ad51d7324a2742248500bbbd8477e61ff1c304c74f
MD5 657ebcfe4ca88dc9fc64b2a71a095190
BLAKE2b-256 71f309e7b1c2cd16c756d0aa16e3382f8909f371aca56176fe3f9ffe36a60808

See more details on using hashes here.

Supported by

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