tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).

MIT License

Downloads
89.9K
Stars
831
Committers
46
tinytuya - v1.10.0 - Tuya Protocol v3.5 Device Support / Scanner Rewrite

Published by jasonacox almost 2 years ago

What's Changed

TinyTuya [1.10.0]

Usage:

    python -m tinytuya <command> [<max_time>] [-nocolor] [-force [192.168.0.0/24 192.168.1.0/24 ...]] [-h]

      wizard         Launch Setup Wizard to get Tuya Local KEYs.
      scan           Scan local network for Tuya devices.
      devices        Scan all devices listed in devices.json file.
      snapshot       Scan devices listed in snapshot.json file.
      json           Scan devices listed in snapshot.json file [JSON].
      <max_time>     Maximum time to find Tuya devices [Default=18]
      -nocolor       Disable color text output.
      -force         Force network scan for device IP addresses.  Auto-detects network range if none provided.
      -no-broadcasts Ignore broadcast packets when force scanning.
      -h             Show usage.

New Contributors

Full Changelog: https://github.com/jasonacox/tinytuya/compare/v1.9.1...v1.10.0

tinytuya - v1.9.1 - Minor Bug Fix for Cloud

Published by jasonacox almost 2 years ago

  • PyPI 1.9.1
  • Fix logging for Cloud _gettoken() to prevent extraneous output. #229

Full Changelog: https://github.com/jasonacox/tinytuya/compare/v1.9.0...v1.9.1

tinytuya - v1.9.0 - Zigbee Gateway Support

Published by jasonacox almost 2 years ago

What's Changed

import tinytuya

# Zigbee Gateway support uses a parent/child model where a parent gateway device is
#  connected and then one or more children are added.

# Configure the parent device
gw = tinytuya.Device( 'eb...4', address=None, local_key='aabbccddeeffgghh', persist=True, version=3.3 )

print( 'GW IP found:', gw.address )

# Configure one or more children.  Every dev_id must be unique!
zigbee1 = tinytuya.OutletDevice( 'eb14...w', cid='0011223344556601', parent=gw )
zigbee2 = tinytuya.OutletDevice( 'eb04...l', cid='0011223344556689', parent=gw )

print(zigbee1.status())
print(zigbee2.status())

New Contributors

Full Changelog: https://github.com/jasonacox/tinytuya/compare/v1.8.0...v1.9.0

tinytuya - v1.8.0 - Expanded Cloud Functions

Published by jasonacox almost 2 years ago

What's Changed

import tinytuya
import json

c = tinytuya.Cloud()
r = c.getdevicelog( '00112233445566778899' )
print( json.dumps(r, indent=2) )

New Contributors

Full Changelog: https://github.com/jasonacox/tinytuya/compare/v1.7.2...v1.8.0

tinytuya - v1.7.2 - Fix Contrib Devices Bug

Published by jasonacox almost 2 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/jasonacox/tinytuya/compare/v1.7.1...v1.7.2

tinytuya - v1.7.1 - Auto-IP Detection Enhancement

Published by jasonacox about 2 years ago

What's Changed

import tinytuya 

# Specify only Device ID and tinytuya will scan for IP 
# and lookup Device Local KEY from devices.json

d = tinytuya.OutletDevice( '0123456789abcdef0123' )

New Contributors

Full Changelog: https://github.com/jasonacox/tinytuya/compare/v1.7.0...v1.7.1

tinytuya - v1.7.0 - Tuya Protocol v3.4 Device Support

Published by jasonacox about 2 years ago

What's Changed

d = tinytuya.OutletDevice(
    dev_id='xxxxxxxxxxxxxxxxxxxxxxxx',
    address='x.x.x.x',
    local_key='xxxxxxxxxxxxxxxx',
    version=3.4)

print(d.status())

Full Changelog: https://github.com/jasonacox/tinytuya/compare/v1.6.6...v1.7.0

tinytuya - v1.6.6 - Updated Payload Dictionary and Command List

Published by jasonacox about 2 years ago

What's Changed

# Example usage of community contributed device modules
from tinytuya.Contrib import SocketDevice

socket = SocketDevice('abcdefghijklmnop123456', '172.28.321.475', '1234567890123abc', version=3.3)

print(socket.get_energy_consumption())
print(socket.get_state())

New Contributors

Full Changelog: https://github.com/jasonacox/tinytuya/compare/v1.6.5...v1.6.6

tinytuya - v1.6.5 - Updated Payload Dictionary and Command List

Published by jasonacox about 2 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/jasonacox/tinytuya/compare/v1.6.4...v1.6.5

tinytuya - v1.6.4 - IRRemoteControlDevice and Read Improvements

Published by jasonacox over 2 years ago

What's Changed

# Example usage of community contributed device modules
from tinytuya import Contrib

ir = Contrib.IRRemoteControlDevice( 'abcdefghijklmnop123456', '172.28.321.475', '1234567890123abc' )

New Contributors

Full Changelog: https://github.com/jasonacox/tinytuya/compare/v1.6.2...v1.6.4

tinytuya - v1.6.2 - Cloud, TuyaMessage & ThermostatDevice Improvements

Published by jasonacox over 2 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/jasonacox/tinytuya/compare/v1.6.1...v1.6.2

tinytuya - v1.6.1 - ThermostatDevice - User Contributed Device Module

Published by jasonacox over 2 years ago

What's Changed

# Example usage of community contributed device modules
from tinytuya import Contrib

thermo = Contrib.ThermostatDevice( 'abcdefghijklmnop123456', '172.28.321.475', '1234567890123abc' )

New Contributors

Full Changelog: https://github.com/jasonacox/tinytuya/compare/v1.6.0...v1.6.1

tinytuya - v1.6.0 - Colorama for Terminal Color

Published by jasonacox over 2 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/jasonacox/tinytuya/compare/v1.5.0...v1.6.0

tinytuya - v1.5.0 - Add "nowait" Option to Commands

Published by jasonacox over 2 years ago

What's Changed

New Contributors

# Example use of nowait option
d.turn_on(nowait=True)
d.set_colour(r, g, b, nowait=True)
d.set_value(201, '9AEmAvQBJgL0ASYCQAYmAkAGJgJABiY', nowait=True)  # send IR command
d.set_value(25, '010e0d0000000000000003e803e8', nowait=True)      # set scene

Full Changelog: https://github.com/jasonacox/tinytuya/compare/v1.4.0...v1.5.0

tinytuya - v1.4.0 - Updated Scanner Functions

Published by jasonacox over 2 years ago

What's Changed

  • PyPI 1.4.0 - Minor Update to APIs (additional arguments and elements)
  • Debug - Updated debug output for payloads to formatted hexadecimal (pull request #98)
  • Scan - Terminal color fix for 3.1 devices.
  • Error Handling added for set_timer() function (Issue #87)
  • Add galaxy lamp example by @knrdl in https://github.com/jasonacox/tinytuya/pull/115
  • Add wizard capability to pull mac addresses from TuyaPlatform in devices.json (Issue #117)
  • Add wizard -force option to perform network scan for device IP addresses (Issue #117)
  • Added support to get the MAC address and local IP address in the Wizard by @frodeheg in https://github.com/jasonacox/tinytuya/pull/120
  • Separated scan functions into scanner.py file.
  • NEW: Added command line functions for scanning:
    • devices - Display and poll all registered devices for status (using devices.json). This will force a network scan for IP address changes and will create snapshot.json.
    • snapshot - Display and poll all devices as listed snapshot.json. This assume IP address are the same as the last snapshot.
    • json - Same as snapshot but respond with a JSON payload.
# Run wizard using brute force scan for IP addresses
python -m tinytuya wizard -force

# New Interactive Command Line Options
python -m tinytuya devices
python -m tinytuya snapshot

# Non-Interactive poll with JSON response
python -m tinytuya json

New Contributors

Full Changelog: https://github.com/jasonacox/tinytuya/compare/v1.3.1...v1.4.0

tinytuya - v1.3.1 - TuyaCloud API Support

Published by jasonacox over 2 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/jasonacox/tinytuya/compare/v1.3.0...v1.3.1

tinytuya - v1.3.0 - TuyaCloud API Support

Published by jasonacox almost 3 years ago

  • Code format cleanup and readability improvements (pull request #91)
  • Upgrade - Add TuyaCloud API support and functions (#87 #95)
import tinytuya

c = tinytuya.Cloud(
        apiRegion="us", 
        apiKey="xxxxxxxxxxxxxxxxxxxx", 
        apiSecret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 
        apiDeviceID="xxxxxxxxxxxxxxxxxxID")

# Display list of devices
devices = c.getdevices()
print("Device List: %r" % devices)

# Select a Device ID to Test
id = "xxxxxxxxxxxxxxxxxxID"

# Display DPS IDs of Device
result = c.getdps(id)
print("DPS IDs of device:\n", result)

# Display Status of Device
result = c.getstatus(id)
print("Status of device:\n", result)

# Send Command - This example assumes a basic switch
commands = {
	'commands': [{
		'code': 'switch_1',
		'value': True
	}, {
		'code': 'countdown_1',
		'value': 0
	}]
}
print("Sending command...")
result = c.sendcommand(id,commands)
print("Results\n:", result)
tinytuya - v1.2.11 - Updated Scan and Wizard Retry Logic

Published by jasonacox almost 3 years ago

  • Added retries logic to wizard and scan to honor value set by command line or default to a value based on the number of devices (if known):
# Explicit value set via command line
python3 -m tinytuya wizard 50   # Set retry to 50 
python3 -m tinytuya scan 50     

# Use automatic computed value
python3 -m tinytuya wizard      # Compute a default
python3 -m tinytuya scan        

# Example output
TinyTuya (Tuya device scanner) [1.2.11]

[Loaded devices.json - 32 devices]

Scanning on UDP ports 6666 and 6667 for devices (47 retries)...
tinytuya - v1.2.10 - Wizard Update for New Tuya Regions

Published by jasonacox almost 3 years ago

  • PyPi Version 1.2.10
  • Added ability to disable device auto-detect (default vs device22) via d.disabledetect=True.
  • Wizard: Added new data center regions for Tuya Cloud: (Issues #66 #75)
Code Region Endpoint
cn China Data Center https://openapi.tuyacn.com
us Western America Data Center https://openapi.tuyaus.com
us-e Eastern America Data Center https://openapi-ueaz.tuyaus.com
eu Central Europe Data Center https://openapi.tuyaeu.com
eu-w Western Europe Data Center https://openapi-weaz.tuyaeu.com
in India Data Center https://openapi.tuyain.com
tinytuya - v1.2.9 - Edge Case Device Support

Published by jasonacox about 3 years ago

  • PyPi Version 1.2.9
  • Added Error Handling in class Device(XenonDevice) for conditions where response is None (Issue #68)
  • Added edge-case handler in _decode_payload() to decode non-string type decrypted payload (Issue #67)