i am also using the multifunction gateway ( version 1.4.1_155.0143) from Xiaomi together with openhab2, Xiaomi binding 2.2 .
Everything works good. I want to use the gateway’s light as night light wirh Aqara Human body sensor in a rule. This works also but not always. I can see in the log that the variable for gateway brightness is changing, but nothing is happening on the gateway. From basicUI (slider) everything works as expected, only from rules seems not to work properly.
Hi
How close is your gateway to your Wifi router (or however it is on the wifi network). I have found the most common cause of my Gateway lights not responding via openHAB is when the Gateway is at the edge of the range of wifi coverage and sometimes loses connection during the rule’s execution.
Can you post the rule you have?
below you can find the details.
What is also strange is that when i’m changing the dimmer from BasicUI, the things are happening with gateway as expected. After that the rule is working very good, but only first time.
If I want to make the rule work, I have to change the brightness dimmer from UI again.
It seems to me that the UI is setting the items correct and something is not happening ok in the rule.
rule "Corridor_Presence"
when
Item MotionSensor_Status_Corridor changed
then
if (MotionSensor_Status_Corridor.state == ON) {
Gateway_Brightness.sendCommand(5)
}
else {
Gateway_Brightness.sendCommand(OFF)
}
end
Switch MotionSensor_Status_Corridor "MotionSensor Status" <motion> (GF_Corridor) { channel="mihome:sensor_motion_aq2:<ID>:motion" }
Dimmer Gateway_Brightness "Gateway Illumination" (GF_Corridor) { channel="mihome:gateway:<ID>:brightness" }
Hmm.
I assume you have the off-timer on the motion sensor configured to turn it off again? How long do you have that timer set as?
The rule seems correct.
Something that can maybe help you is putting logInfo lines on each of the two cases to see which one is triggering in the log.
You mention it shows the brightness change in your logs though, so I suppose an extra log isn’t necessary. Something you can maybe try is to use ON instead of 5. Then set the brightness beforehand to 5 using the UI or APP then turning it off with an OFF command (or using the app).
Also check whether the Motion sensor’s OFF and ON updates is received in the correct time using the log. It could be that the motion sensor turns off very quickly, and a network delay means it doesn’t turn on at all.
Effectively you’d have:
- Motion Sensor changed to ON
- Gateway_Brightness Received command ON (or 5)
- Gateway_Brightness changed to ON (or 5)
— Some time passes (based on the off-timer of the motion sensor) - Motion Sensor changed to OFF
- Gateway_Brightness Received command OFF
- Gateway_Brightness changed to OFF
thanks for the fast reply. I think that the ON instead of 5 is a very good idea. The motion sensor has 60s timeout. If the light would be very fast turning from on to off I should have seen it in the log files.
I will try with ON
It seems that the solution for my problem was to use the ON instead of value. Perhaps it should be somewhere documented.
hey @radu022003, try
rule "Corridor_Presence"
when
Item MotionSensor_Status_Corridor changed
then
if (MotionSensor_Status_Corridor.state == ON) {
Gateway_Brightness.sendCommand(new PercentType(5))
}
else {
Gateway_Brightness.sendCommand(OFF)
}
end
like suggested here
![]()
@dimalo a big request to you, help me understand how to use the events of pushing the buttons of wire switches, I described the problem here. The log records the pressing of buttons, so the event can be caught. But what event or how to describe the trigger in the rule, I can not understand.
Thank you!
@Olymp:
@SkyyStorm was mainly right, the channel does not trigger an event like the battery powered ones. It’s a switch - the code has a little flaw in it:
for this item:
// Xiaomi Aqara Mains Powered Wall Switch 1
Switch AqaraWallSwitch <switch> { channel="mihome:ctrl_neutral1:<ID>:ch1" }
you would write
rule "Xiaomi Aqara Mains Powered Wall Switch 1"
when
Item AqaraWallSwitch changed
then
if (AqaraWallSwitch.state == ON)
{
logInfo("INFO","Switch On")
}
else
{
logInfo("INFO","Switch Off")
}
end
no, it does not work
Your results lead me to solve an issue I was having with my gateway!
I was getting datagrams, etc. Everything looked great, but it turns out in my .items I had entered the wrong SID by 1 number, and your discussion about the identifier ID saved the day!
Thanks again!
openHAB 2.4.0 Build #1326
Hi!
When changing the state of the switch, the event is triggered 3 times instead of one, pay attention to the log:
2018-08-10 19:33:09.806 [DEBUG] [home.handler.XiaomiDeviceBaseHandler] - Device 158d0001f2766d on channel mihome:ctrl_ln1:158d0001f2766d:ch1 received command OFF
2018-08-10 19:33:09.811 [DEBUG] [g.mihome.handler.XiaomiBridgeHandler] - Send to bridge mihome:bridge:286c078921f5: {"cmd": "write", "sid": "158d0001f2766d", "data": "{\"channel_0\": \"off\", \"key\": \"E22EACEF4CEC8EC343F4E98C5B1275EC"}"}
2018-08-10 19:33:09.818 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.215.140:9898 on Port 9898
2018-08-10 19:33:09.819 [DEBUG] [g.mihome.handler.XiaomiBridgeHandler] - Device 158d0001f2766d honored write request
2018-08-10 19:33:09.820 [DEBUG] [home.handler.XiaomiDeviceBaseHandler] - Item got update: {"cmd":"write_ack","model":"ctrl_ln1.aq1","sid":"158d0001f2766d","short_id":21497,"data":"{\"voltage\":3600,\"channel_0\":\"on\"}"}
2018-08-10 19:33:09.919 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.215.140:4321 on Port 9898
2018-08-10 19:33:09.920 [DEBUG] [home.handler.XiaomiDeviceBaseHandler] - Item got update: {"cmd":"report","model":"ctrl_ln1.aq1","sid":"158d0001f2766d","short_id":21497,"data":"{\"channel_0\":\"off\"}"}
2018-08-10 19:33:10.691 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.215.140:4321 on Port 9898
2018-08-10 19:33:10.692 [DEBUG] [home.handler.XiaomiDeviceBaseHandler] - Item got update: {"cmd":"report","model":"gateway","sid":"286c078921f5","short_id":0,"data":"{\"rgb\":0,\"illumination\":423}"}
2018-08-10 19:33:10.957 [INFO ] [.eclipse.smarthome.model.script.RULE] - <-- OFF light
2018-08-10 19:33:10.962 [INFO ] [.eclipse.smarthome.model.script.RULE] - <-- OFF light
2018-08-10 19:33:10.969 [INFO ] [.eclipse.smarthome.model.script.RULE] - <-- OFF light
2018-08-10 19:33:36.578 [DEBUG] [home.handler.XiaomiDeviceBaseHandler] - Device 158d0001f2766d on channel mihome:ctrl_ln1:158d0001f2766d:ch1 received command ON
2018-08-10 19:33:36.583 [DEBUG] [g.mihome.handler.XiaomiBridgeHandler] - Send to bridge mihome:bridge:286c078921f5: {"cmd": "write", "sid": "158d0001f2766d", "data": "{\"channel_0\": \"on\", \"key\": \"E6FF670C3C7BA6E6106A74D442E07ECA"}"}
2018-08-10 19:33:36.582 [INFO ] [.eclipse.smarthome.model.script.RULE] - <-- ON light
2018-08-10 19:33:36.623 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.215.140:9898 on Port 9898
2018-08-10 19:33:36.624 [DEBUG] [g.mihome.handler.XiaomiBridgeHandler] - Device 158d0001f2766d honored write request
2018-08-10 19:33:36.625 [DEBUG] [home.handler.XiaomiDeviceBaseHandler] - Item got update: {"cmd":"write_ack","model":"ctrl_ln1.aq1","sid":"158d0001f2766d","short_id":21497,"data":"{\"voltage\":3600,\"channel_0\":\"off\"}"}
2018-08-10 19:33:36.628 [INFO ] [.eclipse.smarthome.model.script.RULE] - <-- OFF light
2018-08-10 19:33:36.727 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.215.140:4321 on Port 9898
2018-08-10 19:33:36.735 [DEBUG] [home.handler.XiaomiDeviceBaseHandler] - Item got update: {"cmd":"report","model":"ctrl_ln1.aq1","sid":"158d0001f2766d","short_id":21497,"data":"{\"channel_0\":\"on\"}"}
2018-08-10 19:33:36.741 [INFO ] [.eclipse.smarthome.model.script.RULE] - <-- ON light
Switch room_light_switch Lights[%s]" <switch> { channel="mihome:ctrl_ln1:158d0001f2766d:ch1" }
rule "switch light room"
when
Item room_light_switch changed from OFF to ON or
Item room_light_switch changed from ON to OFF
then
if(room_light_switch.state == ON) {
logInfo("RULE","<-- ON light")
} else {
logInfo("RULE","<-- OFF light")
}
end
Am I doing something wrong?
Thank you!
UPD: This is made of paper, if you physically press the switch, then everything is ok.
there is a new real interesting xiaomi gadget (motion sensor gyroscope based)
https://www.gearbest.com/smart-home-controls/pp_009661787808.html?wid=1433363
it would be really great if you can integrate it
I am interested in too.
Also bought 2 of them. I’ll see what we can do in order to integrate these devices with the MiHome binding ![]()
So far, we’ve been using this repository to get the reference for the API.
If it’s not updated, we’ll need to reverse-engineer it somehow ![]()
Other thing is that the gateway’s firmware should allow to expose these devices to the local network.
Anyways, I’ll play around when it arrives!
Cheers
I also ordered 2 of them ![]()
The latest Aqara Cube & Switch (with Gyrometer) is also not yet integrated in openHAB.
I’ve them both, so if I can help…
hi everyone!
I have made a PR to fix your issue @Olymp. It was also reported on github…
I have also enabled the new Aqara Cube and tested it already @wars
It’s only working with the newest firmware though (something with 159)…
As soon as anybody can provide logs for new devices please open an issue in the github repo.
In the future I want to get rid of the gateway and use pure zigbee with zigbee2mqtt.
This means I will support this binding not that much anymore.
I hope there is anybody wanting to step in, so that the binding stays alive.
@kubawolanin: seems like aqara is pushing an updated doc here now, already in english so no need to translate. don’t know if the chinese version has more content…
seems like they are preparing for a new protocol version which would need a major change in the binding…
Hi Team here! Really great job! I already bought lot of Xiaomi smart stuff and also successfully bind it into OH - temperature, humidity sensors, Air Index sensor, el. plug, IR remote, door sensors, Roborock .. but this time I tried door core lock which is not integrated in OH Mi Smart binding. This lock can give information which from registered keys is used to unlock, reminds for not pulled out key after unlocking and most important - can give alert when there is illegal try for unlocking. Integration in OH can give chance to disarm alarm system with unlocking the door with registered key and so on. It works through Gateway. I’ve been able to extract token from iOS sqlite database from MI Home App. I can support (with a little help) if someone capable of integration of it wills to do it (can try to capture its communication to the gateway with Wireshark etc). Please excuse me if this is not the right way for requesting it - still not very aware hot he community works here.
Here are few pictures of this Wima Door Smart Lock.
Thanks everybody for their time and efforts making this binding better and better!


