OpenWonderLabs / SwitchBotAPI

SwitchBot Open API Documents
874 stars 73 forks source link

API 190 Error #296

Closed Shirotaku closed 5 months ago

Shirotaku commented 6 months ago

Current Situation

When using SwitchbotPy or Home Assistant (SwitchBot Bluetooth integration) i to sign in to my account I'm getting API 190 Error and don't know why. Any ideas? I'm logging in using email and password.

Logs

Haven't found relevant logs. Just API Error 190.

Configuration

?

Environment

Additional Context

No response

donavanbecker commented 6 months ago

you are over your rate limit for the day: https://github.com/OpenWonderLabs/SwitchBotAPI?tab=readme-ov-file#request-limit

Shirotaku commented 6 months ago

you are over your rate limit for the day: https://github.com/OpenWonderLabs/SwitchBotAPI?tab=readme-ov-file#request-limit

surely not, haven't used it at all for a few days

donavanbecker commented 6 months ago

You haven't pulled any status updates?

Shirotaku commented 6 months ago

I'm just using the SwitchBot app to control my lock. I've tried using the SwitchBot lock via the Home Assistant "SwitchBot Bluetooth" integration since I've got the lock (about a week ago). Since day 1 I'm getting 190 Error in HA as well via SwitchBotPy.

Shirotaku commented 6 months ago

Edit: I am using pySwichtBot (https://github.com/Danielhiversen/pySwitchbot#obtaining-locks-encryption-key) not SwitchBotPy (if relevant). But I'm also just using this, since the Bluetooth integration for home assistant doesn't work.

NdK73 commented 6 months ago

Same error here. Newly installed lock, never used their services before => no way I have exceeded limits. The app works correctly. Smells like 3rd party lockout...

Jeffnl98 commented 6 months ago

I have several switchbot devices, all work perfect in the switchbot bluetooth intergration. Only the lock seems too have trouble configuring.

NdK73 commented 6 months ago

Customers assistance pusher a firmware update (from 6.6 to 6.8) but that did not fix the issue (as expected).

mali385 commented 6 months ago

I also have same issue customer support suggest me update the lock firmware but the firmware update not showing up in the app.

Spirineu commented 6 months ago

Having the same issue!

Reacted to the issue :)

micaelp commented 6 months ago

I'm having exactly the same issue. Lock purchased 2 days ago. Works fine with the Mobile App, HomeAssistant bluetooth integration returns API error 190 as well as the https://github.com/Danielhiversen/pySwitchbot#obtaining-locks-encryption-key script. I even bought a hub and registered the lock to wifi but this made no difference to the issue. My lock is running 6.4 firmware and there is no firmware update available 6.6 or 6.8 as @NdK73 mentioned.

Spirineu commented 6 months ago

I'm having exactly the same issue. Lock purchased 2 days ago. Works fine with the Mobile App, HomeAssistant bluetooth integration returns API error 190 as well as the https://github.com/Danielhiversen/pySwitchbot#obtaining-locks-encryption-key script. I even bought a hub and registered the lock to wifi but this made no difference to the issue. My lock is running 6.4 firmware and there is no firmware update available 6.6 or 6.8 as @NdK73 mentioned.

Exactly the same issue yup, glad to see it's not because of me :)

hsakoh commented 6 months ago

As far as I understand, this issue pertains to the HomeAssistant SwitchBot Bluetooth integration and not to the SwitchBot API (OpenAPI).

It seems more appropriate to raise an issue on the HomeAssistant side.

To be more specific, when operating the SwitchBot Lock via Bluetooth, it requires a keyId and key. Therefore, when adding Lock to the SwitchBot Bluetooth integration:

  1. Log in to AWS Cognito IdP using the ID and password to obtain an access token.
  2. Use this access token to call an internal API (/developStage/keys/v1/communicate), unrelated to this repository, to retrieve the key.

I believe there may be a failure in either step 1 or step 2, but this topic falls outside the scope of this repository.

https://github.com/home-assistant/core/issues/85243 https://github.com/home-assistant/core/issues/104572

hsakoh commented 6 months ago

I've created a minimal sample in C# to retrieve the key, equivalent to the process described. It should clarify where the error occurs (likely Step 2). https://gist.github.com/hsakoh/f3b48514f43d98c2f9a2f7a20bbfe6d8 Just for reference.

In my environment, I can retrieve the key using both the HomeAssistant integration and the aforementioned program.

NdK73 commented 6 months ago

The token to use is just the one you left in the code or the one obtained via developer-mode in the app?

hsakoh commented 6 months ago

The token to use is just the one you left in the code

Yes.

It appears that the client ID and secret embedded within the SwitchBot app have been extracted through reverse engineering or similar means. I'm implementing based on this information. (https://github.com/Danielhiversen/pySwitchbot/blob/master/switchbot/api_config.py)

This differs from the developer tokens and secrets required to call the SwitchBot API (OpenAPI).

micaelp commented 6 months ago

The token to use is just the one you left in the code

Yes.

It appears that the client ID and secret embedded within the SwitchBot app have been extracted through reverse engineering or similar means. I'm implementing based on this information. (https://github.com/Danielhiversen/pySwitchbot/blob/master/switchbot/api_config.py)

This differs from the developer tokens and secrets required to call the SwitchBot API (OpenAPI).

Thanks @hsakoh but I can't seem to get this code to run without loads of errors referring to out of c#7.0 spec. Is there a preferred compiler to use?

hsakoh commented 6 months ago

@micaelp The first program presented was checked with .NET 8/LangVer12. .NET 6/C#7.0 buildable added. https://gist.github.com/hsakoh/f3b48514f43d98c2f9a2f7a20bbfe6d8#file-program-langver7-dotnet6-cs

micaelp commented 6 months ago

@hsakoh thanks for your help so far. I did manage to get your original .net 8 code working adding 'using System.Threading.Tasks;' to correct the task command failure and also a {} at the end of the namespace. However, using your client ID and secret I get 'not owner' and if I generate my own ID and secret I get error 400 bad request. I have installed your MQTT Home Assistant add-on and managed to get that working, however there are delays in the commands being triggered, so I was hoping to be able to see the key result in the log files but it doesn't appear to reference them.

hsakoh commented 6 months ago

@micaelp When you say "not owner," do you mean that in the response of Step 2 (/developStage/keys/v1/communicate), the message statusCode: 190, message: not the device owner is returned?

If so, it's likely that either the user ID/PW entered cannot access or operate the Lock, or there's an error in the entered MAC address. The deviceMac should be specified in the following format: C41D96xxxxxx Please ensure it's all uppercase and without colons or hyphens.

I'll reiterate that the client ID and client secret are values reverse-engineered from the app, and they are common IDs/secrets shared among all users. They are not tokens or keys obtainable in developer mode. When you're trying to retrieve the key for the Lock, you won't be using tokens or keys obtainable in developer mode.

micaelp commented 6 months ago

@hsakoh user ID/PW is correct and MAC is also correct and all uppercase. Correct error returned is statusCode:190,message:not the device owner. Also I get "Object reference not set to an instance of an object." in reference to the 'Console.WriteLine($"keyId:{communicateResp.body.communicationKey.keyId},key:{communicateResp.body.communicationKey.key}");' command

hsakoh commented 6 months ago

@micaelp NullReferenceException occurs when the status code is 190. It happens because the implementation for handling exceptional cases is missing.Please ignore it as it's not relevant to the core issue.

If the entered account is indeed the owner of the Lock and the MAC address matches, I feel there's nothing more we can do at this point.

As for other options to try... how about associating another account? You can try the following steps: 1.Create a new SwitchBot account. 2.Obtain an invitation code with your current user. https://support.switch-bot.com/hc/en-us/articles/4424755304215-How-do-I-share-devices-with-other-users 3.Log in to the app with the new account and join the home by entering the invitation code. https://support.switch-bot.com/hc/en-us/articles/4424792502935-How-can-I-join-other-users-in-Home-Sharing 4.Try to retrieve the Lock's key with the new account.

micaelp commented 6 months ago

@hsakoh same error 190 not the device owner. I have a feeling the lock may have had a previous owner and is refurbished. I'm going to reach out to switchbot to check.

Spirineu commented 6 months ago

@hsakoh same error 190 not the device owner. I have a feeling the lock may have had a previous owner and is refurbished. I'm going to reach out to switchbot to check.

let me know if that was it

hsakoh commented 6 months ago

@micaelp It seems that there has been a change in the host for calling /keys/v1/communicate in the latest android app. For recently created accounts, it might be possible to obtain it only from the new host.

Could you try executing with the URL changed as follows and see what happens? Old: "https://l9ren7efdj.execute-api.us-east-1.amazonaws.com/developStage/keys/v1/communicate" New: "https://wonderlabs.us.api.switchbot.net/wonder/keys/v1/communicate"

micaelp commented 6 months ago

@hsakoh Thanks for the update, but unfortunately I get the same error still.
Screenshot 2024-05-13 164144

micaelp commented 6 months ago

@hsakoh same error 190 not the device owner. I have a feeling the lock may have had a previous owner and is refurbished. I'm going to reach out to switchbot to check.

let me know if that was it

@Spirineu Switchbot support confirmed the lock was removed from the 'original account'. Upon opening the Switchbot app I can see that the Lock is no longer there. I have re-paired it now, completed calibration and still getting the error message from HomeAssistant and from @hsakoh's script. :(

micaelp commented 6 months ago

@SwitchBot @SwitchBot-Wonderlabs just wondering if you could offer any input? I see nothing from you although Switchbot support say you're very active here?

alexschultze commented 6 months ago

+1 with this issue.

hsakoh commented 6 months ago

I omitted to check the basic assumption. You all want to control the “lock”, not the “lock pro”... right?

huyuwei1996 commented 6 months ago

@hsakoh You can try using "https://wonderlabs.ap.api.switchbot.net/wonder/keys/v1/communicate", especially if your location is in a country like Japan.

@micaelp try using "https://wonderlabs.eu.api.switchbot.net/wonder/keys/v1/communicate", especially if your location is in Europe.

micaelp commented 5 months ago

I omitted to check the basic assumption. You all want to control the “lock”, not the “lock pro”... right?

yes, original lock.

alexschultze commented 5 months ago

Long story short, apparently "key retrieval" is not an official feature in the official API.

It is therefore probably the wrong place to ask here, it would be nice to have "official" support.

The authentication for retrieving the keys has changed. The problem will be solved in the respective library (https://github.com/Danielhiversen/pySwitchbot).

hsakoh commented 5 months ago

I will share the program that has been modified to obtain the access token using SRP and to retrieve the LockKey. https://gist.github.com/hsakoh/cc079f56b509d601db6924ed70d5b8b9

I completely agree that this issue should not be opened in this repository.

micaelp commented 5 months ago

I will share the program that has been modified to obtain the access token using SRP and to retrieve the LockKey. https://gist.github.com/hsakoh/cc079f56b509d601db6924ed70d5b8b9

I completely agree that this issue should not be opened in this repository.

@hsakoh You are my hero! Thanks to you and of course @alexschultze I've now got my lock natively working in HomeAssistant. I got error 190 with the first 2 APIs but the 3rd one did the trick (eu, which makes sense seeing as I'm in that region).

mali385 commented 5 months ago

I will share the program that has been modified to obtain the access token using SRP and to retrieve the LockKey. https://gist.github.com/hsakoh/cc079f56b509d601db6924ed70d5b8b9 I completely agree that this issue should not be opened in this repository.

@hsakoh You are my hero! Thanks to you and of course @alexschultze I've now got my lock natively working in HomeAssistant. I got error 190 with the first 2 APIs but the 3rd one did the trick (eu, which makes sense seeing as I'm in that region).

That's great! Can you share how you get the lockkey?

hsakoh commented 5 months ago

I have implemented some additional ideas. https://gist.github.com/hsakoh/fdeadc915b7c62ed443604ad3b364f2d

  1. Retrieving the access token https://account.api.switchbot.net/account/api/v1/user/login
  2. Determining the botRegion https://account.api.switchbot.net/account/api/v1/user/userinfo
  3. Obtaining the key and keyId https://wonderlabs.{botRegion}.api.switchbot.net/wonder/keys/v1/communicate

Whether the botRegion obtained in Step 2's UserInfo is wonderlabs.{botRegion} will require verification by various users. (At least for Japanese users, ap is returned, so it worked correctly.)

If these steps are implemented in PySwitchbot, it might make the setup process easier for everyone.

micaelp commented 5 months ago

I will share the program that has been modified to obtain the access token using SRP and to retrieve the LockKey. https://gist.github.com/hsakoh/cc079f56b509d601db6924ed70d5b8b9 I completely agree that this issue should not be opened in this repository.

@hsakoh You are my hero! Thanks to you and of course @alexschultze I've now got my lock natively working in HomeAssistant. I got error 190 with the first 2 APIs but the 3rd one did the trick (eu, which makes sense seeing as I'm in that region).

That's great! Can you share how you get the lockkey?

@mali385 to use @hsakoh's code, I used LINQPad8 for Windows. Language is C# and .NET version is 8. Enter your registered email address, password and lock MAC address (omitting delimiters and using all uppercase), then scroll down to HTTP method code and comment/uncomment out to use the line relevant to your region. then run the code. For HomeAssistant's Switchbot Bluetooth service, both the KeyID and Key are needed.

Spirineu commented 5 months ago

Hey @micaelp

so I was able to run it and get the key!

But when i put in to HA integration it keeps loading until it gives the error

image image

any idea?

NdK73 commented 5 months ago

Script at https://github.com/Danielhiversen/pySwitchbot/issues/234#issuecomment-2123565588 is working for me (after removing @.***").

Il gio 23 mag 2024, 12:21 Spirineu @.***> ha scritto:

Hey @micaelp https://github.com/micaelp

so I was able to run it and get the key!

But when i put in to HA integration it keeps loading until it gives the error

image.png (view on web) https://github.com/OpenWonderLabs/SwitchBotAPI/assets/72891552/83af7d3c-4eb8-40fe-995b-3b82329ff85f image.png (view on web) https://github.com/OpenWonderLabs/SwitchBotAPI/assets/72891552/76801e47-a8b8-413f-b365-efeeee94816f

any idea?

— Reply to this email directly, view it on GitHub https://github.com/OpenWonderLabs/SwitchBotAPI/issues/296#issuecomment-2126749503, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAODXYIJFUUVOH4YEBQX3EDZDW7MNAVCNFSM6AAAAABHA6SFIGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRWG42DSNJQGM . You are receiving this because you were mentioned.Message ID: @.***>

Spirineu commented 5 months ago

Script at Danielhiversen/pySwitchbot#234 (comment) is working for me (after removing @."). Il gio 23 mag 2024, 12:21 Spirineu @.> ha scritto: Hey @micaelp https://github.com/micaelp so I was able to run it and get the key! But when i put in to HA integration it keeps loading until it gives the error image.png (view on web) https://github.com/OpenWonderLabs/SwitchBotAPI/assets/72891552/83af7d3c-4eb8-40fe-995b-3b82329ff85f image.png (view on web) https://github.com/OpenWonderLabs/SwitchBotAPI/assets/72891552/76801e47-a8b8-413f-b365-efeeee94816f any idea? — Reply to this email directly, view it on GitHub <#296 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAODXYIJFUUVOH4YEBQX3EDZDW7MNAVCNFSM6AAAAABHA6SFIGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRWG42DSNJQGM . You are receiving this because you were mentioned.Message ID: @.***>

Hey what do you mean? on the script? I was able to get the key and the api key but when putting on HA it doenst work

NdK73 commented 5 months ago

I used that script and added the lock in HA by id and key, not with cloud account.

Spirineu commented 5 months ago

I used that script and added the lock in HA by id and key, not with cloud account.

Hey

Yup that's what I did. I did wit id and key but it give the error.

"uknown error"

Spirineu commented 5 months ago

Also my key Id only has 2 characters

eg: h1

micaelp commented 5 months ago

@Spirineu 2 character ID is correct. I can only assume the error is down to a bluetooth communication timeout. Passive scanning needs to be disabled on your BT adapter. Was your lock discovered or did you add manually?

Spirineu commented 5 months ago

@Spirineu 2 character ID is correct. I can only assume the error is down to a bluetooth communication timeout. Passive scanning needs to be disabled on your BT adapter. Was your lock discovered or did you add manually?

Hey

So passive scanning is disabled and the lock was auto discovered. image

My BT adapter is TP-Link UB500

Nardol commented 5 months ago

My BT adapter is TP-Link UB500

According to the Unsupported adapters part of the Bluetooth integration Documentation:

tp-link UB500 (RTL8761BU) - Frequent connection failures with active connections

It might be a cause of your error.

hsakoh commented 5 months ago

I recommend checking the logs output by the integration, not just the screen display. If there are any errors occurring in the config_flow, those error logs should appear. However, since the discussion is quite off-topic now, it might be better to move this to the HomeAssistant side.


To briefly summarize the conclusion of this issue:

mali385 commented 5 months ago

With new relase of Home Assistant 2024.5.5 the problem is solved. I succesfully added Switchbot Lock to the Home Assistant.

Spirineu commented 5 months ago

With new relase of Home Assistant 2024.5.5 the problem is solved. I succesfully added Switchbot Lock to the Home Assistant.

Yup it solved, well more or less.

I've switch my Bluetooth dongle which was on of the issues and it worked, until a few days ago, I can lock the door, but the door is always marked as opened.

Any ideas?