jasonacox / tinytuya

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

Device Cloud Pairing has changed? #75

Open Bonze255 opened 2 years ago

Bonze255 commented 2 years ago

I would add my Tuya device to the Cloud. But this

_Set up a Tuya Account:

Create a Tuya Developer account on iot.tuya.com and log in.
Click on "Cloud" icon -> Create Cloud Project (Skip the configuration wizard) (remember the Authorization Key: API ID and Secret for below)
Click on "Cloud" icon -> Select your project -> Devices -> Add Device
Click Add Device with IoT Device Management App 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 "Service API" ensure the API groups are listed: 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 "Service API" tab
    Click "Go to Authorize" button
    Select the API Groups from the dropdown and click Subscribe (see screenshot here)_

wont work, the device is a Medion Lola Device like https://www.paul-neuhaus.de/led-deckenleuchte-in-rund-und-schwarz-mit-smart-home-funktion-und-farbwechselmodus/ via the Medion Life+ App and the Search Script are working. But it seems that Tuya has changed their Website.

jasonacox commented 2 years ago

Hi @Bonze255 ,

Thanks for raise the issue. To control your devices locally, you will need to add them to the Tuya cloud. Currently I believe that is only supported with SmartLife app (download Android or iOS version). Let me know if you are able to make this new app from Medion work.

Tuya does update their process from time to time so it makes a challenge to stay current on the steps needed to set up an IOT account. Help me understand what you see different so I can update instructions.

  1. Go to iot.tuya.com and create a new account.
  2. On the Tuya portal after logged in, Click on "Cloud" icon on left then "Create Cloud Project" button. This pop-up form should appear (make sure you remember the datacenter you pick - it will be required by TinyTuya Wizard): image
  3. Skip the "Configuration Wizard" by pushing the "Skip" button. It will end up on a page that has your Authentication Keys like this image
  4. Click the "Devices" tab at top like this image
  5. Find the "Add Device" button to the right, click it. image
  6. In the SmartLife app you will scan that code to link your local devices to this project so you can get the Local Keys.
  7. Follow the rest of the instructions you pasted... let me know if you see discrepancies.

Please note, every time you pair a device to SmartLife it generates a new Local Key which means your Medion Life+ app will most likely NOT work any longer unless you re-pair it with that app, which will break the SmartLife keys. All that to say, unless Medion has a way for you to scan the QR code on iot.tuya.com, you will need to use SmartLife app if you want local control of your Tuya devices with tools like TinyTuya.

Bonze255 commented 2 years ago

step 1-5 are ok,

but when i want to add the Cloud to the Tuya Smart App. It would strange. I can scan the DMC code butthen apperas a popup, which refers to the Iot Device Manager App from Tuya?!

EDIT: I have created a new Projekt and choose two Times Smart Home,, then i could link the tuya App Acoount to the Cloud Project. Then i must buy the "Device connection Service" APi, and allow the Cloud project to use it.. i think it should work , but i must test it.

jasonacox commented 2 years ago

I'm not entirely sure I follow you. But it looks like progress? Anything I should change on the setup instructions?

Please, if you can, share any screen shots you think may be helpful for others.

Thank you!

Bonze255 commented 2 years ago

importent is that the Datacenter must the same as your App location is. For Germany is Middle Europe

Screenshot 2021-10-25 at 10-23-45 Tuya IoT Platform

Screenshot 2021-10-25 at 10-23-57 Tuya IoT Platform Select "Device connection Service", this APi must be Bought for 0€ , then the API must selected for each projekt to use.

i got this from the device scan

{ "devices": [ { "name": "NLG-RGB-TW Light", "ip": "192.168.1234", "ver": "3.3", "id": "12343", "key": "12345", "dps": { "devId": "2124214", "dps": { "1": true, "2": "white", "3": 255, "4": 85, "5": "0000FF00f2ffFF", "6": "bd76000168ffff", "7": "ffff500100ff00", "8": "ffff8003ff000000ff000000ff000000000000000000", "9": "ffff5001ff0000", "10": "ffff0505ff000000ff00ffff00ff00ff0000ff000000" } } } ] } its RGB stripe lamp

i think the cloud connection works now, but tinytuya not i got always this error "{'Error': 'Timeout Waiting for Device', 'Err': '902', 'Payload': 'Check device key or version'}"

jasonacox commented 2 years ago

Are you able to run python -m tinytuya wizard and use the API ID and Secret from the Tuya iot portal to have TinyTuya grab the local key?

You should find the ID and Secret here: image

ClusterM commented 2 years ago

image

jasonacox commented 2 years ago

Interesting. Thank you. Not clear to me what that means or what adjustments we should make.

ClusterM commented 2 years ago

You need only "IoT Core" API access.

jasonacox commented 2 years ago

Thanks. So, we should update the instructions/README to change...

to

paraita commented 2 years ago

step 1-5 are ok,

but when i want to add the Cloud to the Tuya Smart App. It would strange. I can scan the DMC code butthen apperas a popup, which refers to the Iot Device Manager App from Tuya?!

EDIT: I have created a new Projekt and choose two Times Smart Home,, then i could link the tuya App Acoount to the Cloud Project. Then i must buy the "Device connection Service" APi, and allow the Cloud project to use it.. i think it should work , but i must test it.

Same, the Tuya Smart App and Iot Device Manager App didn't work for me, I could register successfully my light bulbs but the scan part wouldn't work (I don't remember the exact error but it was something about my devices not in the same region or DC as my Tuya Cloud Project). The Smart Life App did work though, with the exact info I've put in the two previous apps.

ClusterM commented 2 years ago

step 1-5 are ok, but when i want to add the Cloud to the Tuya Smart App. It would strange. I can scan the DMC code butthen apperas a popup, which refers to the Iot Device Manager App from Tuya?! EDIT: I have created a new Projekt and choose two Times Smart Home,, then i could link the tuya App Acoount to the Cloud Project. Then i must buy the "Device connection Service" APi, and allow the Cloud project to use it.. i think it should work , but i must test it.

Same, the Tuya Smart App and Iot Device Manager App didn't work for me, I could register successfully my light bulbs but the scan part wouldn't work (I don't remember the exact error but it was something about my devices not in the same region or DC as my Tuya Cloud Project). The Smart Life App did work though, with the exact info I've put in the two previous apps.

Try to change the region of the data center:

image

Also, you can edit the list of available data centers:

image

paraita commented 2 years ago

thanks for your answer @ClusterM :) that did the trick ! I encountered another problem after that: the wizard command would return the following error: "Cross-region is not allowed". I had to use a VPN to bypass that.

ClusterM commented 2 years ago

Hm, weird. Need to do some tests about it. Where are you from? And which region was selected the first time and the last time?

paraita commented 2 years ago

I'm from Tahiti (French Polynesia). I've selected French Polynesia when I signed up on Tuya Smart and Smart Life apps. I don't recall having selected any region from those apps..

Here's the trace when I ran the wizard the first time (no VPN):

(env) ➜  test-nedis-light-bulb python -m tinytuya wizard
TinyTuya Setup Wizard [1.2.9]

    Existing settings:
        API Key=REDACTED
        Secret=REDACTED
        DeviceID=REDACTED
        Region=eu

    Use existing credentials (Y/n):

    Enter API Key from tuya.com: REDACTED
    Enter API Secret from tuya.com: REDACTED
    Enter any Device ID currently registered in Tuya App (used to pull full list): REDACTED
    Enter Your Region (Options: us, eu, cn or in): eu

Error from Tuya server: your ip(REDACTED) cross-region access is not allowed

Then, I've connected to France with ExpressVPN and ran the same command and it worked.

ClusterM commented 2 years ago

@paraita Which region did you select on iot.tuya.com during project creation and when you used VPN?

paraita commented 2 years ago

When I created my Cloud project on iot.tuya.com, I only selected "Western Europe Data Center". When I created my Cloud project on iot.tuya.com, I only selected "Central Europe Data Center". I then proceeded with the scanning of the QR code in the Device tab of my project with (first) the Tuya Smart app, then the IoT Device Manager app, both didn't worked for me. There was an error message after the scanning of the QR code: "You cannot add devices in your project that you declared in a different region" (or something like this, sorry I don't have the exact message anymore).

One thing I noticed,I believe this is what solved the problem for me: The current readme tells me to display the QR code from the "devices" tab. But in your screenshot, you are using the last tab "Link Tuya App Account", which did the trick when I scanned its QR code with Smart Life app (nope, it didn't work with the Tuya Smart app, which I tried first).

Lastly, when I got stuck again during the wizard step, that's when I added all the data centers to my cloud project. I've ran the same python -m tinytuya wizard command again but it still didn't work, so I connected to France with my VPN and re-ran the command again, and finally it worked :)

jasonacox commented 2 years ago

Great discovery! Thanks @ClusterM and @paraita

TinyTuya version 1.2.10 will have the option to select the Western Europe region. I think this would have worked for your case. I'm updating the README and will get this new version pushed to PyPI:

TinyTuya Setup Wizard [1.2.10]

    Existing settings:
        API Key= REDACTED 
        Secret= REDACTED
        DeviceID= REDACTED
        Region=us

    Use existing credentials (Y/n): n

    Enter API Key from tuya.com: REDACTED
    Enter API Secret from tuya.com: REDACTED
    Enter any Device ID currently registered in Tuya App (used to pull full list): REDACTED

      Region List
        cn  China Data Center
        us  US - Western America Data Center
        us-e    US - Eastern America Data Center
        eu  Central Europe Data Center
        eu-w    Western Europe Data Center
        in  India Data Center

    Enter Your Region (Options: cn, us, us-e, eu, eu-w, or in): eu-w
paraita commented 2 years ago

After reading your comment @jasonacox I realized it shouldn't have been possible for me to link to eu-w in the first place ! I double checked on my Cloud project and indeed I wasn't using the Western Europe Data Center but the Central Europe Data Center: image

@ClusterM I'm sorry for my mistake. I'll fix my previous comment with the correct DC.

42Willow commented 2 years ago

step 1-5 are ok, but when i want to add the Cloud to the Tuya Smart App. It would strange. I can scan the DMC code butthen apperas a popup, which refers to the Iot Device Manager App from Tuya?! EDIT: I have created a new Projekt and choose two Times Smart Home,, then i could link the tuya App Acoount to the Cloud Project. Then i must buy the "Device connection Service" APi, and allow the Cloud project to use it.. i think it should work , but i must test it.

Same, the Tuya Smart App and Iot Device Manager App didn't work for me, I could register successfully my light bulbs but the scan part wouldn't work (I don't remember the exact error but it was something about my devices not in the same region or DC as my Tuya Cloud Project). The Smart Life App did work though, with the exact info I've put in the two previous apps.

Try to change the region of the data center:

image

Also, you can edit the list of available data centers:

image

THANK YOU SO MUCH, switching the datacentres and using trial and error fixed my problem πŸ‘πŸΌ I wish I had just scrolled up earlier 🀣

42Willow commented 2 years ago

image One last question, when I subscribed to the IoT core api I got the trial version and it says it will only last for one month, does that mean in one month I will have to do this whole process again with a different email? It says it expires 2021-12-01

ClusterM commented 2 years ago

image One last question, when I subscribed to the IoT core api I got the trial version and it says it will only last for one month, does that mean in one month I will have to do this whole process again with a different email? It says it expires 2021-12-01

Good question. I want to know it too.

ClusterM commented 2 years ago

One last question, when I subscribed to the IoT core api I got the trial version and it says it will only last for one month, does that mean in one month I will have to do this whole process again with a different email? It says it expires 2021-12-01

My IoT Core API expired

image

But in fact, it still works 😏

42Willow commented 2 years ago

bruh

jasonacox commented 2 years ago

Mine expired a few years ago, still works. At some point I think I had to select "Basic Account" for my profile. At the top right, the portal has a profile icon:

image

Mine says "Basic Version" with an upgrade button which takes you to: https://iot.tuya.com/exp/intro

image

As I understand it, the subscription is to be able to use Tuya Cloud for your own commercial device and app development. We just need access to get the local keys for private use.