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

Others (MiLight, Hue, Toon etc...)

Moderator: leecollings

Post Reply
User avatar
Wolly76
Posts: 24
Joined: Sunday 21 March 2021 8:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands / Utrecht region
Contact:

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

Post 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
User avatar
Wolly76
Posts: 24
Joined: Sunday 21 March 2021 8:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands / Utrecht region
Contact:

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

Post 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.
User avatar
Wolly76
Posts: 24
Joined: Sunday 21 March 2021 8:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands / Utrecht region
Contact:

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

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest