Mi(Xiaomi) Smart home bindings?

(Thomas Binder) #590

If it’s a Linux System: iw wlan0 get power_save, it should then return if it’s on or off (If your Wifi is wlan0)

[14:23:43] openhabian@openHAB2:~$ iw wlan0 get power_save
Power save: off

to disable it, type sudo iw wlan0 set power_save off - but as that’s only temporarily until the next reboot, you should make it permanent. I didn’t found out how to do this in raspbian stretch (as you shouldn’t touch /etc/network/interfaces), so I just added the iw wlan0 set power_save OFF to my /etc/rc.local.

(Patrick Boch) #591

Hi everyone

I’ll jump onto this topic, as there seem to be several problems with the mi home binding after upgrading to 2.2.

I have an interesting problem as well: I have a few window/door sensors from xiaomi and a motion sensor.
Ever since upgrading to 2.2 the following happens:

  • all sensors (including motion sensor) show up as status “online” in Paper UI
  • same for the gateway (interestingly, two gateways show up as things (“XIaomi Gateway” and “Xiaomi Smart Home Gateway”), although physically I only have one (but that was always the case, even before upgrading to 2.2)
  • If I trigger one of the sensors, it shows up in the Mi Home app as an event (i.e. open/close for door/window and movement detected for the motion sensor)
  • now it gets interestiing: In OH2, the motion sensor and the rule(s) associated with it work fine.
  • However, the door/window sensor status does not update. There is no event in the event log, and no other log entries in OpenHAB log, even though I set the log level to debug (log:set DEBUG org.eclipse.binding.mihome)

Gateway is on the latest version 1.4.1_151.0143

Anyone have any ideas what this could be (or how I even find out more information)

(Thomas Binder) #592

Hi Patrick,

do you configure everything (including items) with PaperUI? if not, please post your Things-file and/or your items-file
But please post your rules.

and lastly: your Pi is on LAN or on Wifi?

(Patrick Boch) #593

I configure items manually, not things. The excerpt from the items file dealing with the sensors looks like this:

Contact TR_Sensor “Terrasse rechts” (Sensor_EG) { channel=“mihome:sensor_magnet:158d0001586a64:isOpen” }
Contact ET_Sensor “Esszimmertür” (Sensor_EG) { channel=“mihome:sensor_magnet:158d0001586c18:isOpen” }
Contact WC_Sensor “WC Fenster” (Sensor_EG) { channel=“mihome:sensor_magnet:158d0001583ccc:isOpen” }
Contact AZ_Sensor “Buerofenster” (Sensor_KG) { channel=“mihome:sensor_magnet:158d0001586ae3:isOpen” }
Contact TL_Sensor “Terrasse links” (Sensor_EG) { channel=“mihome:sensor_magnet:158d0001584559:isOpen” }
Contact KF_Sensor “Küchenfenster” (Sensor_EG) { channel=“mihome:sensor_magnet:158d00015840a0:isOpen” }
Contact HT_Sensor “Haustür” (Sensor_EG) { channel=“mihome:sensor_magnet:158d0001583622:isOpen” }

String TR_Sensor “Terrasse rechts [MAP(de.map):%s]” (Sensor_EG) { channel=“mihome:sensor_magnet:158d0001586a64:isOpen” }
String ET_Sensor “Esszimmertür [MAP(de.map):%s]” (Sensor_EG) { channel=“mihome:sensor_magnet:158d0001586c18:isOpen” }
String WC_Sensor “WC Fenster [MAP(de.map):%s]” (Sensor_EG) { channel=“mihome:sensor_magnet:158d0001583ccc:isOpen” }
String AZ_Sensor “Bürofenster [MAP(de.map):%s]” (Sensor_KG) { channel=“mihome:sensor_magnet:158d0001586ae3:isOpen” }
String TL_Sensor “Terrasse links [MAP(de.map):%s]” (Sensor_EG) { channel=“mihome:sensor_magnet:158d0001584559:isOpen” }
String KF_Sensor “Küchenfenster [MAP(de.map):%s]” (Sensor_EG) { channel=“mihome:sensor_magnet:158d00015840a0:isOpen” }
String HT_Sensor “Haustür [MAP(de.map):%s]” (Sensor_EG) { channel=“mihome:sensor_magnet: 158d0001583622:isOpen” }

and one of the corresponding rules:

rule "Alarmanlage AN Haustür"
Item HT_Sensor changed from CLOSED to OPEN

if (Alarmanlage.state == ON) {

    sendNotification ("xxx@xxx.de","Haustür steht offen")

However, I don’t think it’s the rules - the status of the sensors doesn’t update in the UI, either.

Lastly - I am not using a Pi (used to, but due to SD card issues switched), but an old netbook, which is connected to the network via LAN.

(Patrick Boch) #594

Update: it seemed the binding „just“ needed some configuration. Although before I de-installed and re-installed to no effect.
What I did now: I’ve added a channel I haven’t used previously (lastOpened) with just one item and all of a sudden, all sensors work again!

I read in another post (not sure what it was) that they needed to edit and save the rules (even though nothing changed) for them to work again - maybe this is similar here?

In any case, everything works - for now.

(Thomas Binder) #595

great to hear, it worked out. It seems, sometimes you need to touch configurations. Please keep in mind (all readers), that sometimes you need to clear cache and tmp, especially after an upgrad, as it seems. i think this has the same effect as touching the config…

(Tom M ) #596

Hi all,
i‘m relativ new in the world of smart home and openhab but i installed a few sensors from the Xiaomi ecosystem and Yeelight. Both are works like a charme with openhab. Like Bulbs, Temp., plugs, and so on. Great work!

As a christmas gift i bought the „Xiaomi Bedside Lamp 2“ with Wifi and Bluetooth.

Is there an possibility to add this lamp in openhab ?
I tried the MiHome Binding 2.2 and the Yeelight Binding 2.2.

(Daniel Linder) #597

I bought these for my daughters for x mas. You will get basic functionality (on/off & brightness) using the “Xiaomi Mi IO Binding”. You have to extract a token from the mi home app. Check the binding thread for more info.

(Patrick Boch) #598

OK, seems like I was a bit premature in talking about success.

Shortly after the sensors “went off”, i.e. they went to status undefined and any changes are not shown in OH2 (in the MiHome app they do show the changes).

I tried everything I can think of, even, finally, deleting and re-installing OH2 more or less from scratch.

Any other ideas what to do? I have a trace file this time:

2017-12-30 23:41:33.050 [TRACE] [g.mihome.handler.XiaomiBridgeHandler] - Received message {“cmd”:“report”,“model”:“magnet”,“sid”:“158d0001586c18”,“short_id”:36159,“data”:"{“status”:“open”}"}
2017-12-30 23:41:33.051 [TRACE] [g.mihome.handler.XiaomiBridgeHandler] - Updated “last time seen” for device 158d0001586c18
2017-12-30 23:41:33.053 [DEBUG] [home.handler.XiaomiDeviceBaseHandler] - Item got update: {“cmd”:“report”,“model”:“magnet”,“sid”:“158d0001586c18”,“short_id”:36159,“data”:"{“status”:“open”}"}
2017-12-30 23:41:33.061 [DEBUG] [ler.XiaomiSensorBaseHandlerWithTimer] - Setting timer to 300s
2017-12-30 23:41:33.064 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners
2017-12-30 23:41:33.065 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-695,5,main] waiting for data on port 9898
2017-12-30 23:41:33.785 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from on Port 9898
2017-12-30 23:41:33.786 [TRACE] [g.mihome.handler.XiaomiBridgeHandler] - Received message {“cmd”:“heartbeat”,“model”:“gateway”,“sid”:“286c0788ae6c”,“short_id”:“0”,“token”:“cCz0ZQKFGSc7DdcJ”,“data”:"{“ip”:“”}"}
2017-12-30 23:41:33.787 [TRACE] [g.mihome.handler.XiaomiBridgeHandler] - Updated “last time seen” for device 286c0788ae6c
2017-12-30 23:41:33.789 [DEBUG] [home.handler.XiaomiDeviceBaseHandler] - Item got update: {“cmd”:“heartbeat”,“model”:“gateway”,“sid”:“286c0788ae6c”,“short_id”:“0”,“token”:“cCz0ZQKFGSc7DdcJ”,“data”:"{“ip”:“”}"}
2017-12-30 23:41:33.791 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners
2017-12-30 23:41:33.792 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-695,5,main] waiting for data on port 9898
2017-12-30 23:41:34.505 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from on Port 9898
2017-12-30 23:41:34.506 [TRACE] [g.mihome.handler.XiaomiBridgeHandler] - Received message {“cmd”:“report”,“model”:“magnet”,“sid”:“158d0001586c18”,“short_id”:36159,“data”:"{“status”:“close”}"}
2017-12-30 23:41:34.507 [TRACE] [g.mihome.handler.XiaomiBridgeHandler] - Updated “last time seen” for device 158d0001586c18
2017-12-30 23:41:34.509 [DEBUG] [home.handler.XiaomiDeviceBaseHandler] - Item got update: {“cmd”:“report”,“model”:“magnet”,“sid”:“158d0001586c18”,“short_id”:36159,“data”:"{“status”:“close”}"}
2017-12-30 23:41:34.520 [DEBUG] [ler.XiaomiSensorBaseHandlerWithTimer] - Cancelled running timer
2017-12-30 23:41:34.521 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners
2017-12-30 23:41:34.522 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-695,5,main] waiting for data on port 9898
2017-12-30 23:41:35.735 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from on Port 9898

This is the part where I open and close the door. The status in OpenHab, however, remains undefined, although data seems to flow.

(Tom M ) #599

Thank you. It works now.
But only (on/off & brightness). i´m looking forward for new functions.

(Gary Lau) #600

My binding is crashed by the curtain report -1 again these days.
Item got update: {“cmd”:“read_ack”,“model”:“curtain”,“sid”:“158d00012d69e7”,“short_id”:56211,“data”:"{“voltage”:3600,“curtain_level”:"-1"}"}


Line 105
void parseDefault(JsonObject data) {
if (data.has(CURTAIN_LEVEL)) {
int level = data.get(CURTAIN_LEVEL).getAsInt();
if (level >= 0 | level <= 100) {
updateState(CHANNEL_CURTAIN_CONTROL, new PercentType(level));

i think if (level >= 0 | level <= 100) {
has to be changed to
if (level >= 0 && level <= 100) {
or add
if (level < 0) level=0;
if (level >100) level=100;

to avoid the value out of range?


(Patrick Boch) #601


no change for me either - I’ve also tried to use the channel “openWindowAlarm”, to see whether it was maybe my items file which was incorrect. The channel, however, also did not report anything back to OH2.

It looks like the error (i.e. mihome binding not reporting anything back to OH2 although everything seems fine) is more common here, if I read the posts correctly.

If anyone solved this, can you let us know how? Or is it worthwhile to open an issue for the binding?

(Javi) #602

Any ideas about this problem?

(Ondrej Pecta) #603

The fact is v1 version is no longer supported.
I suggest moving to v2 binding, it works pretty well and I’ve moved to v2 version too.

Anyway the plug voltage reading was fixed several weeks ago - please see the latest snapshot, I’ve just released

(Patrick Boch) #604

V1 vs V2 was not the problem for me - I was always using OH2 and the latest version of the binding.

But I have the problem solved anyway: apparently my String items were the problem. Not only did they not update basic UI, apparently they also prevented the rules from triggering.

I commented out the string items and now everything works. (Could also be something to do with my transformation map, not sure)

So my question, ideally to someone involved in development of the binding: did something change with OH 2.2 for those string items? Either in the binding or in OH 2.2 itself?

Would be happy for any information which could help me pinpoint the issue.

(Javi) #605

Great !!! Rock you!!!

Works perfectly!!

I’ll try to new version move.


(Ward) #606

I noticed that one of my sensors (water sensor to be specefic) is shoning ‘offline’ in the Mi app. I also tested it, and it is realy offline.
Does someone knows a solution so OpenHAB reports this? I have a rule which checks my battery levels, but not if they are offline.

(rb) #607

You can fire a rule when a thing becomes offline:

I also use an expire binding on my battery level, so they are set to 0% if no update within XX hours. I am still experimenting how many hours are an acceptable period to wait for a a battery update, but at least for motion sensors it seems to be around 24h.

(Thomas Binder) #608

If you set the value to “UNDEF” within the expire-definition of your item, you can distinguish between a “real 0%”-battery and a UNDEF one (meaning your sensor went offline).

(Sergey M) #609

thanks, updated, everything is fine!

Did you manage to use it?