Mi smart plug - Xiaomi Binding does not find token

Hi there,

I bought the Mi Smart Plug, it is the EU version (this one) and want to connect it to my Openhab instance. I have successfully connected it to my Wifi and it works well in the Xiaomi Home app.

However when trying to add it to Openhab, I can find it, but it does not come with a token. When adding the thing, it is marked as uninitialized. I already have three other Xiaomi devices (air purifiers). One of them on the Chinese server and two on the Singapore server (I am in Vietnam). I added the smart plug when my Xiaomi account was set to Vietnam as country.
My Inbox in PaperUI shows two Xiaomi things, one is an air purifier (which is already initialized, no idea why it still shows up in the inbox) and one is the smart plug. This is the entry I get:

I tried various servers, but the binding does not properly recognise the thing, i.e. it does not find the token.

Any help is much appreciated!

as first hiny: Try to remove the county settings so all known servers are checked.
Check the json files in the userdata/miio folder to see if the server included your device in the responses.

what is the modelId? Is it an already supported model?

Hi Marcel,

thank you for your response. In the meantime I was able to get a token through these instructions and now it works.
It was not found on any server (also not with the country setting removed). I will still check these things and tell you the model id when I am at home, maybe this will help further development of the binding.

Hi Marcel,

sorry it took a while, I had a few busy weeks. The modelID is chuangmi.plug.hmi206, according to the binding page it should be supported.

Look indeed like you don’t have a working cloud connection. Hence no tokens found.
Anyways, good to here that with the laternative way you could obtain the token and it works for you

Yes, there seems to be some connection error with the Xiaomi cloud (I view this as a good thing…). In the logs there is an error getting logon location URL (Return code 70016). Might be because of pi hole.

This happens every ten minutes, is there an option to put this on mute?

The cloud connection is not needed except for getting tokens and vacuum maps.
The error every 10 min is when the discovery does a refresh, it will also refresh the info from the cloud.

You can remove your credentials, I expect the error to go away than as well.
Note: Return code 70016 typically indicates a wrong userId/password

ok, then I will try that. Might be that I had to reset my credentials in the Mi home app when adding the plug and then the credentials in Openhab became invalid. I will try that out

Hi Marcel,

I removed my credentials (and according to the logs there was some sort of updating happening), but the error remains. The full errror message is
Error logging on to Xiaomi cloud (0): Error getting logon location URL. Return code: 79916

Error logging on to Xiaomi cloud (0): Error getting logon location URL. Return code: 79916

That is an error I don’t think I saw before.
The only way to understand more what it is, to enable trace logging
log:set TRACE org.openhab.binding.internal.cloud

In trace mode, during the logon it has also some chinese error description. Throw it into google translate and maybe it has a better hint what is the issue at hand.

Unfortunately there is no known list of cloud errors as the whole thing was developed by reverse engineering, not from a clear spec.