Xiaomi Gateway Integration

I’ve updated the binary sensor py and restarted HA, now the sensor is not showing up anymore …
Any ideas?

What’s in the log

How do you change hub led color? Is it through mobile app or through HA?

through mobike app for sure. Through HA not sure

Made an error getting the new file. All working now and the motion sensor is showing up in HomeKit! Wohuuu!

Received my gateway and sensors yesterday! Got it running stand-alone now :slight_smile:
Will try to integrate with HA soon!

Some hints:
See this clear instructions for enabling developer mode on the gateway: https://www.domoticz.com/wiki/Xiaomi_Gateway_(Aqara)

But I was facing issues enabling the developer mode on the gateway by using the iOS MI Home app.
Kept getting a ‘retrieve failed’ error. The Android app seems to work fine, but I don’t have any Android device at home.

So I used a (free) Android emulator droid4x from:
https://droid4x.en.uptodown.com/windows/download

And downloaded the APK http://www.apkmirror.com/apk/xiaomi-inc/mihome/mihome-3-9-20-release/mihome-3-9-20-android-apk-download/download/

It worked without any issues!

3 Likes

See my post below:

1 Like

Seems RGB-write (set and turn on\off RGB light on gateway) works too, but little fix needed, send 0 to turn off and int value(for example: 1694440448) to turn on:

def write_to_hub(self, sid, data_key, datavalue):
    key = self._get_key()
    if type(datavalue) == int:
        datavalue_formatted = str(datavalue)
    else:
        datavalue_formatted = '"' + datavalue + '"'
    cmd = '{ "cmd":"write","sid":"' + sid + '","data":"{"' + data_key + '":' + datavalue_formatted + ',"key":"' + key + '"}}'
    return self._send_cmd(cmd, "write_ack")
3 Likes

Nice. I’m planning to add the gateway itself as a light. Should be easy

3 Likes

looking forward to test this feature.

@rave I think it’s been asked before, but whilst looking at light integration with the gateway, any chance of the Alarm feature?

Yeah. I’ll look at it at the same time

2 Likes

You’re the man.

1 Like

I have tried alarm functions some minutes ago - it doesn’t report about alarm state change (only reporting on rgb light change while arming light flashes and I think it will report flashes on alarm trigger), but we can’t turn it on\off and ask for alarm state.

P.S. No reports about radio state change too.

1 Like

Too bad. thanks for testing it

looks like i’m not the only one to have sensor stuck on “on” then. I noticed at the moment if sensors are stuck and I restart HA, they are then in the “on” state on the home card, but if I go into history, they are in the “unknown” state, until they get triggered to the on state, then it will function as normal.

Today one of the motion sensor is not aligning with the xiaomi app, HA shows it as turning on and off during the day but timestamp wise it’s all over the place. Feels like the off signal never made it to HA so HA was showing “on” and xiaomi was showing off. However this doesn’t explain why magically my sensors all went into “on” last time

it would be great to use the light sensor … an important sensor for other functions in HA, possible?

I have similar problem when having two interfaces, so I wrote a small patch that allows you to specify which interface to listen on for communication from the hub. It’s an open pull request now, so once it’s accepted give it a try by adding in your config the ip address of your WiFi

xiaomi:
  key: aaaaaaaaaaaaaaaaaa    
  interface: 192.168.xxx.yyy

i made some tests…

when the sensor trigger the output is:

{"cmd":"report","model":"motion","sid":"xxxxxx","short_id":22951,"data":"{\"status\":\"motion\"}"}

after 1 minute the sensor is avaible again for a new reading so i think must be set to off manually…

after 2 minutes without movement this is the output

{"cmd":"report","model":"motion","sid":"xxxxxx","short_id":22951,"data":"{\"no_motion\":\"120\"}"}

@rave i’ll hope this is helpful… :slight_smile:

1 Like

Having the same issue on the motion sensor, sticks at ‘on’ state.
I’m running the latest firmware version (from yesterday), never got it running on the previous version so cannot compare.

@rave is there anything I can do to help you on this one?

Edit: how do you guys sniff the network traffic? I don’t see anything relevant in WireShark.
I’m running HaSS on a Raspberry PI and sniffing from a Windows machine. Should I see the hub broadcast any status updates on sensors?

Edit2:
Patched this module to printout any messages received.
Can conform the motion sensor sends a message no_motion after 2 min:
{‘data’: ‘{“no_motion”:“120”}’, ‘cmd’: ‘report’, ‘sid’: ‘xx’, ‘model’: ‘motion’, ‘short_id’: 61771}