jasonacox / tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).
MIT License
879 stars 159 forks source link

help Mr. wizard #354

Closed sjpbailey closed 1 year ago

sjpbailey commented 1 year ago

Hello Jason, Just getting back into this, much improved. WOW!

I have one thing that i noticed if i run Wizard independently it will not give local devices any longer just device Cloud info. When it asks for local devices it cannot find: AttributeError: module 'tinytuya' has no attribute 'scanner'

Am i missing a module or is local IP addresses no longer used?

I am trying to poll local devices to read it's json "snapshot" return, then using Pandas to sort out LED from Switches via 'dps' info.

More than likely and Hopefully it is just me doing something dumb. Thank You for your valuable time! Regards, Steve

jasonacox commented 1 year ago

Hi @sjpbailey - can you share some of the output you see?

python3 -m tinytuya wizard

# turn on debug
python3 -m tinytuya wizard -debug

# or just scan
python3 -m tinytuya scan # -debug works here too
sjpbailey commented 1 year ago
TinyTuya Setup Wizard [1.12.7]

    Existing settings:
        API Key=xxxx 
        Secret=xxxx
        DeviceID=xxx
        Region=us

    Use existing credentials (Y/n): 

Device Listing

[
    {
        "name": "Switch Garden Outside",
    ...

    }
]

>> Saving list to devices.json
    11 registered devices saved

>> Saving raw TuyaPlatform response to tuya-raw.json

Poll local devices? (Y/n): 
Traceback (most recent call last):
  File "/Users/stevenbailey/Downloads/tinytuya-master/tinytuya/wizard.py", line 287, in <module>
    wizard()
  File "/Users/stevenbailey/Downloads/tinytuya-master/tinytuya/wizard.py", line 254, in wizard
    result = tinytuya.scanner.poll_and_display(
AttributeError: module 'tinytuya' has no attribute 'scanner'
(Treatlife_3_8_6) stevenbailey@Stevens-iMac tinytuya-master % 
jasonacox commented 1 year ago

File "/Users/stevenbailey/Downloads/tinytuya-master/tinytuya/wizard.py", line 287, in

This is odd. It seems that you didn't get the complete installation (that would include scanner.py). Have you tried installing this way:

pip install --upgrade tinytuya
sjpbailey commented 1 year ago

I did,

Treatlife_3_8_6) stevenbailey@Stevens-iMac tinytuya-master % pip install --upgrade tinytuya
Requirement already satisfied: tinytuya in /Users/stevenbailey/.pyenv/versions/3.8.6/envs/Treatlife_3_8_6/lib/python3.8/site-packages (1.12.7)
Requirement already satisfied: pycryptodome in /Users/stevenbailey/.pyenv/versions/3.8.6/envs/Treatlife_3_8_6/lib/python3.8/site-packages (from tinytuya) (3.11.0)
Requirement already satisfied: requests in /Users/stevenbailey/.pyenv/versions/3.8.6/envs/Treatlife_3_8_6/lib/python3.8/site-packages (from tinytuya) (2.26.0)
Requirement already satisfied: colorama in /Users/stevenbailey/.pyenv/versions/3.8.6/envs/Treatlife_3_8_6/lib/python3.8/site-packages (from tinytuya) (0.4.6)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/stevenbailey/.pyenv/versions/3.8.6/envs/Treatlife_3_8_6/lib/python3.8/site-packages (from requests->tinytuya) (1.26.13)
Requirement already satisfied: certifi>=2017.4.17 in /Users/stevenbailey/.pyenv/versions/3.8.6/envs/Treatlife_3_8_6/lib/python3.8/site-packages (from requests->tinytuya) (2021.10.8)
Requirement already satisfied: charset-normalizer~=2.0.0 in /Users/stevenbailey/.pyenv/versions/3.8.6/envs/Treatlife_3_8_6/lib/python3.8/site-packages (from requests->tinytuya) (2.0.7)
Requirement already satisfied: idna<4,>=2.5 in /Users/stevenbailey/.pyenv/versions/3.8.6/envs/Treatlife_3_8_6/lib/python3.8/site-packages (from requests->tinytuya) (3.3)
(Treatlife_3_8_6) stevenbailey@Stevens-iMac tinytuya-master % 
sjpbailey commented 1 year ago

Maybe missing a module?

environment pip:

autopep8              1.5.7
certifi               2021.10.8
charset-normalizer    2.0.7
colorama              0.4.6
idna                  3.3
ipaddress             1.0.23
markdown2             2.4.1
netifaces             0.11.0
numpy                 1.21.2
paho-mqtt             1.5.1
pandas                1.3.3
pip                   23.1.2
pycodestyle           2.8.0
pycryptodome          3.11.0
pyisy                 2.1.1
python-dateutil       2.8.2
python-dotenv         0.19.1
pytz                  2021.3
requests              2.26.0
setuptools            49.2.1
six                   1.16.0
style                 1.1.0
tinytuya              1.12.7
toml                  0.10.2
tuya-connector-python 0.1.2
udi-interface         3.0.18
update                0.0.1
urllib3               1.26.13
websocket-client      1.2.3
sjpbailey commented 1 year ago

i just installed scanner independently and still a problem. I will restart my system and check it. However my pip reflects what i am using currently in VSC. I have more than one window open maybe this is a problem on my end if yours is runnable.

sjpbailey commented 1 year ago

current pip: autopep8 1.5.7 certifi 2021.10.8 charset-normalizer 2.0.7 colorama 0.4.6 idna 3.3 ipaddress 1.0.23 markdown2 2.4.1 netifaces 0.11.0 numpy 1.21.2 paho-mqtt 1.5.1 pandas 1.3.3 pip 23.1.2 pycodestyle 2.8.0 pycryptodome 3.11.0 pyisy 2.1.1 python-dateutil 2.8.2 python-dotenv 0.19.1 pytz 2021.3 requests 2.26.0 scanner 0.1.0 setuptools 49.2.1 six 1.16.0 style 1.1.0 tinytuya 1.12.7 toml 0.10.2 tuya-connector-python 0.1.2 udi-interface 3.0.18 update 0.0.1 urllib3 1.26.13 websocket-client 1.2.3

jasonacox commented 1 year ago

You may have a local version that it is picking up instead of the installed package. Try this:

cd /tmp
python3 -m tinytuya scan
sjpbailey commented 1 year ago

That works in color lol,

`Switch Office Outside Lights Product ID = key5nck4tavy43jp [Valid Broadcast]: Address = 192.168.1.145 Device ID = 017743508caab5f0973e (len:20) Local Key = e779c96c964f71b2 Version = 3.3 Type = default, MAC = 8c:aa:b5:f0:97:3e Status: {'1': False, '9': 0} LED Office Product ID = keypcvqhw97kqy4h [Valid Broadcast]: Address = 192.168.1.147 Device ID = ebfc16d57ed374932cjqfk (len:22) Local Key = 805217605357161b Version = 3.3 Type = default, MAC = 84:e3:42:1a:96:35 Status: {'20': True, '21': 'white', '22': 1000, '23': 1000, '24': '009000c102c5', '25': '020d0d00000000000000001903e8', '26': 0} Switch Side Garage Outside Product ID = keya4gvchmtapm8n [Valid Broadcast]: Address = 192.168.1.111 Device ID = eb577fdd6642efcbc3g0qc (len:22) Local Key = 85861de497baa60d Version = 3.3 Type = default, MAC = 38:1f:8d:18:57:b3 Status: {'1': False, '9': 0, '38': 'off', '40': 'relay', '41': False, '42': '', '43': '', '44': ''} Switch Front Door Product ID = keyu5sjrcfhjsvd8 [Valid Broadcast]: Address = 192.168.1.110 Device ID = eb7053a032f633f952bqq2 (len:22) Local Key = a792deae091dff2c Version = 3.3 Type = default, MAC = d8:1f:12:32:8c:79 Status: {'1': False, '7': 0, '15': 'none', '18': ''} Switch Garden Outside Product ID = key5nck4tavy43jp [Valid Broadcast]: Address = 192.168.1.146 Device ID = 017743508caab5f385a7 (len:20) Local Key = 2bc2d5aef80f3aee Version = 3.3 Type = default, MAC = 8c:aa:b5:f3:85:a7 Status: {'1': False, '9': 0} LED Strip Cabinets Product ID = keys8pj5xkq8cmrm [Valid Broadcast]: Address = 192.168.1.155 Device ID = ebe097c0407da32084kvtr (len:22) Local Key = 22ad5946c44356a4 Version = 3.3 Type = default, MAC = d4:a6:51:a0:9f:98 Status: {'20': False, '21': 'scene', '24': '000003e803e8', '25': '000e0d00002e03e802cc00000000', '26': 0} Switch Dutch Door Product ID = keyu5sjrcfhjsvd8 [Valid Broadcast]: Address = 192.168.1.105 Device ID = eb9f1eaef823420e19bewt (len:22) Local Key = 659ef2b2c7d3a60a Version = 3.3 Type = default, MAC = d8:1f:12:32:bf:7f Status: {'1': False, '7': 0, '15': 'none', '18': ''} Switch Master Outside Product ID = key5nck4tavy43jp [Valid Broadcast]: Address = 192.168.1.100 Device ID = 017743508caab5f126b0 (len:20) Local Key = 17a1e4c963773637 Version = 3.3 Type = default, MAC = 8c:aa:b5:f1:26:b0 Status: {'1': False, '9': 0} Switch Garage Overhead Product ID = keya4gvchmtapm8n [Valid Broadcast]: Address = 192.168.1.102 Device ID = eb7ac0fbe689ca95f7dxxk (len:22) Local Key = 449ebc60812eb8bb Version = 3.3 Type = default, MAC = 38:1f:8d:18:5e:a2 Status: {'1': True, '9': 0, '38': 'off', '40': 'relay', '41': False, '42': '', '43': '', '44': ''} Switch Dining Pool Outside Product ID = key5nck4tavy43jp [Valid Broadcast]: Address = 192.168.1.101 Device ID = 017743508caab5f29984 (len:20) Local Key = be9d5b1387e6f231 Version = 3.3 Type = default, MAC = 8c:aa:b5:f2:99:84 Status: {'1': False, '9': 0} LED Garage Product ID = keypcvqhw97kqy4h [Valid Broadcast]: Address = 192.168.1.148 Device ID = ebfd4f4263bb769d99zjkq (len:22) Local Key = ec0b2b581a246eab Version = 3.3 Type = default, MAC = 84:e3:42:1a:94:31 Status: {'20': True, '21': 'white', '22': 1000, '23': 1000, '24': '00f301470292', '25': '000d0d0000000000000000180000', '26': 0} Scan completed in 18.0631 seconds

Scan Complete! Found 11 devices. Broadcasted: 11 Versions: 3.3: 11

Saving device snapshot data to snapshot.json `

jasonacox commented 1 year ago

That's great! I suspect you have an old tinytuya folder in your home directory (or wherever you were running it) that is missing the new scanner and supporting core files. Python will attempt to load from the local folder before looking at your installed libraries.

sjpbailey commented 1 year ago

DOH!! Thank you i do! That is cool i will destroy all others and start over, 'dps' is now status!

I just need to be able to scan like this within a function next. Currently in my home automation program i need to add in my snapshot file manually in it's parameters. THANK YOU for the help!