Xiaomi Gateway Integration

HA newbe here:
I’m getting the the Mi Home Kit in a couple of days and doing some research around integration with HA and homebridge etc.
I have an Ubuntu server running for my media and would like to put the home automation on there, too.
So I’d need to:

  1. install home-assistant
  2. configure the hub with the devices
  3. add the Gateway Integration discussed here
  4. add homebridge to make it all available via HomeKit/Siri

is that correct or am I missing something?

That’s correct

Thanks. Works as described (temperature-humidity, motion, zigbee-plug)!
Tomorrow my cube will arrive and I will test it too.

I hope you can integrate zigbee-plug power monitoring in future (I think it might be separate ‘query’ for gateway - like ‘give me plug-xxx power consumption’?).

1 Like

This is exciting stuff. Thanks for your work on this. I only became interested in the Xiaomi HA stuff because of the Cube, so now that support has been added, I’m going to have to put this script to work. The only other item I have is the wireless button, which I had integrated with Jonathan’s script (https://notes.jmsinfor.com/blog/post/admin/Xiaomi-Hub), but now it’s time to get my cube working and pick up a couple more Mi items.

One thing that looks like it’s still missing in the cube functionality (at least from looking at the README) is rotate. Looking at the Xiaomi app, I can see that it tracks degree of rotation and direction of rotation. I imagine that’s more difficult to capture and parse since it’s not as straightforward as double tap, flip, or shake. Still, I can see some fun interactions that could happen if that data were exposed, like a counter-clockwise spin dimming the lights, and clockwise bringing them up, or volume control, with the degree of change dependent on the amount of rotation. But, yeah, I’m sure that’s a little trickier to deal with when it’s not just “action X has happened.”

But that’s daydreaming. I’m just happy to have a way to integrate my cube into my Home assistant set-up and have do more than play Chinese radio stations. Thanks for all the work. I can’t wait to try it out.

Hi all,

I started to use my Xiaomi devices with Home Assistant and it’s very impressive!
My temperature/humidity sensors, PIR sensor, switch, door sensor are working perfectly.
There is only one thing I miss: I don’t know how to control the Gateway light (and maybe audio, but that’s not a priority issue for me) from Home Assistant automation. Is it not yet implemented, or did I miss something?

Thanks in advance :slight_smile:

Does anybody get cube working?
I am using lazcad’s component and got following response for cube read_ack:
17-01-05 14:33:37 ERROR (Thread-6) [custom_components.xiaomi] Response: {'model': '', 'short_id': 39716, 'data': '{}', 'cmd': 'read_ack', 'sid': '158d00011065e3'}

Mine have empty model and no info in ‘data’ section.

Hi, we are having the same problem in Domoticz, empty model and data http://www.domoticz.com/forum/viewtopic.php?f=17&t=11520&p=112429#p112429

I haven’t looked into it, but looks like radio customization is possible at least - http://www.domoticz.com/forum/viewtopic.php?f=17&t=11520&start=220#p112345

Yep, sorry - cant register on domoticz forum (all my ips are banned O_o), cube doesn’t send reports on action(ex: it silent while flip90, rotate, etc). Will try to use wireshark to sniff all responses on ack.

p.s. while it silent in ack’s response - it works in gateway scenarios.
p.s.s Sometimes cube sends heartbeat:
('received message:', '{"cmd":"heartbeat","model":"","sid":"158d00011065e3","short_id":39716,"data":"{}"}')

Thanks, I will watch this thread also if you can report any news!

I’ll get the cube in 2 days. So i should be able to test it then

1 Like

Nice find!

Seems like Aqara is crowdsourcing a new in-wall outlet. Looks much nicer than Xiaomi Plug. You can see it from Mi Home App. I’m getting 2 of those :grin:

Also, Xiaomi has increased the price for temp/humidity sensor in their official website. So they have increased the price of all their sensors in the last 2 months. But they’re still cheap :grin:

Is the smart plug supported?

Yep, but only zigbee version (not wifi).

A few weeks back I modified my standard alarms into smart smoke alarms with xiaomi sensors.

Here is a guide for anyone else that want a cheaper smart smoke alarm.

You can use either a door/windows sensor or a switch. The door and window sensor is preferred due to it’s tiny size and integrated battery holder. The sensor has 2 signal contacts that simulates the action of the reed switch onboard. If we close the contacts (short circuit) it means the door is closed and if we open up the contacts, it means the door is open.

The wiring is extremely simple and only require 3 extra components:
• 1x diode I used a standard 4004 type
• 1xreed relay, which I bought from here http://www.gearbest.com/relays/pp_142262.html
• 1x 1uF capacitor, I’ve used electrolytic, note negative ( - ) terminal

How it works
For this mod, the xiaomi door sensor is in a normally open state (relay opened).

  1. The activation of the smoke alarm sends a 9V PWM signal to the piezo. The frequency of the wave is very high.
  2. The 9V signal powers the relay. Since the PWM is so high, the relay closes.
  3. This then closes the contacts on the xiaomi sensor, signalling a door closed signal.

The wiring diagram is as follows

So the steps are:

  1. Wireup the 3 components per the wiring diagram. Open the smoke alarm and identify the piezo pins. Mine is a 3 pin piezo. 1 is GND, 1 is positive, 1 is osilate. We ignore the osilate pin. For me GND is the outer ring. Positive is the middle ring.
  2. Solder in the wires from the relay to piezo
  3. Open up the xiaomi smoke alarm using your finger nails/small object at the notch. Remove the circuit board out of the case. Indentify the 2 signal contacts. Solder wires onto the contacts.
  4. Complete the circuit by soldering the wires from the xiaomi sensor to the relay
  5. Secure the relay in the casing with electrical tape
  6. Secure the sensor using double sided tape

You can then use the xiaomi app / HA for your automation.

Notes:

  • Due to the PWM wave, the sensor’s state will toggle between close and open. Having a bigger sized capacitor may prevent this but since it was good enough to trigger, I wasn’t too bothered.
  • The smoke alarm will chirp on low battery, this will also set off the sensor
  • Smoke alarm I used https://www.bunnings.com.au/family-first-9v-photoelectric-smoke-alarm-with-test-button_p4210432
  • The door sensor has a bug where if you quickly close it and open it, it will still show as closed in the xiaomi app. Since when the alarm goes off, it toggles the relay, it will trigger the sensor still.
  • For the adventurous, you can remove the piezo if you hate the buzzing, you can wire in a chip that you can record a voice onto. Then you get a nice ‘nest’ style alarm that talks to you for 1/5 of the cost.

Edit more photos of the mod
,

9 Likes

did you go in
alarm setting, alarm ringtone, linkage alarm, and add the two gateway together?

Second gateway is working fine now. I have programmed it to work in NodeJS for my side project. Will move the code over to HA

My devices arrived yesterday and I was able to set them up with the gateway using the app.
However, I’m having some trouble activation the developer mode and getting the key.
I’m using the iOS app and am able to go to About, tap in the white area and open the other menu items. I get the attached error message when I try to open the Developer page, and after tapping confirm, it goes back to the about menu …
FW 1.4.1_142.0141

Any ideas?

Make sure you have mainland china set as the country + try several times. Had the same. Guess it is due to the connectivity problems to xiaomi servers.