Xiaomi smart Cube actions

Tags: #<Tag:0x00007efec4d8fc10> #<Tag:0x00007efec4d8fb20> #<Tag:0x00007efec4d8fa58>

I’m trying to capture the actions of my Xiaomi cube (such as MOVE, FLIP90, etc.) and publish it to my MQTT with this line of code in my items file:

String MiCube_Action "Cube action" (gMiCube) {channel="mihome:sensor_cube:158d000105cd62:action", mqtt=">[mosquitto:xiaomiCube/action/state:state:*:default"}

My MQTT is up and running and I get data from my other devices. Only this one is not working. Nothing is published to xiaomiCube/action/state topic.

Did you update your Gateway to the latest firmware?
Else you could run Wireshark for a bit to see the json formatted data in the network packages from the Cube

Yes, I updated my gateway firmware. I think, there is something wrong with the item type. Is is correct ? (String). In addition, in my paper UI, the channel for action is different from the others (look at the photo). There is no type and the logo is different:

Quite strange, do you get values from those channels?

I get values from all the channels, except Cube event.

That’s weird.
I really do think that your problem doesn’t belong to the OH Binding.
Just run wireshark and see if you can detect network packages when shakeing or rotating the cube.
And you can’t see any events in the logs right?

Let me be specific. When I do any action with the Cube, the corresponding action is published to MQTT, but not on the topic that I specified ( xiaomiCube/action/state). As you know, openHAB has even bus for MQTT(look at the picture). The corresponding action (FLIP90, etc.) is published to state/publish topic.

Therefore, I am sure that there is something wrong with my items file.

The action channel is an event channel. Events cannot be linked to an item, because an item has to have a state, whereas events happen at a point in time, but do not persist (as states).

To accomplish your forwarding, you have to define a rule.
It triggers on the action from the cube and then sends the action via the MQTT Action extension to a topic.

Please read about rules here
An example for the cube is here
And MQTT Action extension docs are here

1 Like

I have the same problem with aqara cube, rotation, last action,battery can be seen, but cube event is disabled. openhab latest milestone build, up to date firmware on xiaomi hub.
Any idea anyone?

This not a “error”, this is normal for this kind of “event type” !
I have also an Cube since today, I follow the hint from dimalo , and it works immediately !!

You have to create a rule that checks what “Event” the cube is sending!
Here is my test rule for my cube:

rule "Aqara Cube event #01"
when
    Channel 'mihome:sensor_cube:YOUR-ID-NO-HERE:action' triggered
then
    var actionName = receivedEvent.getEvent()
    switch(actionName) {
        case "MOVE": {
            logInfo("diverses.rules", "MOVE")
        }
        case "ROTATE_RIGHT": {
            logInfo("test_rule.rules", "Cube #01: Roate right")
        }
        case "ROTATE_LEFT": {
            logInfo("test_rule.rules", "Cube #01: Rotate left")
        }
        case "FLIP90": {
            logInfo("test_rule.rules", "Cube #01: Flip 90")
        }
        case "FLIP180": {
            logInfo("test_rule.rules", "Cube #01: Flip 180")
        }
        case "TAP_TWICE": {
            logInfo("test_rule.rules", "Cube #01: Tap Twice")
        }
        case "SHAKE_AIR": {
            logInfo("test_rule.rules", "Cube #01: Shake Air")
        }
        case "FREE_FALL": {
            logInfo("test_rule.rules", "Cube #01: Free Fall")
        }
        case "ALERT": {
            logInfo("test_rule.rules", "Cube #01: Alert")
        }
    }
end

If you want to display the last action’s name, you can hide the channel config behind the item, it makes Cube_Action item as a dummy one, and postupdate the state via the rule itself.

Here is my example:
item:

String Cube_Action // { channel="mihome:sensor_cube:78xxxxxxxxxx:158xxxxxxxxxxxx:action" }

Rule:

rule "Aqara Cube event #01"
 when
     Channel 'mihome:sensor_cube:YOUR-ID-NO-HERE:action' triggered
 then
     var actionName = receivedEvent.getEvent()
     switch(actionName) {
         case "MOVE": {
             logInfo("diverses.rules", "MOVE")
             Cube_Action.postUpdate(actionName)
         }
 .
 .

It works fine.