ZHA - Aqara Magic Cube (69 actions)

Blueprint to automate the Aqara Magic Cube using ZHA.
Based on Mikkelmoller’s 51-action blueprint.
as well as brent’s 57-action blueprint.

This blueprint adds support for rotating the cube per specific side, by using an Input Number helper to track the side that was last activated by a side-specific action (flip, slide, knock).

Note that since this blueprint uses an input number helper to track which side is active, it will only register side changes from valid side actions (again, flip/knock/slide). If you lift the cube, rotate it freely, and then place it down on a different side, this is not registered as a valid action and the tracking variable won’t be updated.

The input number helper will need to be created independently in HomeAssistant, by going to Configuration → Helpers in the UI and adding a new Number helper.

Supported actions

  • Slide
  • Knock
  • Flip 90 degress
  • Flip 180 degress
  • Flip to specific side
  • Shake
  • Drop
  • Wake
  • Rotate clockwise
  • Rotate counter-clockwise
  • Rotate per side

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

Here’s a sample automation that will call out the side using Alexa media player TTS when flipped, and will adjust brightness of office lights based on the relative degree of the rotation (thanks brent!) but only for face 1:

- id: '1634593050891'
  alias: 'Master: Aqara Magic Cube'
  description: ''
  use_blueprint:
    path: rvaidya/aqara_magic_cube.yaml
    input:
      remote: 3243d34
      active_face: input_number.aqara_magic_cube_active_face
      flip_any: true
      cube_flip_1:
      - service: notify.alexa_media
        data:
          message: One
          target: media_player.user_s_echo_dot
          data:
            type: tts
      cube_flip_2:
      - service: notify.alexa_media
        data:
          message: Two
          target: media_player.user_s_echo_dot
          data:
            type: tts
      cube_flip_3:
      - service: notify.alexa_media
        data:
          message: Three
          target: media_player.user_s_echo_dot
          data:
            type: tts
      cube_flip_4:
      - service: notify.alexa_media
        data:
          message: Four
          target: media_player.user_s_echo_dot
          data:
            type: tts
      cube_flip_5:
      - service: notify.alexa_media
        data:
          message: Five
          target: media_player.user_s_echo_dot
          data:
            type: tts
      cube_flip_6:
      - service: notify.alexa_media
        data:
          message: Six
          target: media_player.user_s_echo_dot
          data:
            type: tts
      rotate_left_side_1:
      - service: light.turn_on
        target:
          area_id: office
        data_template:
          brightness_step: '{{ relative_degrees | float }}'
      rotate_right_side_1:
      - service: light.turn_on
        target:
          area_id: office
        data_template:
          brightness_step: '{{ relative_degrees | float }}'
14 Likes

Hey this looks like it will do exactly what I am looking for. I am however very new to HA and was wondering if you could just give me an example how the number helper would work. What lines were required etc. I am a once I see it I can understand how to do the rest but the big thing is tracking the sides which is the big functionality.

Really Appreciate it and looks great!

Thanks very great work!
I have tested for rotate face and it works but if try to use knock face option seems to not work.
There is some special flag to use “knock” face feature?
Thanks so much

You can create an input number helper in HomeAssistant’s UI. Just go to Configuration → Helpers and create a “Number” helper. You can then reference this in the automation in the UI.

The knock detection on the cube is kind of flaky - I find that I have to pick up the cube and then hit it against the desk 3 times to trigger it somewhat consistently.

Excellent work! Thank you!

Yes you are right, now if pick up and then i hit it it works!! So thanks so much and sorry…!

Any reason that an action can’t go against an entity instead of a device. I have some zigbee groups that I would like to use this on. But can’t get the action down. Thanks

As far as I can tell, the cube doesn’t expose entities that can be used for automations when added to ZHA.

Dear Rahul,
from some time (i can not be sure…sorry) the feature of “Slide - Side X up” seems not working as we expected.
If we look on “active_face_entity” (the helper entity) i can see the right side but as soon i slide the cube the active_face_entity will change with a different number for instance: if i’m on face n.2 and i slide the cube the “active_face_entity” will be n.5.
Maybe something is changed on homeassistant release (i’m in 2021.12.7).
Thanks so much for your help

1 Like

Thank you for your reply, Rahul. I am looking for a way for the blueprint to perform an action on any entity. So in my case I have the cube and the blueprint, and I want to turn on a zigbee group. There doesn’t seem to be a way for me to define the zigbee group (which is an entity) in the Blueprint. AmI missing something?

Thank you!

I have fixed my problem with a change to those Blueprint lines (bold value):

activated_face: |

    {% if command == "slide" or command == "knock" %}

      {% if trigger.event.data.args.activated_face == 1 %} 1

      {% elif trigger.event.data.args.activated_face == 2 %} **2**

      {% elif trigger.event.data.args.activated_face == 3 %} **3**

      {% elif trigger.event.data.args.activated_face == 4 %} 4

      {% elif trigger.event.data.args.activated_face == 5 %} **5**

      {% elif trigger.event.data.args.activated_face == 6 %} **6**

Now it seems to work as expected but why? :slight_smile:
Thanks so much

5 Likes

Hi, by using this blueprint I develop my one in a much simpler approach (only 24 actions, 6 sides * [rotate, flip, knock and slide])

ZHA - Aqara Magic Cube (24 actions)

Hey,

First of all thank you for providing this blueprint. I’m still not sure what different actions I will program because it will be hard to remember them all :smiley:

I’m trying to use the rotate left and right actions to change the color temperature of a light (like dimming). This is the YAML that I tried

      rotate_left_side_1:
      - service: light.turn_on
        data_template:
          color_temp: "{{ state_attr('light.glas', 'color_temp') - 20 }}"
        target:
          device_id: bd2742b4f7d475d7e876ca73bc305d74

Unfortunately this isn’t working. Any ideas why?

Thanks.

when creating the input helper, do I only need to give it a name and save it with all the other default values?

@rvaidya Amazing blueprint! I love it! I ran into a bug though. If I create a new automation from the blueprint it works perfectly. However if I try and edit the automation later the toggle switches won’t save if I change them (slide any, rotate any, etc.). Am I doing something wrong?

That is an HA Bug I believe…
There is an issue for that.

1 Like

Good to know, thanks!

FYI: I was struggling to get this automation blueprint for my aqara cube working after a recent HA update (currently running 2022.7.7) . I finally realized I didn’t need the blueprint anymore because the cube device now generates events that can be used for automation without the blueprint.

Yes, it always did that. Otherwise the Blueprints would not work.