Xiaomi Gateway Integration

I’m curious, too. The cube seems like a very versatile switch. In hopes that today’s Gateway update will finally make the Cube functional, I’ve started writing a couple of automations for it:
Step 1: I an input_select in HA, so that cube can do multiple functions: Livingroom Lights ; Livingroom TV ; Spare room Lights ; Spare room TV.
Step 2: First cube action is shake_air. It will move the input_select to the next option, and, hopefully, announce the new selection over Google Home.

The remaining steps will involve defining the other actions for each of my possible settings.
Livingroom lights, I’m thinking: Flip90 = toggle the main lights ; Flip180 = toggle the end table lights. I’d love for rotate to dim or brighten the lights based of direction of rotation, but I don’t think that data is being exposed yet. Move = only one light on. Double tap = all lights off, switch input_select to something else.
Livingroom TV is kind of limited until I get some way to send remote control signals (like a Harmony Hub), but for now it should be able to change apps on the Roku: Flip90 = Netflix ; Flip180 = Hulu ; Move = Youtube. Would love to control volume by rotation, but even if the cube was up to it, I can’t control volume through HA yet. Double tap will hopefully power down the TV and switch the input_select to something else.
Spare room is pretty much the same. Spare room is going to need its own cube, I think.
Thinking also that it could do well to control audio by “casting” a playlist or radio station to a speaker or group of speakers. Some actions could decide the audio source, some the volume, and some could skip tracks. But that may depend on how much Google Cast is controllable by Home Assistant.

Those are my thoughts. Curious what anyone else has in mind.

1 Like

tried all works. I still have my intermitting problems with your component

i’ve a problem tonight… the motion sensors triggers and remain to on… why?

I’m also having the issue with sensors stuck on “on”. I think pooling should be added, since it makes the system more reliable. You could add a default of about 30 seconds, for example, since that would not cause any congestion on the network, but allow it to be configurable. I’ll probably set it to 10 seconds or less :stuck_out_tongue:

Also, I think that if HA pools the device X times (5, for example) and the device does not respond (goes offline), sensors should reset to off (or to an assumed state defined on the sensor config).

By the way, lets say there’s motion for 5 minutes. Does the gateway send multiple “on” events? Or only 1?

1 Like

they may changed something in the new firmware because until today it worked without problems…

Nice! Looks like time to update the code again. I wonder if they have enabled gateway control of the led. Have to try tonight

The first one it sends is ‘motion’. If there’s still motion, it will send ‘still motion’ or something like that

The GW push 1 motion update every minute?

this is when i turn on led on GW

01:25:43.934655 IP 192.168.1.4.4321 > 224.0.0.50.9898: UDP, length 98 E..~0......{.......2..&..j.R{"cmd":"report","model":"gateway","sid":"f0b4299ab68b","short_id":0,"data":"{\"rgb\":1694498782}"}

change color

01:27:35.791452 IP 192.168.1.4.4321 > 224.0.0.50.9898: UDP, length 98 E..~0o..... .......2..&..j$Z{"cmd":"report","model":"gateway","sid":"f0b4299ab68b","short_id":0,"data":"{\"rgb\":1694438400}"}

turn it off

01:29:39.711580 IP 192.168.1.4.4321 > 224.0.0.50.9898: UDP, length 89 E..u1A.....W.......2..&..aO.{"cmd":"report","model":"gateway","sid":"f0b4299ab68b","short_id":0,"data":"{\"rgb\":0}"}

Cube is making stuff happen! Woo-hoo!

I’ve checked and the hub keeps sending the “motion” package every minute or so. Unfortunately, HA only updates on the first one. It would be nice to have it update the sensor every time it receives “motion”. This helps with some type of automations, which do not relly on the “off” state.

Great job! It really seems like the feature is enabled now. Did you see anything when you the alarm and radio is turned on?

Is it working now with multiple gateway?

Any luck to hack the radio? Would be cool to be able to use it as media player (multiroom audio:)))

And the gateway light sensor is possible to have it available in HA?

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