Mi Magic Cube - Deconz (45+ actions!)

Hello,

I’ve made a blueprint for the Aqara Cube.
Use this URL to import to your blueprints!

mimagiccube

I have not tested EVERY function yet but every function is built the same way so it should work. But let me know if you see any errors. Be sure to listen to deconz_event to see if cube is actually registering when it’s not working.

Blueprint

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

blueprint:
  name: Mi Magic Cube
  description: |
    Control anything using Mi Magic Cube.
    Remember not to use an action on every combination, then you won't be able to start from anywhere without triggering an action

  domain: automation
  input:
    remote:
      name: Magic Cube
      description: Mi Magic Cube
      selector:
        device:
          integration: deconz
          manufacturer: LUMI
          model: lumi.sensor_cube.aqgl01
#Extra conf
    flip_90:
      name: Flip 90 degrees
      description: |
        Actions to run when cube flips 90 degrees
        
        This cancels all specific 90 degrees functions
        e.g From side 1 to side 2 will be the same as from side 6 to side 2
      default: false
      selector:
        boolean: {}
        
    cube_flip_90:
      name: Flip cube 90 degrees
      description: Action to run when cube flips 90 degrees. This only works if 'Flip 90 degrees' is toggled
      default: []
      selector:
        action:
        
    flip_180:
      name: Flip 180 degrees
      description: |
        Actions to run when cube flips 180 degrees.
        This cancels all specific 180 degrees functions
        e.g From side 1 to side 6 will be the same as from side 5 to side 2
      default: false
      selector:
        boolean: {}
        
    cube_flip_180:
      name: Flip cube 180 degrees
      description: Action to run when cube flips 180 degrees. This only works if 'Flip 180 degrees' is toggled
      default: []
      selector:
        action:
        
    one_side_slide:
      name: Slide any side
      description: |
        Actions to run when cube slides on any side
        
        This cancels all specific slide functions
        e.g Slide on side 1 will be the same as slide on side 2
      default: false
      selector:
        boolean: {}
        
    cube_one_side_slide:
      name: Slide cube on any side
      description: Action to run when cube slides on any slide. This only works if 'Slide any side' is toggled
      default: []
      selector:
        action:
        
    double_tap_any_side:
      name: Double tap on any side
      description: |
        Actions to run when double tapping cube regardless of the side.
        
        This cancels all specific double tap functions
        e.g Double tap on side 1 will be the same as double tapping side 2
      default: false
      selector:
        boolean: {}
        
    cube_double_tap_any:
      name: Double tap cube on any side
      description: Action to run when double tapping cube on any side. This only works if 'Double tap on any side' is toggled
      default: []
      selector:
        action:

#From Side 1
    one_to_two:
      name: From side 1 to side 2
      description: Action to run when cube goes from side 1 to side 2
      default: []
      selector:
        action:
    one_to_three:
      name: From side 1 to side 3
      description: Action to run when cube goes from side 1 to side 3
      default: []
      selector:
        action:
    one_to_four:
      name: From side 1 to side 4
      description: Action to run when cube goes from side 1 to side 4
      default: []
      selector:
        action:
    one_to_five:
      name: From side 1 to side 5
      description: Action to run when cube goes from side 1 to side 5
      default: []
      selector:
        action:
    one_to_six:
      name: From side 1 to side 6
      description: Action to run when cube goes from side 1 to side 6
      default: []
      selector:
        action:
#From Side 2
    two_to_one:
      name: From side 2 to side 1
      description: Action to run when cube goes from side 2 to side 1
      default: []
      selector:
        action:
    two_to_three:
      name: From side 2 to side 3
      description: Action to run when cube goes from side 2 to side 3
      default: []
      selector:
        action:
    two_to_four:
      name: From side 2 to side 4
      description: Action to run when cube goes from side 2 to side 4
      default: []
      selector:
        action:
    two_to_five:
      name: From side 2 to side 5
      description: Action to run when cube goes from side 2 to side 5
      default: []
      selector:
        action:
    two_to_six:
      name: From side 2 to side 6
      description: Action to run when cube goes from side 2 to side 6
      default: []
      selector:
        action:
#From Side 3
    three_to_one:
      name: From side 3 to side 1
      description: Action to run when cube goes from side 3 to side 1
      default: []
      selector:
        action:
    three_to_two:
      name: From side 3 to side 2
      description: Action to run when cube goes from side 3 to side 2
      default: []
      selector:
        action:
    three_to_four:
      name: From side 3 to side 4
      description: Action to run when cube goes from side 3 to side 4
      default: []
      selector:
        action:
    three_to_five:
      name: From side 3 to side 5
      description: Action to run when cube goes from side 3 to side 5
      default: []
      selector:
        action:
    three_to_six:
      name: From side 3 to side 6
      description: Action to run when cube goes from side 3 to side 6
      default: []
      selector:
        action:    
#From Side 4
    four_to_one:
      name: From side 4 to side 1
      description: Action to run when cube goes from side 4 to side 1
      default: []
      selector:
        action:
    four_to_two:
      name: From side 4 to side 2
      description: Action to run when cube goes from side 4 to side 2
      default: []
      selector:
        action:
    four_to_three:
      name: From side 4 to side 3
      description: Action to run when cube goes from side 4 to side 3
      default: []
      selector:
        action:
    four_to_five:
      name: From side 4 to side 5
      description: Action to run when cube goes from side 4 to side 5
      default: []
      selector:
        action:
    four_to_six:
      name: From side 4 to side 6
      description: Action to run when cube goes from side 4 to side 6
      default: []
      selector:
        action:
#From Side 5
    five_to_one:
      name: From side 5 to side 1
      description: Action to run when cube goes from side 5 to side 1
      default: []
      selector:
        action:
    five_to_two:
      name: From side 5 to side 2
      description: Action to run when cube goes from side 5 to side 2
      default: []
      selector:
        action:
    five_to_three:
      name: From side 5 to side 3
      description: Action to run when cube goes from side 5 to side 3
      default: []
      selector:
        action:
    five_to_four:
      name: From side 5 to side 4
      description: Action to run when cube goes from side 5 to side 4
      default: []
      selector:
        action:
    five_to_six:
      name: From side 5 to side 6
      description: Action to run when cube goes from side 5 to side 6
      default: []
      selector:
        action:
#From Side 6
    six_to_one:
      name: From side 6 to side 1
      description: Action to run when cube goes from side 6 to side 1
      default: []
      selector:
        action:
    six_to_two:
      name: From side 6 to side 2
      description: Action to run when cube goes from side 6 to side 2
      default: []
      selector:
        action:
    six_to_three:
      name: From side 6 to side 3
      description: Action to run when cube goes from side 6 to side 3
      default: []
      selector:
        action:
    six_to_four:
      name: From side 6 to side 4
      description: Action to run when cube goes from side 6 to side 4
      default: []
      selector:
        action:
    six_to_five:
      name: From side 6 to side 5
      description: Action to run when cube goes from side 6 to side 5
      default: []
      selector:
        action:
#Double taps        
    one_to_one:
      name: Double tap - Side 1
      description: Action to run when double tap on side 1
      default: []
      selector:
        action:
    two_to_two:
      name: Double tap - Side 2
      description: Action to run when double tap on side 2
      default: []
      selector:
        action:
    three_to_three:
      name: Double tap - Side 3
      description: Action to run when double tap on side 3
      default: []
      selector:
        action:
    four_to_four:
      name: Double tap - Side 4
      description: Action to run when double tap on side 4
      default: []
      selector:
        action: 
    five_to_five:
      name: Double tap - Side 5
      description: Action to run when double tap on side 5
      default: []
      selector:
        action: 
    six_to_six:
      name: Double tap - Side 6
      description: Action to run when double tap on side 6
      default: []
      selector:
        action: 
#Rotates
    rotate_clockwise:
      name: Rotate clockwise
      description: Action to run when cube rotates clockwise
      default: []
      selector:
        action:
    rotate_counter_clockwise:
      name: Rotate counter clockwise
      description: Action to run when cube rotates counter clockwise
      default: []
      selector:
        action:
#Slides
    slide_on_one:
      name: Slide - Side 1 up
      description: Action to run when slides with Side 1 up
      default: []
      selector:
        action:
    slide_on_two:
      name: Slide - Side 2 up
      description: Action to run when slides with Side 2 up
      default: []
      selector:
        action:
    slide_on_three:
      name: Slide - Side 3 up
      description: Action to run when slides with Side 3 up
      default: []
      selector:
        action:
    slide_on_four:
      name: Slide - Side 4 up
      description: Action to run when slides with Side 4 up
      default: []
      selector:
        action:
    slide_on_five:
      name: Slide - Side 5 up
      description: Action to run when slides with Side 5 up
      default: []
      selector:
        action:
    slide_on_six:
      name: Slide - Side 6 up
      description: Action to run when slides with Side 6 up
      default: []
      selector:
        action:
#Misc
    cube_wake:
      name: Wake up the cube
      description: Action to run when cube wakes up
      default: []
      selector:
        action:
    cube_fall:
      name: Cube falls
      description: |
        Action to run when cube falls
        pro tip: throw up and catch
      default: []
      selector:
        action:
    cube_shake:
      name: Shake cube
      description: Action to run when you shake the cube
      default: []
      selector:
        action:
mode: restart
max_exceeded: silent

trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      device_id: !input "remote"

action:
  - variables:
      event: "{{ trigger.event.data.event }}"
      gesture: "{{ trigger.event.data.gesture }}"
      flip_90: !input "flip_90"
      flip_180: !input "flip_180"
      one_side_slide: !input "one_side_slide"
      double_tap_any_side: !input "double_tap_any_side"
  - choose:
#From Side 1
      - conditions:
          - "{{ event == 1001 }}"
        sequence: 
          - choose:
              - conditions: "{{ double_tap_any_side }}"
                sequence: !input cube_double_tap_any
            default: !input one_to_one

      - conditions:
           - "{{ event == 2001 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input one_to_two

      - conditions:
          - "{{ event == 3001 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input one_to_three

      - conditions:
           - "{{ event == 4001 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input one_to_four

      - conditions:
           - "{{ event == 5001 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input one_to_five
        
      - conditions:
           - "{{ event == 6001 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_180 }}"
                sequence: !input cube_flip_180
            default: !input one_to_six
#From Side 2
      - conditions:
           - "{{ event == 1002 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input two_to_one
        
      - conditions:
           - "{{ event == 2002 }}"
        sequence: 
          - choose:
              - conditions: "{{ double_tap_any_side }}"
                sequence: !input cube_double_tap_any
            default: !input two_to_two
        
      - conditions:
           - "{{ event == 3002 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input two_to_three
        
      - conditions:
           - "{{ event == 4002 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input two_to_four
        
      - conditions:
           - "{{ event == 5002 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_180 }}"
                sequence: !input cube_flip_180
            default: !input two_to_five
        
      - conditions:
           - "{{ event == 6002 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input two_to_six
#From Side 3
      - conditions:
           - "{{ event == 1003 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input three_to_one
        
      - conditions:
           - "{{ event == 2003 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input three_to_two
        
      - conditions:
           - "{{ event == 3003 }}"
        sequence: 
          - choose:
              - conditions: "{{ double_tap_any_side }}"
                sequence: !input cube_double_tap_any
            default: !input three_to_three
        
      - conditions:
           - "{{ event == 4003 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_180 }}"
                sequence: !input cube_flip_180
            default: !input three_to_four
        
      - conditions:
           - "{{ event == 5003 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input three_to_five
        
      - conditions:
           - "{{ event == 6003 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input three_to_six
#From Side 4
      - conditions:
           - "{{ event == 1004 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input four_to_one
        
      - conditions:
           - "{{ event == 2004 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input four_to_two
        
      - conditions:
           - "{{ event == 3004 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_180 }}"
                sequence: !input cube_flip_180
            default: !input four_to_three
        
      - conditions:
           - "{{ event == 4004 }}"
        sequence: 
          - choose:
              - conditions: "{{ double_tap_any_side }}"
                sequence: !input cube_double_tap_any
            default: !input four_to_four
        
      - conditions:
           - "{{ event == 5004 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input four_to_five
        
      - conditions:
           - "{{ event == 6004 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input four_to_six
#From Side 5
      - conditions:
           - "{{ event == 1005 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input five_to_one
        
      - conditions:
           - "{{ event == 2005 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_180 }}"
                sequence: !input cube_flip_180
            default: !input five_to_two
        
      - conditions:
           - "{{ event == 3005 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input five_to_three
        
      - conditions:
           - "{{ event == 4005 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input five_to_four
        
      - conditions:
           - "{{ event == 5005 }}"
        sequence: 
          - choose:
              - conditions: "{{ double_tap_any_side }}"
                sequence: !input cube_double_tap_any
            default: !input five_to_five
        
      - conditions:
           - "{{ event == 6005 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input five_to_six
#From Side 1
      - conditions:
          - "{{ event == 1006 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_180 }}"
                sequence: !input cube_flip_180
            default: !input six_to_one

      - conditions:
           - "{{ event == 2006 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input six_to_two

      - conditions:
          - "{{ event == 3006 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input six_to_three

      - conditions:
           - "{{ event == 4006 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input six_to_four

      - conditions:
           - "{{ event == 5006 }}"
        sequence: 
          - choose:
              - conditions: "{{ flip_90 }}"
                sequence: !input cube_flip_90
            default: !input six_to_five
        
      - conditions:
           - "{{ event == 6006 }}"
        sequence: 
          - choose:
              - conditions: "{{ double_tap_any_side }}"
                sequence: !input cube_double_tap_any
            default: !input six_to_six
#Slides
      - conditions:
           - "{{ event == 1000 }}"
        sequence: 
          - choose:
              - conditions: "{{ one_side_slide }}"
                sequence: !input cube_one_side_slide
            default: !input slide_on_one
        
      - conditions:
           - "{{ event == 2000 }}"
        sequence: 
          - choose:
              - conditions: "{{ one_side_slide }}"
                sequence: !input cube_one_side_slide
            default: !input slide_on_two
        
      - conditions:
           - "{{ event == 3000 }}"
        sequence: 
          - choose:
              - conditions: "{{ one_side_slide }}"
                sequence: !input cube_one_side_slide
            default: !input slide_on_three
        
      - conditions:
           - "{{ event == 4000 }}"
        sequence: 
          - choose:
              - conditions: "{{ one_side_slide }}"
                sequence: !input cube_one_side_slide
            default: !input slide_on_four
        
      - conditions:
           - "{{ event == 5000 }}"
        sequence: 
          - choose:
              - conditions: "{{ one_side_slide }}"
                sequence: !input cube_one_side_slide
            default: !input slide_on_five
        
      - conditions:
           - "{{ event == 6000 }}"
        sequence: 
          - choose:
              - conditions: "{{ one_side_slide }}"
                sequence: !input cube_one_side_slide
            default: !input slide_on_six

#Rotates
      - conditions:
           - "{{ gesture == 7 }}"
        sequence: !input rotate_clockwise
        
      - conditions:
           - "{{ gesture == 8 }}"
        sequence: !input rotate_counter_clockwise
        
#Misc
      - conditions:
           - "{{ event == 7000 }}"
        sequence: !input cube_wake
        
      - conditions:
           - "{{ event == 7007 }}"
        sequence: !input cube_shake
        
      - conditions:
           - "{{ event == 7008 }}"
        sequence: !input cube_fall


23 Likes

Wow! This is one extensive blueprint, good job!

1 Like

Thank you! It was a bit messy to keep track of everything

1 Like

Wouldn’t it be possible to use device triggers here rather than specifying the event? I haven’t looked in detail at blueprints yet

It might, is there any perks by doing that? I guess those triggers are somehow linked to The event but I have no clue.

I am very green in automating in YAML, so I would have to check up how to do that. I actually reused another blueprint that listened for events for an ikea switch. And made it… Huge!

It is more or less the same, it just provides a level of abstraction

This is awesome. Replaced two old automations of myself with this huge one.

Out of interest, do blueprints also update? For example when you add actions or whatever.

Thank you Gerben,

You can just go into the automation you created and change/add actions as you go.

If you mean if I change the code here on the forum I guess it won’t change your blueprint.
I -->think<-- it just syncs over when importing

Yeah that’s what I meant, when you update code here. Would be great if there was a sync button or something to update the blueprint, but that’s off-topic. Great job.

I think I’ll only change if anyone reports a bug. I guess those who follow get a notification when I do. But hey, blueprints is the first thing I am posting in the forum so I have no idea

Dont workin whith lumi.sensor_cube.aqgl01 :slightly_frowning_face:
No matching devices found.

3 Likes

Check integration and see what yours is called

Would it be possible to also configure different actions for rotation on different side up? e.g. rotating side 1 up would adjust the volume of the receiver while rotating side 2, 3, 4 would dim different lights in the house. This would add 2x5 = 10(!) actions to the cube!

This is massive, well done! What would be involved to replicate this as a ZHA Blueprint?

EDIT: I just found a Blueprint to do this with ZHA however judging by the forum thread I think it might be buggy at this stage. A remake of this DeConz one would be awesome.

Hey Freddie,

I don’t think it is possible but I will definetly look it up. Rotating makes a mess to the ‘event’ and that is where I look which side is up, I have to see if there is any pattern on different side-rotation

Thank you Dave!

I have no idea since I haven’t used ZHA at all. I guess it wouldn’t be that hard, but I would have to discuss with you while making it to see if it works :slightly_smiling_face:. I do not know when I have the time, might be in the evening tomorrow.

Do you have any public discord server or something I can join?

I’d be happy to help. I haven’t yet started with Blueprints as I’m currently away for work so my HA is still on 0.118.4
I’ll be back home in a week and can start getting things moving then.
I don’t have a Discord server

I have zero experience with blueprints, but I think this would be possible by writing the ‘last’ side up into an input value and use that to run different actions based on the rotation. So each change in orientation will write the current side up into a variable, that in turn is used when rotation is detected.

I did use your blueprint to re-map all my current actions to the cube and it works perfectly. Thanks!

Well I could invite you to mine when it is time. Just write here when you are home and ready :slightly_smiling_face:

Nice to hear that it works out!
You could use an input_select and change the value on the events. I’d rather keep it without having to rely on other entities. But I could create a new one for this.

The question is, should it be added to this or a blueprint only for the rotation?

1 Like