Closed JAbelP closed 2 years ago
Hi @Jpinales97 - python3 is the default for TinyTuya and is tested with each build on these versions: https://github.com/jasonacox/tinytuya/actions/runs/2050567608
What version are you using? Also, please paste what you were running to get that error (that function you mention is not part of TinyTuya). It could be that you have something corrupt in your python install.
I just needed to update pip!
but when I tried running the file (py3 -m dinnerRoomLight.py (the code will be below))
I got this error
Traceback (most recent call last):
File "C:\Python3\lib\runpy.py", line 184, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "C:\Python3\lib\runpy.py", line 110, in _get_module_details
import(pkg_name)
File "C:\Users\Helquin\Documents\Code\JavaScript\React\homewebsite\backend\dinnerRoomLight.py", line 1, in
Traceback (most recent call last):
File "C:\Python3\lib\runpy.py", line 184, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "C:\Python3\lib\runpy.py", line 110, in _get_module_details
import(pkg_name)
File "C:\Users\Helquin\Documents\Code\JavaScript\React\homewebsite\backend\dinnerRoomLight.py", line 1, in
but running pip freeze you can see that both are installed certifi==2021.10.8 charset-normalizer==2.0.12 click==8.0.3 colorama==0.4.4 crypto==1.4.1 distlib==0.3.4 filelock==3.4.2 Flask==2.0.2 flux-led==0.28.22 idna==3.3 itsdangerous==2.0.1 Jinja2==3.0.3 MarkupSafe==2.0.1 Naked==0.1.31 numpy==1.22.3 paho-mqtt==1.6.1 pandas==1.4.1 platformdirs==2.5.0 pyaes==1.6.1 pycryptodome==3.14.1 python-dateutil==2.8.2 pytz==2022.1 PyYAML==6.0 requests==2.27.1 shellescape==3.8.1 six==1.16.0 tinytuya==1.3.1 tuya-iot-py-sdk==0.6.6 urllib3==1.26.9 virtualenv==20.13.1 webcolors==1.11.1 websocket-client==1.3.2 Werkzeug==2.0.3
Something is not right with your python installation. Try this:
# Try to upgrade tinytuya
py3 -m pip install --upgrade tinytuya
# Try to upgrade pycryptodome - used by tinytuya for encryption
py3 -m pip install --upgrade pycryptodome
# Have tinytuya scan your network
py3 -m tinytuya scan -nocolor
# Try your code again
py3 dinnerRoomLight.py
Windows doesn't always play well with pyaes and Crypto so you could try to uninstall those.
I finally got that part running, but when I try to scan > poll devices
Scanning local network for Tuya devices (retry 29 times)... 6 local devices discovered
Polling local devices... [Dining room east] - 0 - Error: No IP found [Dining room north] - 0 - Error: No IP found [Dining room west] - 0 - Error: No IP found [Dining room south] - 0 - Error: No IP found
(two of the ones not listed are my roomate's so it makes sense that two are not on the list)
I also went into my router and found that the IP address being shown in the app does not match the one found in the router (router shows 192.167.1.229 while the tuya-raw.json shows 99.127.43.38)
import tinytuya d = tinytuya.BulbDevice('xxxx','192.168.1.229','xxxx') b =d.status() print(b)
(backend) C:\Users\Helquin\Documents\Code\JavaScript\React\homewebsite\backend>py3 dinnerRoomLight.py {'Error': 'Unexpected Payload from Device', 'Err': '904', 'Payload': ''}
Hi @Jpinales97 - One thing to note, the scan actually just listens for the Tuya UDP broadcast packets from the devices. This is how Tuya does local device discovery (and is used in the Smart Life app). Some things can preven this:
The scan is useful in helping discover the IP addresses of the devices and matching those with their Device IDs. You can do that manually if your route provides IP address for the devices, but it does require that you know the right Device ID and LocalKey to use for each one.
{'Error': 'Unexpected Payload from Device', 'Err': '904', 'Payload': ''}
This can be caused by invalid version, invalid ID and LocalKey. I notice you are not setting a version in your code. This will cause it to default to protocol 3.1 which is highly unlikely for SmartBulbs. I would try this:
import tinytuya
# tinytuya.set_debug(color=False) # Optional debug mode I would try
d = tinytuya.BulbDevice('xxxx','192.168.1.229','xxxx')
d.set_version(3.3)
b =d.status()
print(b)
Nothing should be blocking the ports but I did have the App open; I'll go ahead and try the code with the version specified by the app
also should I be using the 192.168.1.228 IP or should I use the 99.127.43.38 IP Address?
The IP address in tuya-raw.json
is the public IP address that Tuya Cloud sees when your devices connect to it. You will want to use the local private network addresses for local control (e.g. 192.168.1.228). Try to close the app and run this:
python -m tinytuya scan -nocolor
awesome it all worked out, just for reference, how can you tell what version an item is?
That's great news! The scan will print the version of the device along with the Address and Device ID (it will also include the Name and Local Key if you have a devices.json file in the same directory). Here is an example 3.3 device:
Chandelier Product ID = qcgkaqmaivuwfwz4 [Valid payload]:
Address = 10.0.1.6, Device ID = xxxxxx, Local Key = yyyyyy, Version = 3.3
Status: {u'1': True, u'3': 166, u'101': False}
in _find_latest_available_vc_ver return self.find_available_vc_vers()[-1] IndexError: list index out of range