Repository navigation
A new way of getting deviceId and localKey #323
Description
Activity
I tried this. I am getting: There was an error in evaluating the Pre-request Script: TypeError: Cannot read property 'sigBytes' of undefined. when trying to make the get request. I also can't tell what I am suppose to use as schema value when making the request.
This could be really useful @SleepWalker, thank you for researching it.
tuya-cli linkstill has issues occasionally for some users, so this could be a great alternative.I'll take a look at some point this weekend.
Hello.
i would try your method, but im noob . It's ok for my virtual id, i have found.
But can you tell me how i have to find local key.
I don't know how i can use tuya openapi.
Can you tell me step by step what i have to write to found please.
thank you
@etttoutoi This quick start guide from tuya has all the info you need for using postman to get the local key. Basically:
- Install postman
- Download and import the environment and collection in postman
- Set up the variables according to your tuya developer profile
client_id, device_id (from the app as described in this post), schema, and url (region based, i.e. https://openapi.tuyaeu.com for EU) - Run the
access_tokentask incollectionsin postman - Run the
{{url}}/v1.0/devices/{{device_id}}request to get yourlocal_key
Reacted by kinstrayHere is a gist, that demonstrates how to get
localKeyand then tries to use it with a demo code fromtuyapiREADME:https://gist.github.com/SleepWalker/18f19679adbfacee6c415d4f6dc218bb#file-readme-md
I've successfully turned on/off my socket using
demo.jsfrom that gist 🎉- changed the title
[-]A new way of getting deviceId and localKey (Probably)[/-][+]A new way of getting deviceId and localKey[/+]on May 23, 2020 @SleepWalker so after looking at this a bit, it seems that while linking your TuyaSmart account to your SaaS instance works fine, there's not a programmatic way to get all device IDs.
/devicesthrows an error, and/devices?schema=TuyaSmartgives a permission error. Did you find a good way to list devices?Ideally, the user would be able to link their account through the web interface and then run one
tuya-clicommand to list devices; without having to manually find and copy device IDs.@codetheweb you can use
{{url}}/v1.0/users/{{uid}}/devicesfor that. But, the only way to getuidI know, is by copyingdeviceIdfrom an app and than getuidfield from device info request.So the user should copy
deviceIdfrom any random device, that he had connected to his account. And then it can be used to list all other devicesI've added demo script in gist, that lists all the available devices:
https://gist.github.com/SleepWalker/18f19679adbfacee6c415d4f6dc218bb#file-listdevices-js
Reacted by Gioele AntocideviceId can be obtained programmatically using the cloudtuya library, by providing it with your account login details (smart_life, tuya smart app) it will list the device ids for all connected devices, which can then be used here.
@tim-jc looks like you've forgot to link your smart life account to your tuya dev account (https://auth.tuya.com/). See the issue description for the screenshots.
Reacted by tim-jcWhat do i put for the schema.
i am struggling to get token auth. i get
{
"code": 1000,
"msg": "data not exist",
"success": false,
"t": 1592041129210
}@SleepWalker - thank you. I had linked, but when I went back in to my Tuya account I saw my device count was now 0. I think I'd inadvertently run the
DELversion of{url}}/v1.0/devices/{{device_id}}initially rather thanGET. Re-added the device in the Tuya app and was able to get the key. Appreciate the help.Reacted by Sviatoslav31 remaining items
you need to link devices first
That's the issue, I get the same screen when trying to link a device.
Yes, I'm getting those ridiculous pricing schemes too. My switch is still working with Octopi. Was it only a 1 month trial of the dev services?
Got another e-mail you can use maybe?
Please just use the trial! You only need it for getting the local key.
If you running home assistant as as example, you can run then the commands with a addon called local tuya without the cloud!Reacted by kinstrayCould someone please assist.
I run the access_token - all works great - success = true
I then paste {{url}}/v1.0/devices/{{device_id}} into the GET box... run it
{ "code": 1010, "msg": "token invalid", "success": false, "t": 1614xxxxxxxxx }What am I doing wrong?
Edit: nevermind. Seems there is a pre-set GET that has that in although i missed it due to all the chinese writing!!
- please read devaxtator post…On Tue, Mar 2, 2021 at 4:03 PM vaderag ***@***.***> wrote: Could someone please assist. I run the access_token - all works great - success = true I then paste {{url}}/v1.0/devices/{{device_id}} into the GET box... run it { "code": 1010, "msg": "token invalid", "success": false, "t": 1614xxxxxxxxx } What am I doing wrong? — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#323 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AOI7KSSREMJMKOPDCGCCFU3TBUD6PANCNFSM4NFCOYFQ> .
I am having trouble getting the API Explorer to work. I have linked device:

I have tried the different regions as well China gets permission denied:

Europe returns blank response

My devices show in the device list under Europe selection

Anyone have ideas here? I need to create an account on the app under a different locations?
I am having trouble getting the API Explorer to work. I have linked device:

I have tried the different regions as well China gets permission denied:

Europe returns blank response

My devices show in the device list under Europe selection

Anyone have ideas here? I need to create an account on the app under a different locations?
again....
go to api managment
api groups
and grant permissions to the api only DEVICE MANAGMENT wait 10 minutes
and then get device details is that easy

Clearly from my screenshot, device management is enabled and open under the API Groups.
I think it is strange I am getting blank response from Europe region api?
Do you get blank response from any region?- confirmed the response is response{} something is wrong…On Thu, Mar 4, 2021 at 1:05 PM matyman1122 ***@***.***> wrote: Clearly from my screenshot, device management is enabled and open under the API Groups. I think it is strange I am getting blank response from Europe region api? Do you get blank response from any region? — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#323 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AOI7KSVYCAF2VVNTQXB3MXDTB6ATNANCNFSM4NFCOYFQ> .
thanks for the confirmation, I will try again tomorrow
If you are getting 'Permission Deny' read my post from the 5th Jan 2021...
If you are getting 'Permission Deny' read my post from the 5th Jan 2021...
Thanks for the reply, this step is already completed as per my last message. You can see in my screenshot all the API groups are available for selection. I suspect I get the deny message because that deviceID is not available on the China API as my devices are under the Europe location. But when I use the Europe one I get {} response. I might need to raise a ticket to them to enquire the status of the API. I was not able to find a status page anywhere.
Just to let everyone know I decided to try and use postman to call the Europe API instead and this is working.
The issue is on the Tuya Cloud not having permissions to the APIFor anyone that is trying to use the API Explorer through Tuya IOT Platform and getting the response {} I have found the issue.
This is because the connection is getting blocked due to CORS restrictions. I found this error in the developer console.

I was able to get the API working again using this extension for Chrome:
https://chrome.google.com/webstore/detail/cross-domain-cors/mjhpgnbimicffchbodmgfnemoghjakai- Repository owner locked and limited conversation to collaborators
on Mar 9, 2021

Hello, I've found out, that an official Smart Life app shows you
deviceId. I've tested thatdeviceIdwith tuya OpenAPI and it works (at least for my smart sockets). This means, that you can getlocalKeyfrom an OpenAPI/v1.0/devices/{{device_id}}.I think, that this may be useful to simplify
tuyapisetup workflow.The new setup will consist of three steps:
@tuyapi/cli, you should "Link device by Tuya Smart App Account":deviceId:localKeyvalue: