Aqara Magic Cube + Zigbee2MQTT custom actions

Adaptation of my Hue Dimmer+Z2M custom actions Blueprint to work with Aqara Magic Cube (https://www.zigbee2mqtt.io/devices/MFKZQ01LM.html)

Supports user definable action for each of following cube triggers:
flip90
rotate_left
rotate_right
tap
slide
shake

If you wish to ignore a trigger, define its action as Wait for time to pass (delay) of 0 seconds.

github gist here & import button: Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: Zigbee2Mqtt Aqara Magic Cube control
  description: ''
  domain: automation
  input:
    cube_action:
      name: Magic Cube MQTT topic
      description: 'type in your Magic Cube MQTT topic (i.e. zigbee2mqtt/Magic Cube/action)'
      selector:
        text:
    action_flip:
      name: flip
      description: select action to run when you flip the cube
      selector:
        action:
    action_rotate_left:
      name: rotate_left
      description: select action to run when you rotate the cube counter-clockwise
      selector:
        action:
    action_rotate_right:
      name: rotate_right
      description: select action to run when you rotate clockwise
      selector:
        action:
    action_tap:
      name: tap
      description: select action to run when you double-tap the cube
      selector:
        action:
    action_slide:
      name: slide
      description: select action to run when you slide the cube
      selector:
        action:
    action_shake:
      name: shake
      description: select action to run when you shake the cube
      selector:
        action:

trigger:
  - platform: mqtt
    topic: !input cube_action
    payload: flip90
    id: flip
  - platform: mqtt
    topic: !input cube_action
    id: rotate_left
    payload: rotate_left
  - platform: mqtt
    topic: !input cube_action
    id: rotate_right
    payload: rotate_right
  - platform: mqtt
    topic: !input cube_action
    id: tap
    payload: tap
  - platform: mqtt
    topic: !input cube_action
    id: slide
    payload: slide
  - platform: mqtt
    topic: !input cube_action
    payload: shake
    id: shake

action:
  - choose:
      - conditions:
          - condition: trigger
            id: flip
        sequence:
          !input action_flip
      - conditions:
          - condition: trigger
            id: rotate_left
        sequence:
          !input action_rotate_left
      - conditions:
          - condition: trigger
            id: rotate_right
        sequence:
          !input action_rotate_right
      - conditions:
          - condition: trigger
            id: tap
        sequence:
          !input action_tap
      - conditions:
          - condition: trigger
            id: slide
        sequence:
          !input action_slide
      - conditions:
          - condition: trigger
            id: shake
        sequence:
          !input action_shake
    default: []
mode: single
3 Likes

Nice! Want to define an action based on rotate left and another on rotate right.
After adding the cube to zigbee2mqqt it only defines an action for flip90.
2022-10-17 16_38_29-Zigbee2MQTT – Home Assistant en nog 2 andere pagina's - Persoonlijk - Microsoft​

New to the world of automations though.
I’ve added the blueprint.
And defined the actions.
But I’m probably missing something obvious :sweat_smile:
Is the topic defined wrongly?

2022-10-17 16_40_18-Instellingen – Home Assistant en nog 2 andere pagina's - Persoonlijk - Microsoft

Yep, you forgot the /action at the end:)

edit: zigbee2mqtt shows you flip90, because that is what you did last with the cube, because that’s what the action topic is for and what the blueprint reacts to. The action topic also only appears if you do something with the cube. You can use MQTT Explorer to see how it works under hood, just find your cube there and start moving it.

1 Like

I have some sample rotate actions to change brightness and change color on my topic if you are looking for more examples…

1 Like