Z2M - Xiaomi Cube Controller

One quick question. How can I identify which face of de cube is up? Is not possible to use the last face which is up as 0 face? Like the original cube does with Xiaomi app.

Thanks!

I have the same issue, did you find a resolution?

I just go my cube and connected to zigbee2mqtt.

MQTT Explorer shows correct at first then publishs again and then shows null on everything…

{"action":"flip90","action_angle":null,"action_from_side":3,"action_side":5,"action_to_side":5,"battery":38,"linkquality":57,"side":5,"voltage":2875}

{"action":"","action_angle":null,"action_from_side":null,"action_side":null,"action_to_side":null,"battery":38,"linkquality":57,"side":5,"voltage":2875}

I ended up using Node Red as this was correctly reading the MQTT messages. I’ve just rechecked as there have been a few updates of Home Assistant since I originally tried and it looks like the sensors are all working as they should now. @Billy_Freitag the message does just “flash” as the cube is operated the goes back to reporting null. If you trigger on the action going from null to something is should work.

When I get a chance, I’ll investigate automations with the cube again in Home Assistant and retire the Node Red ones.

1 Like

Can you please share your node-red flow? That’s the implementation I would prefer. Thank you.

I think this is the one I used:
https://gist.github.com/iAbadia/901594084e941ebe88a14e393ca32a88

1 Like

I tried the original blueprint v1.2 for the first time with my new sensors, it doesnt work. Error is always:

Test multiple conditions using "and"
Stopped because a condition failed at January 14, 2022, 22:16:26 (runtime: 0.00 seconds)

Result:
result: false
conditions/0


condition: and
conditions:
  - condition: template
    value_template: >-
      {{ trigger.from_state.attributes.action !=
      trigger.to_state.attributes.action }} 
  - condition: template
    value_template: >-
      {{ trigger.to_state.attributes.action in ('rotate_right', 'rotate_left',
      'flip90', 'flip180', 'slide', 'tap', 'shake', 'fall') }}

No matter how simple the setup is, it usually ends in this error. Especially after using some time, it seems to do with this part, i will try to quote it out:

  • condition: template
    value_template: >-
    {{ trigger.from_state.attributes.action !=
    trigger.to_state.attributes.action }}

The one from @golles is working but only for shaking its reliable, other actions sometimes unreliable for some reason. I found that’s because its firing any possible action with the cube, even if you did not configure an action for that specific flip/round/tap etc. When firing an action not configured its not accessible for the right action if you hit that one straight after.

Edit: possible it is due that side 3 is actually the top side with the Aqara logo.

I am currently having the same issue as @Inferi0r with the 1.2 version of the blueprint. No matter which actions I setup, I get “result:false” on the conditions step on my debug. I have validated through mqtt explorer and the state messages in developer tools that the sides are correct. I can see all the state changes happening, and the side 0 is the first one I’ve been attempting to configure but without any success.

Executed: January 17, 2022, 6:11:03 PM
Result:
result: false
conditions/0


condition: and
conditions:
  - condition: template
    value_template: >-
      {{ trigger.from_state.attributes.action !=
      trigger.to_state.attributes.action }} 
  - condition: template
    value_template: >-
      {{ trigger.to_state.attributes.action in ('rotate_right', 'rotate_left',
      'flip90', 'flip180', 'slide', 'tap', 'shake', 'fall') }}

This is the topic and information I see in MQTT for the messages when I rotate right on side 0

{
  "action": "rotate_right",
  "action_angle": 70.46,
  "action_from_side": null,
  "action_side": null,
  "action_to_side": null,
  "angle": -60.48,
  "battery": 100,
  "linkquality": 51,
  "side": 0,
  "voltage": 3005
}

Full automation configuration as well

mode: queued
max: 5
max_exceeded: silent
trigger:
  - platform: state
    entity_id: sensor.aqara_cube_action
condition:
  - condition: and
    conditions:
      - condition: template
        value_template: >-
          {{ trigger.from_state.attributes.action !=
          trigger.to_state.attributes.action }} 
      - condition: template
        value_template: >-
          {{ trigger.to_state.attributes.action in ('rotate_right',
          'rotate_left', 'flip90', 'flip180', 'slide', 'tap', 'shake', 'fall')
          }}
action:
  - variables:
      event: '{{ trigger.to_state.attributes.action }}'
      sub_event: '{{ trigger.to_state.attributes.side }}'
  - service: system_log.write
    data:
      level: info
      message: 'Blueprint Script: {{ event }} {{ sub_event }}'
  - choose:
      - conditions: '{{ event == "slide" }}'
        sequence:
          - choose:
              - conditions: '{{ sub_event == 0 }}'
                sequence: []
              - conditions: '{{ sub_event == 1 }}'
                sequence: []
              - conditions: '{{ sub_event == 2 }}'
                sequence: []
              - conditions: '{{ sub_event == 3 }}'
                sequence: []
              - conditions: '{{ sub_event == 4 }}'
                sequence: []
              - conditions: '{{ sub_event == 5 }}'
                sequence: []
      - conditions: '{{ event == "tap" }}'
        sequence:
          - choose:
              - conditions: '{{ sub_event == 0 }}'
                sequence: []
              - conditions: '{{ sub_event == 1 }}'
                sequence: []
              - conditions: '{{ sub_event == 2 }}'
                sequence: []
              - conditions: '{{ sub_event == 3 }}'
                sequence: []
              - conditions: '{{ sub_event == 4 }}'
                sequence: []
              - conditions: '{{ sub_event == 5 }}'
                sequence: []
      - conditions: '{{ event == "flip90" }}'
        sequence:
          - choose:
              - conditions: '{{ sub_event == 0 }}'
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.office_closet_light
                    data:
                      brightness: 128
              - conditions: '{{ sub_event == 1 }}'
                sequence: []
              - conditions: '{{ sub_event == 2 }}'
                sequence: []
              - conditions: '{{ sub_event == 3 }}'
                sequence: []
              - conditions: '{{ sub_event == 4 }}'
                sequence: []
              - conditions: '{{ sub_event == 5 }}'
                sequence: []
      - conditions: '{{ event == "flip180" }}'
        sequence:
          - choose:
              - conditions: '{{ sub_event == 0 }}'
                sequence:
                  - service: light.turn_on
                    data:
                      brightness: 128
                    target:
                      entity_id: light.office_closet_light
              - conditions: '{{ sub_event == 1 }}'
                sequence: []
              - conditions: '{{ sub_event == 2 }}'
                sequence: []
              - conditions: '{{ sub_event == 3 }}'
                sequence: []
              - conditions: '{{ sub_event == 4 }}'
                sequence: []
              - conditions: '{{ sub_event == 5 }}'
                sequence: []
      - conditions: '{{ event == "rotate_right" }}'
        sequence:
          - choose:
              - conditions: '{{ sub_event == 0 }}'
                sequence:
                  - service: light.turn_on
                    target:
                      device_id: 1613c888150941e2bb2cddf362a294f8
                    data:
                      brightness_step: 10
              - conditions: '{{ sub_event == 1 }}'
                sequence: []
              - conditions: '{{ sub_event == 2 }}'
                sequence: []
              - conditions: '{{ sub_event == 3 }}'
                sequence: []
              - conditions: '{{ sub_event == 4 }}'
                sequence: []
              - conditions: '{{ sub_event == 5 }}'
                sequence: []
      - conditions: '{{ event == "rotate_left" }}'
        sequence:
          - choose:
              - conditions: '{{ sub_event == 0 }}'
                sequence:
                  - service: light.turn_on
                    target:
                      device_id: 1613c888150941e2bb2cddf362a294f8
                    data:
                      brightness_step_pct: -10
              - conditions: '{{ sub_event == 1 }}'
                sequence: []
              - conditions: '{{ sub_event == 2 }}'
                sequence: []
              - conditions: '{{ sub_event == 3 }}'
                sequence: []
              - conditions: '{{ sub_event == 4 }}'
                sequence: []
              - conditions: '{{ sub_event == 5 }}'
                sequence: []
      - conditions: '{{ event == "shake" }}'
        sequence: []
      - conditions: '{{ event == "fall" }}'
        sequence: []
id: '1642466419586'
alias: Aqara Magic Cube (Z2M)
description: ''

Any idea what’s going wrong here? I’ve tried side 3 for some actions as well, same results.

Is it possible to remove this sub condition

- conditions: '{{ sub_event == 0 }}'
                sequence: []

I don’t want to add all scenarios for each side.
For me enaught just to rotate in any side.

Im trying to configure blueprint, unfortunately in GUI i dont see device (magic_cube).
Im using Z2m with conbee II and i have aqara magic cube on the list, working properly.

Any idea?

Did you ever figure this out? I have the same issue.

This would be a lot easier for your users to import and keep track of if you add an import link…
Simply fill this in and then add the markdown code to the original message…

Like this:

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Looks like this in Markdown…

[![Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.](https://my.home-assistant.io/badges/blueprint_import.svg)](https://my.home-assistant.io/redirect/blueprint_import/?blueprint_url=https%3A%2F%2Fcommunity.home-assistant.io%2Ft%2Fz2m-xiaomi-cube-controller%2F263006)

As far as the Blueprint itself goes, it’s awesome and works perfectly.
You may want to add in the initial message ( or better yet the Description of ‘sensor to use’ inside the blueprint ) what sensor to use to get the is to work. I see people seem to be confused because all you need exported to HA to make this work is the sensor.##Device_Name##_action sensor and that is what you put in for the controller to use question. This may seem obvious, but not for everyone. The rest of the sensors can be hidden unless you want to watch battery or signal from diagnostics.

Thanks for the great code!!

What about lowering the brightness?
Is it as simple as adding a negative sign in the template?

UPDATE…
I figured this out and put the new code in my ‘forked’ version of this blueprint.

CW is a positive angle and CCW is a negative angle, so don’t futz with the sign…

Thanks for the idea.

Thanks for this bud, works flawless for me and love that I can change scenes using the rotate clockwise and counter clockwise

I see a couple of other changes that I think should be made.
I believe I’m going to ‘fork’ off of this and start another version. The logging should not be on all the time, and I have a better way to display the last action to a sensor instead, so that you can troubleshoot and generate the actions easier.
That along with some of the descriptions I think a few tweaks like that would make this a lot better.
The basic code is sound and doesn’t need a thing.

Community link for my forked version of this blueprint:

source_url from GitHub: https://github.com/SirGoodenough/HA_Blueprints/blob/master/Automations/Zigbee2MQTT%20-%20Xiaomi%20Cube%20Controller.yaml
Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Event Sensor in Action:

Sample Script Generation Screen

1 Like

Great Blueprint, I especially like the respect for which face is up functionality. Unfortunately I’m a Deconz user. Is this Blueprint coming for Deconz too?

I am also getting these issues. I see that if I change all of the trigger.to_state.attributes.action to trigger.to_state.state then shake will work, but the flip90’s won’t as the sub_event is never populated.

I wonder if something changed with how the action entities are set/updated?

Looks like that states are no longer in the main action’s attributes. I’m running HA 2022.3.1, and Zigbee2MQTT 20211217. Maybe something changed in an update?

EDIT:

On further testing, it seems I can get it to work with the blueprint as-is IF I enable “Home Assistant legacy entity attributes” & “Home Assistant legacy triggers”.

1 Like

Did you ever get it working without setting homeassistant: false in configuration (which caused problems when HAOS is restarted)

If I have is set to true, I just keep getting flashes, and ’ ’ as the final action payload in HA, and I can’t seem to catch the first payload.

Thanks! You’ve saved me a big headache - when after few hours I was unable to get the cube working.

1 Like

Hi,
I’m looking for sort of a “reality check” on what I’m trying to do with my cube. I would like to be somehow able to detect the direction of 1side flip.

Basically what I was trying to do before getting stuck in the “well how the hell would that work” phase is to make the cube work as arrow keys. I already use it for many media controls when watching kodi and was thinking if I could just flip the cube left/right/up/down (where “top” would be the face which was on top at the time of 1st flip).

Would something like this be possible in any (however elaborate) way?

If you pick a starting point, you know where it is. on that starting side draw an arrow up so you know how to position it. Then each flip is from that side to one of the other 4 sides. The cube will tell you the from and the to.
Don’t know if this blueprint will do it or not, but mine would.