codetheweb / tuyapi

🌧 An easy-to-use API for devices that use Tuya's cloud services. Documentation: https://codetheweb.github.io/tuyapi.
MIT License
2.04k stars 332 forks source link

Controlling Tuya devices with cloud API instead of controlling them locally #20

Open michmike opened 6 years ago

michmike commented 6 years ago

hi there,

First thank you for your valuable contributions to the tuya library. I realize this is a long shot, but i am wondering if anyone had success in calling the tuya cloud API? i used fiddler and i was able to decipher a lot of the information on the calls, but there is one thing missing.

How is tuya calculating the MD5 hash? I was not able to replicate their "sign" parameter to the URL and the details on this as slim. Most of the info is located at https://docs.tuya.com/en/cloudapi/cloud_access.html#access-mode (search for accesskey) but i could not get it to work following the example. (I had to order my parameters, i used localKey as the accessKey, and then i did a utf-8 encoded MD5 hash). For the time, i got it in seconds using Unix epoch time.

Once i complete my work, i will share the PowerShell script that can be replicated into standard http/json requests.

brannon-bowden commented 5 years ago

@codetheweb I am using the nodejs cloud library for testing, with some additional logging added. (I'm actually implementing the mobile api for a proprietary embedded system, so it's been extremely helpful to be able to see where I am screwing up). I "borrowed" the keys from smart life app while implementing my code (I have my own, but easier to use something I know is already working). I was just about to test turning on/off, and got the following error. Launched the Android app and noticed app itself quit working and was forcing me to update giving the same error as below. Once I updated the app, I tried logging in using email and password, and it required me to get a sms with verification code (I think this is just an app requirement, not API)..... Going to try my own mobile api keys next with the existing code. (Though it is interesting the API must have some mechanism for minimum app version, although I didn't see mentioned, and not sure what it is using as the basis).

{ t: 1534207449836, success: false, errorCode: 'APP_NEED_UPGRADE', status: 'error', errorMsg: 'Please upgrade your app to the latest version' }

Update: It appears my mobile keys work just fine, so the upgrade requirement must be on an app by app basis. I will use mine from now on.

codetheweb commented 5 years ago

@Sytanek đź‘Ť glad you got it figured out.

brannon-bowden commented 5 years ago

Have spent a bit of time looking through the new apps source code. Haven't been able to identify what part of the api call is allowing them to know what version of the app is running. They are sending quite a bit more as part of the login postdata. I did find mention of a new 2.0 api call for registering that was introduced, and an unpublished api call for upgrading user data. (Not sure why / when this is called yet)

BillSobel commented 5 years ago

You mentioned you 'borrowed' keys from the Smartlife app, I suspect you do not have the correct key material. The actual key in the Smartlife app is encoded into an image file and is extracted through native code and obfuscated as much as possible and doesn't wind up living in the JVM. The JVM keys aren't decoys and have the side effect of locking you into an unknown silo (I also have one account with the upgrade message, it is not clearable as far as I know, I had to change email addresses and use a correct key set). Try your tests again with a provisioned key set, and a different email address, and you should be fine. Bill

On Tue, Aug 14, 2018 at 2:47 AM, Sytanek notifications@github.com wrote:

@codetheweb https://github.com/codetheweb I am using your cloud library for testing, with some additional logging added. (I'm actually implementing the mobile api for a proprietary embedded system, so it's been extremely helpful to be able to see where I am screwing up). I borrowed the keys from smart life app while implementing my code. I was just about to test turning on/off, and got the following error. Launched the Android app and noticed app itself quit working and was forcing me to update giving the same error as below. Once I updated the app, I tried logging in using email and password, and it required me to get a sms with verification code. I'm not sure if I set off some security protection, or what....

{ t: 1534207449836, success: false, errorCode: 'APP_NEED_UPGRADE', status: 'error', errorMsg: 'Please upgrade your app to the latest version' }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/codetheweb/tuyapi/issues/20#issuecomment-412816651, or mute the thread https://github.com/notifications/unsubscribe-auth/ADLj6FbKTNZQ6hDcvO2k6oabbTNrpmMNks5uQpyagaJpZM4Rsiok .

brannon-bowden commented 5 years ago

Bill - I was using them fine for 2 days before it quit working (Exactly the same time my Android app quit working), and did all sorts of fun stuff to my account, the only thing I couldn't test was sending on/off. (my device was at the office unplugged). Bit jumbled, but here is the response for listing the devices on my account.

Code - 200String - {"result":{"devices":[{"schema":"[{\"attr\":5,\"code\":\"switch_on\",\"desc\":\"\",\"iconname\":\"icon-dp_power\",\"id\":1,\"mode\":\"rw\",\"name\":\"??????\"Notice: [App 1] # 2018-08-13 07:30:00 # Day of Week = Mondayown\",\"desc\":\"\",\"id\":2,\"mode\":\"rw\",\"name\":\"?????????\",\"passive\":true,\"property\":{\"unit\":\"???\",\"min\":0,\"max\":86400,\"scale\":0,\"step\":1,\"type\":\"value\"},\"type\":\"obj\"}]","appRnVersion":"1.0","panelConfig":{},"icon":"smart/icon/socket_new2.pNotice: [App 1] # 2018-08-13 07:45:00 # Checking Schedules"000000004w_","ability":0,"attribute":976,"iconUrl":"https://images.tuyaus.com/smart/icon/socket_new2.png","runtimeEnv":"prod","displayMsgs":{},"devId":"0320019068c63ac5d581","phase":1,"schemaExt":"[]","rnFind":false,"productId":"ahg3J1WYWKKAWA1L","dps":{"1":true,"2":0},"actNotice: [App 1] # 2018-08-13 07:45:00 # Day of Week = Monday":true,"i18nTime":1530791181409,"uiPhase":"release","localKey":"61c35fb403582d55"}],"groups":[]},"t":1534156825550,"success":true,"status":"ok"}

BillSobel commented 5 years ago

I am a bit confused, are you sending commands via MQTT or directly? If directly then once you have the key then no other interaction with the cloud is required. I thought your issue was crowd related, and that seems to be coming from you using the wrong keys. The keys you extracted from the app are not the real keys, unless you decrypted the DRM and pulled the real keys from the image file. If not, you are using old keys and at some point those accounts get marked as 'update' and are forced to use the newest version of the app which no longer contains the keys you tried.

On Tue, Aug 14, 2018 at 3:22 PM, Sytanek notifications@github.com wrote:

Bill - I was using them fine for 2 days before it quit working, and did all sorts of fun stuff to my account, the only thing I couldn't test was sending on/off. (my device was at the office unplugged).

Code - 200String - {"result":{"devices":[{"schema":"[{\"attr\":5,\"code\" :\"switch_on\",\"desc\":\"\",\"iconname\":\"icon-dp_power\", \"id\":1,\"mode\":\"rw\",\"name\":\"??????\"Notice: [App 1] # 2018-08-13 07:30:00 # Day of Week = Mondayown\",\"desc\":\"\",\" id\":2,\"mode\":\"rw\",\"name\":\"?????????\",\"passive\": true,\"property\":{\"unit\":\"???\",\"min\":0,\"max\":86400, \"scale\":0,\"step\":1,\"type\":\"value\"},\"type\":\"obj\"} ]","appRnVersion":"1.0","panelConfig":{},"icon":"smart/icon/socketnew2.pNotice: splusmanagerapp.exe [App 1] # 2018-08-13 07:45:00 # Checking Schedules"000000004w","ability":0,"attribute":976,"iconUrl":" https://images.tuyaus.com/smart/icon/socket_new2.png","runtimeEnv":"prod", "displayMsgs":{},"devId":"0320019068c63ac5d581","phase": 1,"schemaExt":"[]","rnFind":false,"productId":" ahg3J1WYWKKAWA1L","dps":{"1":true,"2":0},"actNotice: [App 1] # 2018-08-13 07:45:00 # Day of Week = Monday":true,"i18nTime":1530791181409,"uiPhase":" release","localKey":"61c35fbd03582d55"}],"groups":[ ]},"t":1534156825550,"success":true,"status":"ok"}

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/codetheweb/tuyapi/issues/20#issuecomment-413035170, or mute the thread https://github.com/notifications/unsubscribe-auth/ADLj6FKDjZJUKLbC0X629SkNPuvElbcxks5uQ02ugaJpZM4Rsiok .

brannon-bowden commented 5 years ago

Bill, I was just going through the cloud(technically mobile) api. I decompiled the app, started with the UI Login Form and worked my way backwards through all the method calls and returns. You are right, that It is possible they are older keys, or keys they shouldn't have left active, but they worked with the tuyacloud library, as well as my own code for over a week and two app versions. I did check and the set of keys I used are still in the new app, but the new app is sending quite a bit more data on login. Verified the keys are still accurate through CharlesProxy.

brannon-bowden commented 5 years ago

@codetheweb found documentation in the tuya sample sdk that says session id is 45 days with no activity. (Or until it errors/expires for any other random reason)

uttamraj143 commented 5 years ago

Using postman I have been trying to get the list of devices but I am getting error as "SING_VALIDATE_FALED_4" I am not sure when I am doing wrong can anyone please suggest us how to get list of devices in that account and I am creating sign code with "a=tuya.cloud.user.device.list|time=1534846626|lang=en|v=1.0|os=Linux|clientid=yj83p8srh48ar8aestxq|postData={“countryCode”:“91”} " Using postman I am using below API

https://a1.tuyacn.com/api.json?a=tuya.cloud.user.device.list&time=1534846626&lang=en&v=1.0&os=Linux&clientid=yj83p8srh48ar8aestxq&sign=760B7F3B96A59545B8E9E1274BAF5417&postData={“countryCode”:“91”}

Error:

{ "t": 1534849171288, "success": false, "errorCode": "SING_VALIDATE_FALED_4", "status": "error", "errorMsg": "Parameter or Data Error" }

I tried getting users list but same issue Sign code with

"a=tuya.cloud.user.list|time=1534850428|lang=en|v=1.0|os=Linux|clientid=rqpatuk4nqpafyujpj7s|parameter={"strartTime": "1534850428","endTime": "1534850990.699","offset": 0,"limit": 1}"

Using postman I am using below API

POST: https://a1.tuyacn.com/api.json?a=tuya.cloud.user.list&time=1534850428&lang=en&v=1.0&os=Linux&clientid=rqpatuk4nqpafyujpj7s&sign=E434CDE9D17937A84615440559B549D5&parameter={"strartTime": "1534850428","endTime": "1534850990.699","offset": 0,"limit": 1}

Error: { "t": 1534852817119, "success": false, "errorCode": "SING_VALIDATE_FALED_4", "status": "error", "errorMsg": "Parameter or Data Error" }

craigsirk commented 5 years ago

I have been working this a bit and have gotten it to work with the API services.

@uttamraj143 you are using the ” (slanted quotes) which give the "data error". Instead use the " (straight quotes) in the postData={“countryCode”:“91”}. I had the same issue for a long time.

edmund5 commented 5 years ago

You need the secret key for the device to manage it locally, you get that by registering the device with the cloud api. So if you can intercept the traffic and see the key you can access the devices locally, otherwise you do need the cloud access keys. Did you sign up and request them? I found they were fairly easy to get. … On Mon, Jul 23, 2018 at 2:53 AM, JohnRambo93 @.***> wrote: Hi everyone, I'm fairly new to this and I am currently doing a project for university. I've tried to get the access ID and the ACCESS KEY for the cloud API from Tuya but was unable to. I was wondering if there is anyway to by pass the access ID and access key and just control the devices locally (i.e. no cloud access needed)? — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#20 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/ADLj6K04kyVNuEEDTkwalYjOfTna5fqxks5uJYDmgaJpZM4Rsiok .

Hi, once you have local key - how to make request to Turn On/Off?

thib5 commented 5 years ago

Hey I was wondering ... Would it be possible to redirect the mqtt trafic to a local broker check what is send to them and then just resend command ?

BillSobel commented 5 years ago

No, the MQTT servers are hardcoded in the firmware.

On Mon, Oct 29, 2018 at 7:27 AM thib5 notifications@github.com wrote:

Hey I was wondering ... Would it be possible to redirect the mqtt trafic to a local broker and then just resend command ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/codetheweb/tuyapi/issues/20#issuecomment-433930394, or mute the thread https://github.com/notifications/unsubscribe-auth/ADLj6AOvaEUwY1IPAPczTQc3sT2yZmCZks5upxBRgaJpZM4Rsiok .

thib5 commented 5 years ago

yes but I could make a rule in my router to redirect the trafic to my local broker ...

NorthernMan54 commented 5 years ago

Are you thinking of this?

https://medium.com/@alexharasic/hijacking-your-home-iot-appliance-part-1-8c2aabdf950d

Sent from my iPad

On Oct 29, 2018, at 5:36 PM, thib5 notifications@github.com wrote:

yes but I could make a rule in my router to redirect the trafic to my local broker ...

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

Apollon77 commented 5 years ago

I also just found that article ... I think MQTT is the way to go for some devices types.

The only unknown topic is: what is the password. I tried some things, but was not successfull :-(

Infos I found is:

Password MD5 (seckey returned after device active), taking the middle 16 bits

I think they mean 16 chars :-) but the localKey is it not :-(

Anyone an idea?

uDude commented 5 years ago

IF you are just wanting to control devices you can follow the example from TuyaInc on github.

Auth: https://github.com/TuyaInc/TuyaDemo/blob/master/open-mq-sdk/src/main/java/com/tuya/open/sdk/mq/MqAuthenticationDataProvider.java

Messaging: https://github.com/TuyaInc/TuyaDemo/blob/master/open-mq-sdk/src/main/java/com/tuya/open/sdk/mq/MqConsumer.java

They show how to build your authentication and how to sub to a topic. In the above two references.

Apollon77 commented 5 years ago

@uDude What is "AccessId" and "AccessKey" in these examples? Soma API Ids and stuff? Or local encryption keys or something we can get out of the JSOns the APPs get?

uDude commented 5 years ago

I forget the which key is which, but I believe it was outlined in https://docs.tuya.com/en/cloudapi/device_access.html

I think, emphasis on think -- not certain, that they are the deviceID and the deviceKey.

dominicklee commented 5 years ago

Bill, I was just going through the cloud(technically mobile) api. I decompiled the app, started with the UI Login Form and worked my way backwards through all the method calls and returns. You are right, that It is possible they are older keys, or keys they shouldn't have left active, but they worked with the tuyacloud library, as well as my own code for over a week and two app versions. I did check and the set of keys I used are still in the new app, but the new app is sending quite a bit more data on login. Verified the keys are still accurate through CharlesProxy.

@BillSobel Did you figure out what was causing Tuya from thinking the "app is outdated"? What can be done to fix that?

dominicklee commented 5 years ago

@BillSobel I tried changing the version to 2.0 just to log in. But for some reason, calling the tuya.m.device.list request will return an "API version error". Does this mean this new version does not support that action, or did they change the API parameters? Does anyone find any published documentation from Tuya on this new mobile update?

BillSobel commented 5 years ago

No. I never found a way to clear the account.

Sent from my iPhone please excuse any typos.

On Nov 19, 2018, at 3:41 AM, Dominick Lee notifications@github.com wrote:

Bill, I was just going through the cloud(technically mobile) api. I decompiled the app, started with the UI Login Form and worked my way backwards through all the method calls and returns. You are right, that It is possible they are older keys, or keys they shouldn't have left active, but they worked with the tuyacloud library, as well as my own code for over a week and two app versions. I did check and the set of keys I used are still in the new app, but the new app is sending quite a bit more data on login. Verified the keys are still accurate through CharlesProxy.

@BillSobel Did you figure out what was causing Tuya from thinking the "app is outdated"? What can be done to fix that?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

BillSobel commented 5 years ago

Haven’t seen an issue here by the Chinese docs are more upto date than the English ones. Read those with google translate

Sent from my iPhone please excuse any typos.

On Nov 19, 2018, at 4:27 AM, Dominick Lee notifications@github.com wrote:

@BillSobel I tried changing the version to 2.0 just to log in. But for some reason, calling the tuya.m.device.list request will return an "API version error". Does this mean this new version does not support that action, or did they change the API parameters? Does anyone find any published documentation from Tuya on this new mobile update?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

dominicklee commented 5 years ago

Has anyone here got their API v2.0 to work? Have they fully switched to MQTT only or do they still have REST API access to control devices?

This change they did is really affecting my projects

jmichaeltraub commented 5 years ago

Was anyone able to get and access? I tried a year or so ago and got no response.

dominicklee commented 5 years ago

Apparently not. I'm not sure whether their MQTT protocol is still the same. I don't see their API v2.0 being documentated. If anyone believes otherwise, please share the link.

They have bad programmers who slack on the documentation and close people out.

Orneeman commented 5 years ago

Hi!! I got this info : devid= 2047*****d9448 localkey =faf4**ceb8f what should be the next step to control my device remotely by third party software ( Postman..) ? Thanks

dominicklee commented 5 years ago

@Ericmas001 Could you please update to the latest SmartLife app on your old phone that has Fiddler and show us what request parameters are being sent for login and turning a device on/off?

Its been months that Tuya did not update their documentation for the 2.0 version API - I believe they unofficially decided to make it closed source. If anything, they removed their 1.0 version API documentation! This is ridiculous. Also, whatever docs they have online right now will not help at all. The "api key" that you get from them does not give access to anything except for the devices you designed yourself, not something you bought on Amazon (or other 3rd party).

I'm determined to figure this out for the sake of data. Tuya apparently gets to track your data on their cloud but they don't let you even control your devices openly. They are the unethical ones here.

dominicklee commented 5 years ago

@BillSobel What keys are you using nowadays? The "borrowed keys" or your own? And if you got mobile keys from Tuya, please shed some light on how you got them.

BillSobel commented 5 years ago

I got them from Tuya. Just signed up for an account and sent them my justification (writing home control plugin for HomeSeer). They authorized me within a week or so.

Sent from my iPhone please excuse any typos.

On Feb 2, 2019, at 1:22 PM, Dominick Lee notifications@github.com wrote:

@BillSobel What keys are you using nowadays? The "borrowed keys" or your own? And if you got mobile keys from Tuya, please shed some light on how you got them.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Orneeman commented 5 years ago

I got them from Tuya. Just signed up for an account and sent them my justification (writing home control plugin for HomeSeer). They authorized me within a week or so. Sent from my iPhone please excuse any typos. … On Feb 2, 2019, at 1:22 PM, Dominick Lee @.***> wrote: @BillSobel What keys are you using nowadays? The "borrowed keys" or your own? And if you got mobile keys from Tuya, please shed some light on how you got them. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Hey @BillSobel , I got the token, but when I try to control the device I receive this answer:

{ "code": 2010, "msg": "device not exist", "success": false, "t": 1549147492375 } What I do wrong ?

BillSobel commented 5 years ago

Which token are you referring to? Tokens are for device registration, not control. Did you register the device to your account?

On Sat, Feb 2, 2019 at 2:53 PM Orneeman notifications@github.com wrote:

I got them from Tuya. Just signed up for an account and sent them my justification (writing home control plugin for HomeSeer). They authorized me within a week or so. Sent from my iPhone please excuse any typos. … <#m-8402404856868371769> On Feb 2, 2019, at 1:22 PM, Dominick Lee @.***> wrote: @BillSobel https://github.com/BillSobel What keys are you using nowadays? The "borrowed keys" or your own? And if you got mobile keys from Tuya, please shed some light on how you got them. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Hey @BillSobel https://github.com/BillSobel , I got the token, but when I try to control the device I receive this answer:

{ "code": 2010, "msg": "device not exist", "success": false, "t": 1549147492375 } What I do wrong ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/codetheweb/tuyapi/issues/20#issuecomment-460006426, or mute the thread https://github.com/notifications/unsubscribe-auth/ADLj6Feo4LI7XNLaQz2y0EEkUREH4akJks5vJhbogaJpZM4Rsiok .

Orneeman commented 5 years ago

I mean that I got access ID and secret ( from Tuya) and now I want to control my device is it possible?

On Sun, 3 Feb 2019 at 1:53 BillSobel notifications@github.com wrote:

Which token are you referring to? Tokens are for device registration, not control. Did you register the device to your account?

On Sat, Feb 2, 2019 at 2:53 PM Orneeman notifications@github.com wrote:

I got them from Tuya. Just signed up for an account and sent them my justification (writing home control plugin for HomeSeer). They authorized me within a week or so. Sent from my iPhone please excuse any typos. … <#m-8402404856868371769> On Feb 2, 2019, at 1:22 PM, Dominick Lee @.***> wrote: @BillSobel https://github.com/BillSobel What keys are you using nowadays? The "borrowed keys" or your own? And if you got mobile keys from Tuya, please shed some light on how you got them. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Hey @BillSobel https://github.com/BillSobel , I got the token, but when I try to control the device I receive this answer:

{ "code": 2010, "msg": "device not exist", "success": false, "t": 1549147492375 } What I do wrong ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/codetheweb/tuyapi/issues/20#issuecomment-460006426, or mute the thread < https://github.com/notifications/unsubscribe-auth/ADLj6Feo4LI7XNLaQz2y0EEkUREH4akJks5vJhbogaJpZM4Rsiok

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/codetheweb/tuyapi/issues/20#issuecomment-460009832, or mute the thread https://github.com/notifications/unsubscribe-auth/AkSE9Ic1qnADh0i_CPVQh_OafRnfg4Euks5vJiUCgaJpZM4Rsiok .

dominicklee commented 5 years ago

@Orneeman What keys is it? Mobile or cloud API? Tuya used to have some documentation but removed alot of the pages. I think this page still has some good references: https://docs.tuya.com/en/cloudapi/cloud_access.html

Carefully read through everything and use Postman. This does take some decent time and trial/error unless you know what you're doing.

dominicklee commented 5 years ago

I got them from Tuya. Just signed up for an account and sent them my justification (writing home control plugin for HomeSeer). They authorized me within a week or so. Sent from my iPhone please excuse any typos. … On Feb 2, 2019, at 1:22 PM, Dominick Lee @.***> wrote: @BillSobel What keys are you using nowadays? The "borrowed keys" or your own? And if you got mobile keys from Tuya, please shed some light on how you got them. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

@BillSobel I just sent Tuya a message. Hopefully they will give some good keys. I'm sure our implementations are correct.

Orneeman commented 5 years ago

@Orneeman What keys is it? Mobile or cloud API? Tuya used to have some documentation but removed alot of the pages. I think this page still has some good references: https://docs.tuya.com/en/cloudapi/cloud_access.html

Carefully read through everything and use Postman. This does take some decent time and trial/error unless you know what you're doing.

@BillSobel I have the API key that means I can control my device via Postman?

BillSobel commented 5 years ago

Sorry Im not sure what Postman is, I developed my only solution for controlling them. I was on this list as I was sharing what I learned about UDP registration so it could be implemented here as well.

On Sun, Feb 3, 2019 at 1:12 AM Orneeman notifications@github.com wrote:

@Orneeman https://github.com/Orneeman What keys is it? Mobile or cloud API? Tuya used to have some documentation but removed alot of the pages. I think this page still has some good references: https://docs.tuya.com/en/cloudapi/cloud_access.html

Carefully read through everything and use Postman. This does take some decent time and trial/error unless you know what you're doing.

@BillSobel https://github.com/BillSobel I have the API key that means I can control my device via Postman?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/codetheweb/tuyapi/issues/20#issuecomment-460035433, or mute the thread https://github.com/notifications/unsubscribe-auth/ADLj6P3YM2x5wf9mVK7Da5SibgBA_Wehks5vJqgHgaJpZM4Rsiok .

limkopi78 commented 5 years ago

Does anyone know how home assistant did the integration via python? Somehow their calls only require username, password and country. Did they do their own backend to encapsulate all these?

Apollon77 commented 5 years ago

I checked that: It seems they registered and use an API that is also used by Alexa Skills or something like that. But because of this they only know basic information and control options

rajchristhu commented 5 years ago

I am trying to connect cloud API user sync interface then I am facing this kind of response. Anyone know about it, please tell me.

Responce: {'t': 1549606678728, 'success': False, 'errorCode': 'BIZTYPE_INVALID', 'status': 'error', 'errorMsg': 'API is not supported, please use the latest version.'}

Thanks.

BillSobel commented 5 years ago

The error literally tells you what is wrong. You are calling a depreciated api version. Bill

Sent from my iPad please excuse any typos

On Feb 7, 2019, at 10:21 PM, Christhu notifications@github.com wrote:

I am trying to connect cloud API user sync interface then I am facing this kind of response. Anyone know about it, please tell me.

Responce: {'t': 1549606678728, 'success': False, 'errorCode': 'BIZTYPE_INVALID', 'status': 'error', 'errorMsg': 'API is not supported, please use the latest version.'}

Thanks.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

rajchristhu commented 5 years ago

The error literally tells you what is wrong. You are calling a depreciated api version. Bill Sent from my iPad please excuse any typos … On Feb 7, 2019, at 10:21 PM, Christhu @.***> wrote: I am trying to connect cloud API user sync interface then I am facing this kind of response. Anyone know about it, please tell me. Responce: {'t': 1549606678728, 'success': False, 'errorCode': 'BIZTYPE_INVALID', 'status': 'error', 'errorMsg': 'API is not supported, please use the latest version.'} Thanks. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

I am using API version 1.0

This my request

{'a': 'tuya.cloud.user.sync', 'os': 'Linux', 'v': '1.0', 'clientId': 'xxxxxxx', 'lang': 'en', 'time': 1549606677, 'postData': '{"countryCode": "91", "username": "xx@gmail.com", "passwd": "xx", "nick": "", "usernameType": 2}', 'sign': '211b4026884cd871ed25f04ce24bc5d6'}

@BillSobel

BillSobel commented 5 years ago

The Tuya docs leave much to be desired. My advice is when you see something like this, go to the docs and change to the Chinese version (/cn in url vs /en) the try bumping the version number manually. Why not linked correctly the 2.0 docs are here for that api

https://docs.tuya.com/cn/cloudapi/cloudAPI/tuya.cloud.user.sync_2.0.html

Sent from my iPad please excuse any typos

On Feb 7, 2019, at 10:31 PM, Christhu notifications@github.com wrote:

The error literally tells you what is wrong. You are calling a depreciated api version. Bill Sent from my iPad please excuse any typos … On Feb 7, 2019, at 10:21 PM, Christhu @.***> wrote: I am trying to connect cloud API user sync interface then I am facing this kind of response. Anyone know about it, please tell me. Responce: {'t': 1549606678728, 'success': False, 'errorCode': 'BIZTYPE_INVALID', 'status': 'error', 'errorMsg': 'API is not supported, please use the latest version.'} Thanks. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

I am using API version 1.0

This my request

{'a': 'tuya.cloud.user.sync', 'os': 'Linux', 'v': '1.0', 'clientId': 'xxxxxxx', 'lang': 'en', 'time': 1549606677, 'postData': '{"countryCode": "91", "username": "xx@gmail.com", "passwd": "xx", "nick": "", "usernameType": 2}', 'sign': '211b4026884cd871ed25f04ce24bc5d6'}

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

rajchristhu commented 5 years ago

The Tuya docs leave much to be desired. My advice is when you see something like this, go to the docs and change to the Chinese version (/cn in url vs /en) the try bumping the version number manually. Why not linked correctly the 2.0 docs are here for that api https://docs.tuya.com/cn/cloudapi/cloudAPI/tuya.cloud.user.sync_2.0.html Sent from my iPad please excuse any typos … On Feb 7, 2019, at 10:31 PM, Christhu @.> wrote: The error literally tells you what is wrong. You are calling a depreciated api version. Bill Sent from my iPad please excuse any typos … On Feb 7, 2019, at 10:21 PM, Christhu @.> wrote: I am trying to connect cloud API user sync interface then I am facing this kind of response. Anyone know about it, please tell me. Responce: {'t': 1549606678728, 'success': False, 'errorCode': 'BIZTYPE_INVALID', 'status': 'error', 'errorMsg': 'API is not supported, please use the latest version.'} Thanks. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread. I am using API version 1.0 This my request {'a': 'tuya.cloud.user.sync', 'os': 'Linux', 'v': '1.0', 'clientId': 'xxxxxxx', 'lang': 'en', 'time': 1549606677, 'postData': '{"countryCode": "91", "username": @.***", "passwd": "xx", "nick": "", "usernameType": 2}', 'sign': '211b4026884cd871ed25f04ce24bc5d6'} — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Thanks, @BillSobel I cross the BIZTYPE_INVALID error.

Now I am facing the new error I send a request like, {'a': 'tuya.cloud.user.sync', 'os': 'Linux', 'v': '2.0', 'clientId': 'xxx', 'lang': 'en', 'time': 1549610606, 'postData': '{"schema": "tuyasmart", "countryCode": "91", "username": "xxx@gmail.com", "passwd": "xx", "nick": "rajchristhu", "usernameType": 2}', 'sign': 'e7a20e4a072225acd7081c5a3ee08a0d'} {}

And I am getting a response PERMISSION_DENIED,

{'t': 1549610607753, 'success': False, 'errorCode': 'PERMISSION_DENIED', 'status': 'error', 'errorMsg': 'No permission'}

any idea about it @BillSobel

BillSobel commented 5 years ago

Most likely using the wrong keys. Cloud api is keyed differently than mobile.

Sent from my iPad please excuse any typos

On Feb 7, 2019, at 11:27 PM, Christhu notifications@github.com wrote:

The Tuya docs leave much to be desired. My advice is when you see something like this, go to the docs and change to the Chinese version (/cn in url vs /en) the try bumping the version number manually. Why not linked correctly the 2.0 docs are here for that api https://docs.tuya.com/cn/cloudapi/cloudAPI/tuya.cloud.user.sync_2.0.html Sent from my iPad please excuse any typos … On Feb 7, 2019, at 10:31 PM, Christhu @.> wrote: The error literally tells you what is wrong. You are calling a depreciated api version. Bill Sent from my iPad please excuse any typos … On Feb 7, 2019, at 10:21 PM, Christhu @.> wrote: I am trying to connect cloud API user sync interface then I am facing this kind of response. Anyone know about it, please tell me. Responce: {'t': 1549606678728, 'success': False, 'errorCode': 'BIZTYPE_INVALID', 'status': 'error', 'errorMsg': 'API is not supported, please use the latest version.'} Thanks. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread. I am using API version 1.0 This my request {'a': 'tuya.cloud.user.sync', 'os': 'Linux', 'v': '1.0', 'clientId': 'xxxxxxx', 'lang': 'en', 'time': 1549606677, 'postData': '{"countryCode": "91", "username": @.***", "passwd": "xx", "nick": "", "usernameType": 2}', 'sign': '211b4026884cd871ed25f04ce24bc5d6'} — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Thanks, @BillSobel I cross the BIZTYPE_INVALID error.

Now I am facing the new error I send a request like, {'a': 'tuya.cloud.user.sync', 'os': 'Linux', 'v': '2.0', 'clientId': 'xxx', 'lang': 'en', 'time': 1549610606, 'postData': '{"schema": "tuyasmart", "countryCode": "91", "username": "xxx@gmail.com", "passwd": "xx", "nick": "rajchristhu", "usernameType": 2}', 'sign': 'e7a20e4a072225acd7081c5a3ee08a0d'} {}

And I am getting a response PERMISSION_DENIED,

{'t': 1549610607753, 'success': False, 'errorCode': 'PERMISSION_DENIED', 'status': 'error', 'errorMsg': 'No permission'}

any idea about it @BillSobel

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

rajchristhu commented 5 years ago

I am using Cloud API key getting from TUYA website dashboard @BillSobel

rajchristhu commented 5 years ago

I am using Cloud API key getting from TUYA website dashboard @BillSobel

tempsnip

This is my credential can I using this Access ID and Key then I implement the register (tuya.m.user.email.register)

My request:

https://a1.tuyacn.com/api.json {'a': 'tuya.m.user.email.register', 'os': 'Linux', 'v': '1.0', 'clientId': 'myID', 'lang': 'en', 'time': 1549622235, 'postData': '{"countryCode": "91", "email": "rajchristhu39@gmail.com", "passwd": "password123"}', 'sign': '2d6c877015ab143a154ef5bd1ed9844a'}

My Responce:

{'t': 1549622242495, 'success': False, 'errorCode': 'BIZTYPE_INVALID', 'status': 'error', 'errorMsg': 'API is not supported, please use the latest version.'}

Please clarify this error. DOCS: https://docs.tuya.com/en/cloudapi/appAPI/userAPI/tuya.m.user.email.register_1.0.html https://docs.tuya.com/cn/cloudapi/appAPI/userAPI/tuya.m.user.email.register_1.0.html @BillSobel

Thanks.

unparagoned commented 5 years ago

@rajchristhu I only started playing with cloud stuff last night and too be honest this thread is just making more confused. But in my journeys the only valid biztypes I found were are 'tuya' and 'smart_life'. But I maybe talking about a completely different API than you or everyone else is.

What is the current state of play of things I had a quick play with a couple cloud repos and I thought they were doing the same thing but there were a few differences and I'm not sure if they are just separate APIs with similar implantations.

I did manage to get a key from the Tuya site for tuyapi/cloud but the Tuya site said they have a limited life and supply. Anyway I got a bit lost after running the three introduction commands and getting my token. I did have more sucess with a python tuyapy setup. https://pypi.org/project/tuyapy/ . You just need your normal smart life or tuya app login, it's really simple and easy for people to set up. I managed to create a njs script which lets you log in a similar way to tuyapy does it.

codetheweb commented 5 years ago

@unparagoned from looking at the source for that Python module, it appears Tuya set up a special URL for Home Assistant users that doesn't require API keys. If someone wants to take a look at that and make a PR to do the same thing for tuyapi/cloud I'm happy to merge it.

You're right, at this point tuyapi/cloud only works with API keys that you get off Tuya's developer site. I didn't know the above method was feasible at the time (but I suspect the Home Assistant integration is somewhat limited).

In general, Tuya user accounts are always associated with a company's API keys; which is why I didn't think it was possible to authenticate solely with a user account.

unparagoned commented 5 years ago

@codetheweb I did give it a good go, but it was pretty much impossible to work in the change to tuyapi/cloud. It feels like they are using completely different apis. It almost feels like they have some sort of helper function sitting in the middle translating queries to the normal api. So I just worked on getting something working. I can now see the state of the devices and set the states to on/off. It's all relatively simple, apart from the fact the type of POST requests need to be of a very specific type and the settings for getting a token don't work for getting or setting states. https://github.com/unparagoned/cloudtuya