Python interface to ESP8266MOD WiFi smart devices from Shenzhen Xenon
Switch branches/tags
Clone or download
Latest commit 7b89d38 Dec 2, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
pytuya Log library version Dec 3, 2018
.gitignore Initial commit Dec 2, 2017
.travis.yml Support Python 3.5 Jan 27, 2018
LICENSE Initial commit Dec 2, 2017 Add sean6541 acknowledgement Oct 9, 2018
requirements.txt Add requirements file Jan 25, 2018 Fix readme ref in setup, preventing install Oct 16, 2018 Remove logging basic config require caller to setup logging Dec 3, 2018


Build Status

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 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:


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

Related Projects


  • Major breakthroughs on protocol work came from 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