Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Author: Jason A. Cox https://github.com/jasonacox/tuyapower
Python module to pull power and state data from Tuya WiFi smart devices. Tested on RaspberryPi, Linux, Windows 10 and MacOS.
This module requires: pycryptodome and tinytuya (replaces pytuya).
# Install required libraries
sudo apt-get install python-crypto python-pip # for RPi, Linux
python3 -m pip install pycryptodome # or pycrypto, pyaes or Crypto
python3 -m pip install tinytuya # or pytuya
python3 -m pip install tuyapower # this tuyapower module
For Windows 10 users or if you get errors related to Crypto, try installing the pycryptodome module:
pip install pycryptodome
(on, w, mA, V, err) = tuyapower.deviceInfo(PLUGID, PLUGIP, PLUGKEY, PLUGVERS)
rawData = tuyapower.deviceRaw(PLUGID, PLUGIP, PLUGKEY, PLUGVERS)
tuyapower.devicePrint(PLUGID, PLUGIP, PLUGKEY, PLUGVERS)
dataJSON = tuyapower.deviceJSON(PLUGID, PLUGIP, PLUGKEY, PLUGVERS)
verbose = False
devices = tuyapower.deviceScan(verbose)
Note: If error occurs, on will be set to false, w, mA and V will be set to -99.0.
# Poll a Single Devices
import tuyapower
PLUGID = '01234567891234567890'
PLUGIP = '10.0.1.99'
PLUGKEY = '0123456789abcdef'
PLUGVERS = '3.1'
(on, w, mA, V, err) = tuyapower.deviceInfo(PLUGID,PLUGIP,PLUGKEY,PLUGVERS)
# Scan Network for All Devices
# To see output on stdout set verbose True
tuyapower.deviceScan(True)
Scanning on UDP port 6666 for devices...
FOUND Device [Valid payload]: 10.0.1.100
ID = 01234567891234567890, Key = 0123456789abcdef, Version = 3.1
Stats: on=True, W=6.0, mA=54.0, V=121.1 [OK]
FOUND Device [Valid payload]: 10.0.1.200
ID = 01234567891234567891, Key = 0123456789abcdea, Version = 3.1
Stats: on=True, W=-99, mA=-99, V=-99 [Power data unavailable]
Scan Complete! Found 2 devices.
# Scan the network and unpack the response
devices = tuyapower.deviceScan()
for ip in devices:
id = devices[ip]['gwId']
key = devices[ip]['productKey']
vers = devices[ip]['version']
(on, w, mA, V, err) = deviceInfo(id, ip, key, vers)
print("Device at %s: ID %s, state=%s, W=%s, mA=%s, V=%s [%s]"%(ip,id,on,w,mA,V,err))
The function tuyapower.scan()
will listen to your local network (UDP 6666 and 6667) and identify Tuya devices broadcasting their IP, Device ID, productKey and Version and will print that and their stats to stdout. This can help you get a list of compatible devices on your network. The tuyapower.deviceScan()
function returns all found devices and their stats (via dictionary result).
You can run the scanner from the command line using this:
python -m tuyapower
By default, the scan functions will retry 15 times to find new devices. If you are not seeing all your devices, you can increase max_retries by passing an optional arguments (ex. 50 retries):
# command line
python -m tuyapower 50
# invoke verbose interactive scan
tuyapower.scan(50)
# return payload of devices
devices = tuyapower.deviceScan(false, 50)
FAQs
Pull power and state data from Tuya WiFi smart devices
We found that tuyapower demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.