merdok / homebridge-miot

Homebridge plugin for devices supporting the Xiaomi miot protocol
MIT License
395 stars 63 forks source link

Issue: mi Smart plug failed auth #168

Closed Vannixxo closed 2 years ago

Vannixxo commented 2 years ago

Mi two smart plugs always worked fine (Mi Cloud), starting from today homebridge console reports: 401 unauthorized, and the devices can’t be controlled

merdok commented 2 years ago

Maybe something changed with your account? A 401 in general means that you do not have access to the service/account.

Vannixxo commented 2 years ago

Nope, same credentials. App works regularly!

merdok commented 2 years ago

It does not matter if your app works or not, something might have changed with your account which now prevents access to some services (i guess maybe there was some kind of switch between years in your country regarding regarding your account?)

iishrnika commented 2 years ago

Hey, I have the same issue with all of my xiaomi devices.

merdok commented 2 years ago

What country do you have your devices on and what country is your micloud account setup for? Also could you post a homerbidge debug log, ideally with the the deepDebug parameter set to true, so at least i can have a look at what point it fails for you. My suspicion is that either Xiaomi changed something or something with your account changed (might be specific for your country since for me all devices over micloud are working fine)

iishrnika commented 2 years ago

Hey, my xiaomi devices are in romania, but the only server that worked previously was DE, so it's set on Germany. How can i export my log file, or it's ok to post it here with copy paste?

merdok commented 2 years ago

Interesting... I am not aware of any changes to micloud for the Germany region.

Please no copy/paste as it might get too big 😄 Try to attach it as a .txt file or post it on gist https://gist.github.com/ just make sure to remove any sensitive information.

iishrnika commented 2 years ago

https://gist.github.com/iishrnika/1c57c643e7813955fc6e693c489a97e8

iishrnika commented 2 years ago

If i did it wrong please say.

merdok commented 2 years ago

That does not help me much. Like i already mentioned above you need to run homebridge in debug mode and additionally enable the deepDebugLog parameter for one of your devices which has this issue.

iishrnika commented 2 years ago

hey, i just updated it with the deepDebugLog on

kovapatrik commented 2 years ago

I don't know if it matters much, but I have the same issues and my account is also in Germany region.

https://gist.github.com/kovapatrik/ab34a7a193caaf29303efe91980d327d

Extra info: when I try to use any of the token extractor windows apps, I got there also an Unauthorized error.

merdok commented 2 years ago

Well not sure what the issue here is, might be that something changed with the germany server (but why only Germany?) or it might be just a temporary issue due to a bug... I think for now you need to observe that for a couple of days and see if it will start work again... other then that, you can try to move your devices to another server (i have all my devices on the CN server and they are working fine)

@kovapatrik yeah, that would indicate that there is something wrong with the server...

iishrnika commented 2 years ago

Thanks.

kovapatrik commented 2 years ago

Okay, thanks for the help!

zormic commented 2 years ago

Have the same problem with mine...

merdok commented 2 years ago

@zormic also got your devices on the Germany server?

zormic commented 2 years ago

Yup!

Vannixxo commented 2 years ago

Yes Germany server on the plugin, Italy inside Mi account (one device requires it)

Seger85 commented 2 years ago

We had a worldwide server failure on December 31st. since then all servers are online, only the DE server is still causing problems, the devices are not listed on the server and you can only log in to a limited extent. Do you always have to rely on the server? Thought with the token it runs locally. However, like you, I am currently not getting the token. I think we have to wait or move to another server, which I don't want.

merdok commented 2 years ago

@Seger85 as i thought, there must have been something going on with the server... Yes, for device which does not support the miot protocol natively (older devices, which was released before around 2020) all commands has to go over the micloud, which takes care of the translation of the older protocol to the miot protocol. On newer devices all commands are sent locally and a micloud connection is not needed.

Like i already mentioned the best would be first to wait a couple of days and see if xiaomi fixes the issue (maybe due to holidays in Germany nobody could have a look at the issue yet). Another option would be to switch to another server since all other servers seems to work fine.

Seger85 commented 2 years ago

Hey @merdok,

you had just said that it is only for devices before about 2020 so how exactly do you find out and do you happen to know how it behaves with the device:

xiaomi air purifier 3c

The release year is not that long ago: Late 2020/early 2021

Thank you for all and fingers crossed that the DE servers are back soon ;-)

merdok commented 2 years ago

@Seger85 air purifier 3c is a native miot device, you do not need micloud to control it, should also work with local commands.

Seger85 commented 2 years ago

@merdok I don't know how it should work locally, the token must be entered in your plugin.

My token was reset somehow, so I have to get the current one.

My device was offline so I had to reset the wi-fi settings and it hasn't shown up in Homebridge since. It looks like my air purifier 3C got a new token.

Maybe you would be so kind and explain it to me here or by email.

Thank you very much, Seger

merdok commented 2 years ago

@Seger85 this is not the correct place to discuss your token changes since it has nothing to do with the issue. If your token changed, then you have to get a new one and enter it in the config.json

Seger85 commented 2 years ago

Hey buddy,

I'll try an e-mail, but I don't know if it'll get through. I don't know where else to ask for what I need ;).

My problem lies exactly in your description. I can only get a new token via this tool, which requests the server, right? Or do I have a possibility to get the new token locally? If so, then of course I have understood it and it would be my desired local solution.

Thank you very much, Seger

merdok commented 2 years ago

Please use the README for that, there is a dedicated page which gives a couple of options on how to get the token here: https://github.com/merdok/homebridge-miot/blob/main/obtain_token.md

kikiwora commented 2 years ago

Yeah, I have the same issue. The DE server is used and nothing works as a result - 401 authorization failure :( And the funny thing here is that Xiaomi disabled LAN control for lots of devices (at least Yeelight devices), so now we have no choice but to use cloud (which doesn't work at this moment)

merdok commented 2 years ago

Ok got an update. It seems that Xiaomi changed the authentication on the DE server to a more secure one, but all other servers are still using the older one. I do not know why they did this only on the DE server. Anyway, it seems that i will have to look at the MiCloud protocol code and update it with the authentication which is used on the DE server. I will be looking into that in the next days and hoping to get a fix as soon as possible!

zormic commented 2 years ago

It appears to be working since this morning!

edit: It did for a moment and then Login error. Login step 2 failed

merdok commented 2 years ago

I think they have some issues right now with their servers. I often see that my devices cannot sync even on china servers.

merdok commented 2 years ago

Hmm, seems like the Germany server is working again by using the old authentication. Can you guys confirm that the issue is fixed for you?

kikiwora commented 2 years ago

Can you guys confirm that the issue is fixed for you?

Yep, all seems to work just fine from this morning.

Seger85 commented 2 years ago

+1

iishrnika commented 2 years ago

+2

Sent from Yahoo Mail for iPhone

On Tuesday, January 4, 2022, 5:17 PM, Seger85 @.***> wrote:

+1

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.Message ID: @.***>

merdok commented 2 years ago

Ok, so it was indeed in the end just some kind of a bug with the DE server which caused the old authentication not to work anymore and they seem to fixed it. Good to hear 👍

I already did implement the new authentication thou (the same as the mi home app uses), and will be switching to that in a future update (no action will be needed from you), but at least i do not have to rush now and properly test everything!