Mi(Xiaomi) Smart home bindings?

Hi there.
Did you add the developer key of the Gateway on Paper UI?

If you switch the item on Paper UI, and you check your Info-level logs, do you see this in your logs?

 Item *itemname* received command ON
 *itemname* changed from OFF to ON

As an added question, do you have a Switch Item defined for this channel?

Developer key was added. I have other Xiaomi Sensors and 1 Aqara Zigbee Wireless Wall Switch 2 Button (Battery Powered) working on it. Somehow the Aqara Zigbee Wireless Switches (No neutral) does not work at all.

Logs shows that the the Switch item is turned ON and OFF when triggered from the Paper or Basic UI

You can maybe try the snapshot build of the Mihome binding, 2.3?
Obvious disclaimer, the snapshot build might have unintended bugs or issues, as it gets updated constantly and isn’t an official release version.

https://openhab.jfrog.io/openhab/libs-pullrequest-local/org/openhab/binding/org.openhab.binding.mihome/2.3.0-SNAPSHOT/

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
:four_leaf_clover:

@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!

Did anyone try to make this smart lock to work under this binding?

Xiaomi Aqara Vida Smart Lock

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)


it would be really great if you can integrate it

1 Like

I am interested in too.

Cheapest on Ali:

https://www.aliexpress.com/item/update-xiaomi-mijia-Aqara-Vibration-sensor-Shock-sensor-Sleep-sensor-Valuables-alarm-Monitoring-vibration-shock-for/32913766540.html

Also bought 2 of them. I’ll see what we can do in order to integrate these devices with the MiHome binding :slight_smile:
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 :wink:
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

2 Likes