Page 1 of 1

Error: Xiaomi Gateway: unable to write command - Invalid key (port is open)

Posted: Thursday 24 June 2021 10:47
by Wolly76
Hi All,

I've purchased the Xiaomi Gateway 2 and have been successful in opening the 9898 port using the UART and soldering procedure.
(following the instruction from a German site or the HA-site).
Subsequently, in Domoticz the Xiaomi Gateway has been added to the hardware according to these (outdated) instructions.

So far so good... When I switch on the light of the gateway by pressing the button or using the Xiaomi Home app on the iPhone, the state is updated in Domoticz. That means that there is connection between the two (Domoticz and the Gateway). However, the other way isn't that successful and results in an error (Error: Xiaomi Gateway: unable to write command - Invalid key).

Code: Select all

2021-06-24 13:57:08.479 Status: User: modoadmin (IP: 192.168.2.190) initiated a switch command (433/XiaomiGateway (Light)/On)
2021-06-24 13:57:08.631 Status: Xiaomi Gateway: SendMessageToGateway failed on first attempt, will try again
2021-06-24 13:57:08.630 Error: Xiaomi Gateway: unable to write command - Invalid key
2021-06-24 13:57:08.881 Error: Xiaomi Gateway: unable to write command - Invalid key 
What I've tried so far:
  • I had a similar issue with Zigbee2MQTT and then found out that the user rights were set to root instead of user "pi". Fixing this solved that issue. However, now, I don't see any file in the /domoticz/ folder that belongs to root or might be related. But of course, I might be mistaken :( .
  • Another suggestion found here wouldn't help as the powermanagement is already off.

Does anybody has a clue what this might cause? Or a suggestion to dig further?

Many thanks,
Wolly

Re: Error: Xiaomi Gateway: unable to write command - Invalid key (port is open)

Posted: Monday 28 June 2021 11:15
by Wolly76
In conjunction to my previous mail above, I was wondering if the password I'm using is not the correct one.

The app has changed considerably over the last few years. All internet instructions for the gateway refer to the 2017/2018 version of the Mi Home app. However, many of the notes does not apply anymore. I have registered to the Xiaomi-portal and used those credentials. But if I reread the instructions it appeared that the password should be a "key" or whatever.

Does anybody know how to retrieve the correct password/key if the portal-login-credentials are not the correct one?

[update] I found out this Github-site that offers a tool to retrieve the key.

However, It does not solve the problem yet.....

Does anybody know how to switch on the developer mode in the current Xiaomi Home app?

Many thanks in advance.
Kind regards.

Re: Error: Xiaomi Gateway: unable to write command - Invalid key (port is open)

Posted: Saturday 10 July 2021 14:10
by Wolly76
Mission accomplished! I've got the system working.

Some of the pitfalls I trapped in were:
  • The mentioned token is not the key that is required. The token can change from time to time.
  • What is required is the "LAN key" which cannot be obtained on a different way than the old Xiaomi version.
  • You don't need to have an android phone to install the old version...
This is what I found out with some help of others:
  • Install Bluestacks Android emulator: which you can find here. And install..., and start....
  • Open Chrome in the Android emulator and download the old version of Xiaomi using apkmirror
  • If you already have an account and had added the device using an iOs device (like I did) then login using your credentials and the gateway is displayed.
  • Subsequently follow the steps by tapping three times on version number in the about menu. Then you will get three extra options. One of these (the second one) contains the LAN key.
The rest is known.... just follow the instructions on the Domoticz site.