Not able to get Xiaomi Gateway Key

I also have a DGNWG05LM EU getaway.
What I did was I’ve added https://github.com/AlexxIT/XiaomiGateway3 to HACS, so I could get the token in the most convenient way.
After that, I’ve added the Xiaomi Miio Integration manually, and it worked.

@vorion Strange that it worked with the DGNWG05LM EU, because the documentation says it shouldn’t work.
I never bothered with it then. Let’s try it.

I’ve only used the https://github.com/AlexxIT/XiaomiGateway3 repository to get the token. It logs in to the Xiaomi Cloud (as the Mi Home app) so you can get information (token, IP, MAC) for every device.
But you cannot add the gateway with that integration.

Well “works” is a matter of perspective. The DGNWG05LM will appear, you’ll be able to set the alarm and change the color but you won’t have access to any subdevices, neither be able to know if the alarm rings.

Hi Olivier

Thanks for your complete information here. I note you said that Aqara ZHWG11LM is OK and you have some? I have two, Both connect via the HomeKit integration in HA and I can turn the lights on and off so all is well there Port 9898 is not open so I am unable to use the sounds like the doorbell, which I would love to make go. I have tried connecting to a UART and while I can see the thing boot up etc. The commands psm-set network.open_pf 3 coming up with an error like not recognised command.

Did you manage to open the port on yours? if so how please?

Hello @bdb1,

yes i have 2 ZHWG11LM, the good news is you dont have to open Port 9898 or anything else!

You dont have the “ringtone” as an entity, you have to use it as a “service” : you need to read the doc :wink: :

https://www.home-assistant.io/integrations/xiaomi_aqara/

Services
The gateway provides the following services:

Service xiaomi_aqara.play_ringtone
Service xiaomi_aqara.stop_ringtone

example :

- alias: Let a dog bark on long press
  trigger:
    platform: event
    event_type: xiaomi_aqara.click
    event_data:
      entity_id: binary_sensor.switch_158d000xxxxxc2
      click_type: long_click_press
  action:
    service: xiaomi_aqara.play_ringtone
    data:
      gw_mac: xxxxxxxxxxxx
      ringtone_id: 8
      ringtone_vol: 8

- alias: Stop barking immediately on single click
  trigger:
    platform: event
    event_type: xiaomi_aqara.click
    event_data:
      entity_id: binary_sensor.switch_158d000xxxxxc2
      click_type: single
  action:
    service: xiaomi_aqara.stop_ringtone
    data:
      gw_mac: xxxxxxxxxxxx

enjoy!

The trigger can be whatever you want…a timer, a motion sensor, … you can even create an input.bolean to create a button to call the service.

If you want to have the “Alarm Panel” option, you need to use -> configuration -> integration -> + -> homekit accessories and add your Aqara Gateway, after that you can arm and disarm your gateway within Home Assistant.

Have fun!

Thanks so much for your reply. Sorry I should have said. I have two others that work fine that are a different model and the port is open. These ones when I run this in Developer mode (note the xx’s in the MAC are blanked for the forum:

Service: xiaomi_aqara.play_ringtone

Service Data:

gw_mac: ‘xx:xx:xx:xx:xx:xx’
ringtone_id: 10
ringtone_vol: 10

When I hit call service a black line comes upo down the bottom and says: (note the xxxxx in the MAC is blanked for this forum). Failed to call service xiaomi_aqara/play_ringtone. Unknown gateway sid xxxxxxxxx for dictionary value @ data[‘gw_mac’]

From Log

Logger: homeassistant.components.websocket_api.http.connection
Source: core.py:1405
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 8:57:55 (3 occurrences)
Last logged: 8:58:06

[140704683660624] Unknown gateway sid xxxxxxxxx for dictionary value @ data[‘gw_mac’]

Traceback (most recent call last): File “/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py”, line 135, in handle_call_service await hass.services.async_call( File “/usr/src/homeassistant/homeassistant/core.py”, line 1405, in async_call processed_data = handler.schema(service_data) File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 272, in call return self._compiled([], data) File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 594, in validate_dict return base_validate(path, iteritems(data), out) File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 432, in validate_mapping raise er.MultipleInvalid(errors) voluptuous.error.MultipleInvalid: Unknown gateway sid xxxxxxx for dictionary value @ data[‘gw_mac’]

Hi Olivier

You seem to be the only person that has this working! So I am sorry to come back at you!! Can you please help?

I have tried and tried again with this but I still get the error. I simply want to play a sound. See the automation I have copied yours. The Gateway is in the Homekit Integration and I can turn the light on/off no problem but when I call the service in an automation or use the Developer tools I get the same error. Unknown gateway sid xxxxxxxxx for dictionary value @ data[‘gw_mac

Note the xx is there to obscure the MAC for the forum.

Thanks in advance

hi!

not well formated : its a syntax problem, try :

gw_mac: 54ef44ccxxxx
ringtone_id: 10
ringtone_vol: 10

enjoy!

Hi Olivier

Sorry. No dice. Copied your format and get:

Error executing script. Invalid data for call_service at pos 1: Unknown gateway sid 54ef44xzxxxxx for dictionary value @ data[‘gw_mac’]

hi

Are you sure its the right gateway mac adress?

go in MiHome APP and be sure of the IP first. Then go to download https://www.advanced-ip-scanner.com and chek your ip and copy your mac adress and compare…just to be sure…

Hi With the new interface of the xiaomi home apps I’m not able to activate the lan access

you have a DGNWG02LM ? right? LAN access is only available with this gateway.

I have the MiHome APP 5.9.19 of the 7 december 2020 and it still have the “LAN” menu, no change.

Hi Olivier

I really appreciate you helping me here my friend. Still no luck. Are you aware that the new ones do not allow you to go into the LAN access mode the old ones did? Sorry silly question but it was a surprise to me.

I have two of the ZHWG11LM gateways and I checked on my router. I checked that it describes the devices as Aqara_Hub-34cb and I copied and pasted the MAC into the automation you can see part of above (previous post). I also tried under developers tools - see image below. The same automation works with the other Aqara gateways I have except they are V3 and have the ports opened. I tried using the different MACs. The two that work in Dev tools and the two that don’t, the ones we are talking about here, don’t.

I have checked the correct MAC in the MiHome app

Below is from the HA logs.

Logger: homeassistant.components.automation.new_automation_2
Source: core.py:1399
Integration: Automation (documentation, issues)
First occurred: 19:14:34 (3 occurrences)
Last logged: 19:17:05

While executing automation automation.new_automation_2
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 404, in async_trigger
    await self.action_script.async_run(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1026, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 242, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 250, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 457, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1399, in async_call
    processed_data = handler.schema(service_data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: Unknown gateway sid 54efxxxxx for dictionary value @ data['gw_mac']

Capture

Lan access is not an option for ZHWG11LM, so its normal you dont have this.

its only for DGNWG02LM.

Have you got a chinese version of ZHWG11LM? or EU ones?

I have chineses versions for the 5 xiaomi gateway i owned. Mainland China in the MiHome App config.

Everything is auto discovered in HA with the new integration Xiaomi Homekit.

Chek if its not EU version and yours setting are Mainland China in Xiaomi MiHome.

Hey Olivier

I am New Zealand so no chance they are European. Got them on Aliexpress. Yes the MiApp is on Mainland China.

Any other bright ideas?

B

Yes I have 2 of them
When I start to configure the 1st one I hade the old interface
After a update I get the New interface for sole device

My gateways are china version too

hello!

sorry to heard that…

Are the gateways are on the same network with the server of HA?

hello,

your screen capture look like from a ZHWG11LM not DGNWG02LM ???

dont understand…

Are you under Android or IOS?

I have the V3 aka DGNWG02LM


And I’m on a Xiaomi mi max 2 Android 9 I guess

As If said was on HA making the conf of the first gateways, taking the data from the old version of the app and its works and After un update I get the new interface


I now I Can’t get the token to add the second gateway