Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error running on Mac #18

Open
sjmotew opened this issue Apr 11, 2021 · 8 comments
Open

Error running on Mac #18

sjmotew opened this issue Apr 11, 2021 · 8 comments

Comments

@sjmotew
Copy link

sjmotew commented Apr 11, 2021

Great app, thank you. Running on MAC trying to find the LOCALKEY for a Recteq grill. Tuyapower identifies the device with device ID, IP etc.. Followed all API Tuya developer instructions and when running tinytuya receive:

`{
"apiKey": "<>",
"apiSecret": "<>",
"apiRegion": "us",
"apiDeviceID": "06200290b4e62d195c2f"
}

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tinytuya/main.py", line 49, in
wizard.wizard(color)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tinytuya/wizard.py", line 206, in wizard
uid = response_dict['result']['uid']
KeyError: 'result'`

@jasonacox
Copy link
Owner

Hi @sjmotew - This error is indicative of a problem with your apiKey & apiSecret values or settings in your Tuya Developer account.

Check section 3 of the following and double check IMPORTANT part - (see screenshot here)

https://github.com/jasonacox/tinytuya#setup-wizard

  1. Set up a Tuya Account
    • Create a Tuya Developer account on iot.tuya.com and log in.
    • Click on "Cloud" icon -> Create a project (remember the Authorization Key: API ID and Secret for below)
    • Click on "Cloud" icon -> select your project -> Project Overview -> Linked Device -> Link devices by App Account (tab)
    • Click 'Add App Account' and it will display a QR code. Scan the QR code with the Smart Life app on your Phone (see step 1 above) by going to the "Me" tab in the Smart Life app and clicking on the QR code button [..] in the upper right hand corner of the app. When you scan the QR code, it will link all of the devices registered in your "Smart Life" app into your Tuya IoT project.
    • IMPORTANT Under "API Management" -> "API Products" and ensure the API groups have status "Subscribed": Smart Home Devices Management, Authorization and Smart Home Family Management (see screenshot here) - Make sure you authorize your Project to use these 3 API groups:
      • Click each of the API boxes
      • Click "Projects" tab
      • Click "New Authorization" button
      • Select your Project from the dropdown and click OK (see screenshot here)

@sjmotew
Copy link
Author

sjmotew commented Apr 12, 2021

Jason,

All is set up correctly, and I just left the API and secret blank above to conceal. Is this occurring perhaps because I am trying to attach a non-standard Tuya device (Recteq Smoker) that does not appear on the Smart Life App? The Recteq app is based on Tuya but it is not a Tuya identifiable device. It is found by tuyapower but cannot read the key which is what I need.

Any thoughts would be helpful, thanks for your work.

@jasonacox
Copy link
Owner

Yes - The Device ID must be in Smart Life app or listed in iot.tuya.com portal as paired or the wizard won't work. Tuya requires a valid paring with the app to provide the local key. The local key is created when you pair (a new one every time you pair). Do you have other Tuya devices you can use? It just needs one valid one to give you all of them.

Is the Smoker dev battery powered? If so, important Note: Battery-powered Tuya sensors are usually designed to stay in sleep mode until a state change (eg. temp chg, open or close alert). This means you will not be able to poll these devices except in the brief moment they awake, connect to the WiFi and send their state update payload the the Tuya Cloud. Keep in mind that if you manage to poll the device enough to keep it awake, you may drain the battery.

@sjmotew
Copy link
Author

sjmotew commented Apr 12, 2021

Yes I have other Tuya devices, I will link them (which I haven't done yet) and then try again. The smoker is not battery. Thanks.

@sjmotew
Copy link
Author

sjmotew commented Apr 12, 2021

It is finding the 2 devices on Tuyapower, one is the app-registered "String Lights", the other is at IP: 10.0.20.26, which is the Recteq smoker. tintuya recognizes the presence 2 devices but will not show the snapshot details including key, only returns the registered device.

Here is the output:

from tuyapower

`
TuyaPower (Tuya compatible smart plug scanner) [0.0.25] tinytuya [1.2.3]

Scanning on UDP ports 6666 and 6667 for devices (15 retries)...

FOUND Device [Valid payload]: 10.0.20.246
ID = eb726cece74119f0bf6atu, product = keyxkjmf8q7ht44p, Version = 3.3
Device Key required to poll for stats
FOUND Device [Valid payload]: 10.0.20.26
ID = 06200290b4e62d195c2f, product = 1CwNbNLE8r70WR7t, Version = 3.1
Stats: on=True [Power data unavailable]

Scan Complete! Found 2 devices.

`

from tinytuya wizard
`
Existing settings:
API Key=pp45rdrwaht9z3l2n21p
Secret=94fb6c5e9e534decaed5e07039397973
DeviceID=eb726cece74119f0bf6atu
Region=us

Use existing credentials (Y/n): Y

Device Listing

[
{
"name": "String Lights",
"id": "eb726cece74119f0bf6atu",
"key": "abccba4985d62425"
}
]

Saving list to devices.json
1 registered devices saved

Poll local devices? (Y/n): Y

Scanning local network for Tuya devices...
2 local devices discovered

Polling local devices...
[String Lights] - 10.0.20.246 - No Response

Saving device snapshot data to snapshot.json

Done.
`
From snapshot.json:

{ "timestamp": 1618263773.9440472, "devices": [ { "name": "String Lights", "ip": "10.0.20.246", "ver": "3.3", "id": "eb726cece74119f0bf6atu", "key": "abccba4985d62425" } ] }

@jasonacox
Copy link
Owner

The Tuya cloud will only return keys for devices that have been paired. That may be why are you still not getting the key. Can you pair the Smoker with the SmartLife app?

Try to scan now that you have the key for "String Lights". Ensure you do not have the app (e.g. SmartLife) open many of the Tuya devices only allow one connection at a time and refuse others. Some things to try:

python -m tinytuya scan    # this will scan network and reference the devices.json file to apply key

Are you able to ping 10.0.20.26 and get a response from that device? You can try this debug code snip to see more details on the tuyaprotocol (try on both devices if you can):

import tinytuya

print("TinyTuya (Tuya Interface) [%s]\n"%tinytuya.__version__)
tinytuya.set_debug(True)

d = tinytuya.OutletDevice(DEVICEID, DEVICEIP, DEVICEKEY)
print(d)
d.set_version(3.1)

print(" > Fetch Status < ")
data = d.status()
print(data)

@sjmotew
Copy link
Author

sjmotew commented Apr 13, 2021

I was able to directly pair with the SmartLife app using a generic wifi device. Solved all the issues, I can now run from SmartLife or as intended have extracted the key for use with Home Assistant. Great problem solving, I will share and link back on the Home Assistant site.

@jasonacox
Copy link
Owner

Excellent! Thanks for the update @sjmotew !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants