Mi(Xiaomi) Smart home bindings?

BTW, you could setup timer with Sunrise scene to make it happen within Yeelight app.
Any problem, feel free to let me know!

(Xiaomi MiHome) Aqara Smart Home API https://github.com/louisZL/lumi-gateway-local-api
I am not familiar with JAVA, but wish someone can implement this to openhab.

Looking at the files inside this repo I wish I knew Chinese rather than JAVA :wink:


I will try to translate them into english, maybe a bit better than gtranslate.


I made a rough translation here: https://github.com/illxi/lumi-gateway-local-api I hope it helps.


The following code reads values from the xiaomi gateway in a very simple way, the returned String is a JSON String.
Probably that helps to create a openhab binding

import java.io.ByteArrayInputStream;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.nio.charset.StandardCharsets;

public class XiaomiTest {

	public static void main(String[] args) {
		XiaomiTest test = new XiaomiTest();
	public void testConnection(){
		try (MulticastSocket socket =  new MulticastSocket(9898); ){
			byte[] b = new byte[1024];
			DatagramPacket dgram = new DatagramPacket(b, b.length);
			while(true) {
			  ByteArrayInputStream in = new ByteArrayInputStream(dgram.getData(), 0, dgram.getLength());
			  int n = in.available();
			  byte[] bytes = new byte[n];
			  in.read(bytes, 0, n);
			  String s = new String(bytes, StandardCharsets.UTF_8); 
		} catch (Exception e) {


I made a python script by modifing jon1012/mihome library. https://github.com/illxi/mihome, it will read status from xiaomi gateway and publish all device status to mqtt server. and It can also turn aqara switches and plug on/off. I will put on more description when I have time.


I made simple OH1 binding - just reading states / events of aqara sub devices. You can check it here: https://github.com/octa22/org.openhab.binding.xiaomigateway
Unfortunatelly there is no controlling of switches (writing ON/OFF) at this time - I have no aqara device supporting write to test it even it is almost prepared. If someone interested we can add/test this feature too…


Just to clarify this should work to read the events from the xaiomi window/ door sensor and the PIR sensor?
The ones from this kit?

Exactly, temp/humidity and door sensors tested, button too. Motion sensor should work too. Enjoy :slight_smile:


Dude, this is amazing! Can’t wait to test it!
I need to buy the proper devices, though.

I would recommend you considering implementing openHAB2 Binding - the community is leaning towards it and it offers lots of goodness, like Inbox, Discovery and Things :slight_smile:

@Ondrej_Pecta could you confirm this binding will work with Xiaomi Gateway 2 ? Seems there’s no much difference between them other that ability to turn on online radio. So technically it’s a speaker?
If so, I’d love to see the Xiaomi Gateway as a Audio Sink for openHAB2 some day :slight_smile:

Thank you Ondrej for your work!

Yes, I do confirm - this is exactly the same gateway I am using right now, so you do not have to be afraid of compatibility and yes it’s technically a speaker with LED strip. Unfortunately the API (gateway firmware) doesn’t expose locally most of the gateways features at this time (no color control, no scenes, radio, volume…) - or at least it has not been documented yet.

Just as a quick info. I am working on implementing the OpenHAB2 binding for the Xiaomi Gateway :).
I already have a working version locally (testing with Xiaomi Gatway 2) that supports the temperature and humidity sensor. Other sensors now should not be much work anymore. Still need to clean up some code. Then I will push it upstream and share here. I hope to get a first push out today. I will try to get it into the offical openhab repository as well.

Having Audio Sink for openHAB2 work would be great. I will post without it first and see if we can actually get this to work afterwards. I wonder how the audio works on the gateway. You can play chinese music streams. Anyone already figured out how playing audio on the gateway works?


Do you know whether you can attach the Flora plant sensors to the gateway too? I am setting up a binding for the Flora (whenever BLE support gets merged into ESH), but if “native” support through the gateway is also possible, it might be better to wait for your solution.

The Floar plant sensor uses Bluetooth 4.1 BLE. The Gateway uses Zigbee. So they can not get coupled. This would require a separate binding that bases on Bluetooth. The new raspberry pis already have bluetooth. So this could be fairly easy. But would require somebody to write the code. I heard from someone that the protocol has already been found out. You might find it on some other sites.

But maybe it might be smart to include it into the same binding? So that in the end ALL Mi Smart Home components can be used with this binding. It would then not go through the gateway, but use bluetooth. That might work and would be user friendly I think. But I have no idea yet how to use the bluetooth in a binding.
So depending on how that all works, it would make sense to split them into separate bindings or have them in one. For now I hope that in the future it can be included in the same binding. So I will call the binding mihome.

Here is the current version of the binding. Still work in progress. When done (or in a state that I think is acceptable), I will try to find out how to get it into the official repository so it can be installed from within openhab2.


O.k., so my efforts will be not in wasted time then. I will continue to convert the python based code that was written elsewhere to whatever BLE API will end up merged into ESH core.

1 Like

I don’t have a Xiaomi Gateway (i have OH and ISY), but I do have a Mi Air. Will this binding work with Mi Air? I think similar to Nest, the appliance connects back to some Xiaomi cloud gateway for control via smartphone app.