Skip to content

Instantly share code, notes, and snippets.

@nreymundo
Last active June 18, 2022 01:30
Show Gist options
  • Save nreymundo/d4204c2fffd2d0f19ff8553123756e87 to your computer and use it in GitHub Desktop.
Save nreymundo/d4204c2fffd2d0f19ff8553123756e87 to your computer and use it in GitHub Desktop.
z2m_magic_cube.yaml
blueprint:
name: Aqara Cube face-based
description: Control devices based on the cube's face.
domain: automation
input:
last_face_input:
name: Last face up numeric helper
description: Please select a Numeric Helper to be used to record the last face up.
selector:
entity:
domain: input_number
cube:
name: Aqara Cube
description: Select the Aqara Cube device
selector:
entity:
domain: sensor
face_1_flip:
name: Flip to face 1
description: Actions to execute when the cube is flipped to face 1 in the top.
default: []
selector:
action: {}
face_1_knock:
name: Knock face 1
description: Actions to execute when the cube is knocked with face 1 in the top.
default: []
selector:
action: {}
face_1_rotate_counter_clockwise:
name: Rotate counter-clockwise face 1
description: Actions to execute when the cube rotates counter-clockwise with face 1 in the top.
default: []
selector:
action: {}
face_1_rotate_clockwise:
name: Rotate clockwise face 1
description: Actions to execute when the cube rotates clockwise with face 1 in the top.
default: []
selector:
action: {}
face_1_slide:
name: Slide face 1
description: Actions to execute when the cube slides with face 1 in the top.
default: []
selector:
action: {}
face_2_flip:
name: Flip to face 2
description: Actions to execute when the cube is flipped to face 2 in the top.
default: []
selector:
action: {}
face_2_knock:
name: Knock face 2
description: Actions to execute when the cube is knocked with face 2 in the top.
default: []
selector:
action: {}
face_2_rotate_counter_clockwise:
name: Rotate counter-clockwise face 2
description: Actions to execute when the cube rotates counter-clockwise with face 2 in the top.
default: []
selector:
action: {}
face_2_rotate_clockwise:
name: Rotate clockwise face 2
description: Actions to execute when the cube rotates clockwise with face 2 in the top.
default: []
selector:
action: {}
face_2_slide:
name: Slide face 2
description: Actions to execute when the cube slides with face 2 in the top.
default: []
selector:
action: {}
face_3_flip:
name: Flip to face 3
description: Actions to execute when the cube is flipped to face 3 in the top.
default: []
selector:
action: {}
face_3_knock:
name: Knock face 3
description: Actions to execute when the cube is knocked with face 3 in the top.
default: []
selector:
action: {}
face_3_rotate_counter_clockwise:
name: Rotate counter-clockwise face 3
description: Actions to execute when the cube rotates counter-clockwise with face 3 in the top.
default: []
selector:
action: {}
face_3_rotate_clockwise:
name: Rotate clockwise face 3
description: Actions to execute when the cube rotates clockwise with face 3 in the top.
default: []
selector:
action: {}
face_3_slide:
name: Slide face 3
description: Actions to execute when the cube slides with face 3 in the top.
default: []
selector:
action: {}
face_4_flip:
name: Flip to face 4
description: Actions to execute when the cube is flipped to face 4 in the top.
default: []
selector:
action: {}
face_4_knock:
name: Knock face 4
description: Actions to execute when the cube is knocked with face 4 in the top.
default: []
selector:
action: {}
face_4_rotate_counter_clockwise:
name: Rotate counter-clockwise face 4
description: Actions to execute when the cube rotates counter-clockwise with face 4 in the top.
default: []
selector:
action: {}
face_4_rotate_clockwise:
name: Rotate clockwise face 4
description: Actions to execute when the cube rotates clockwise with face 4 in the top.
default: []
selector:
action: {}
face_4_slide:
name: Slide face 4
description: Actions to execute when the cube slides with face 4 in the top.
default: []
selector:
action: {}
face_5_flip:
name: Flip to face 5
description: Actions to execute when the cube is flipped to face 5 in the top.
default: []
selector:
action: {}
face_5_knock:
name: Knock face 5
description: Actions to execute when the cube is knocked with face 5 in the top.
default: []
selector:
action: {}
face_5_rotate_counter_clockwise:
name: Rotate counter-clockwise face 5
description: Actions to execute when the cube rotates counter-clockwise with face 5 in the top.
default: []
selector:
action: {}
face_5_rotate_clockwise:
name: Rotate clockwise face 5
description: Actions to execute when the cube rotates clockwise with face 5 in the top.
default: []
selector:
action: {}
face_5_slide:
name: Slide face 5
description: Actions to execute when the cube slides with face 5 in the top.
default: []
selector:
action: {}
face_6_flip:
name: Flip to face 6
description: Actions to execute when the cube is flipped to face 6 in the top.
default: []
selector:
action: {}
face_6_knock:
name: Knock face 6
description: Actions to execute when the cube is knocked with face 6 in the top.
default: []
selector:
action: {}
face_6_rotate_counter_clockwise:
name: Rotate counter-clockwise face 6
description: Actions to execute when the cube rotates counter-clockwise with face 6 in the top.
default: []
selector:
action: {}
face_6_rotate_clockwise:
name: Rotate clockwise face 6
description: Actions to execute when the cube rotates clockwise with face 6 in the top.
default: []
selector:
action: {}
face_6_slide:
name: Slide face 6
description: Actions to execute when the cube slides with face 6 in the top.
default: []
selector:
action: {}
source_url: https://community.home-assistant.io/t/aqara-cube-zha-simplified-face-based-device-control/388850
mode: restart
max_exceeded: silent
trigger:
- platform: device
domain: mqtt
device_id: !input cube
action:
- variables:
command: '{{ trigger.event.data.command }}'
value: '{{ trigger.event.data.args.value | default(0) }}'
flip_degrees: '{{ trigger.event.data.args.flip_degrees | default(0) }}'
relative_degrees: '{{ trigger.event.data.args.relative_degrees | default(0) }}'
temp_last_face_input: !input last_face_input
activated_face: '{{ iif((command == ''slide'' or command == ''knock'' or command == ''flip''), trigger.event.data.args.activated_face, states(temp_last_face_input)) | int(0) }}'
#activated_face: |-
#{% if command == 'slide' or command == 'knock' or command == 'flip' %}
#{{ trigger.event.data.args.activated_face | int(0) }}
#{% else %}
#{{ states(temp_last_face_input) | int(0) }}
#{% endif %}
- service: input_number.set_value
target:
entity_id: !input last_face_input
data:
value: '{{ activated_face }}'
- choose:
- conditions:
- '{{ activated_face == 1 }}'
sequence:
- choose:
- conditions:
- '{{ command == ''flip'' }}'
sequence: !input face_1_flip
- conditions:
- '{{ command == ''knock'' }}'
sequence: !input face_1_knock
- conditions:
- '{{ command == ''rotate_left'' }}'
sequence: !input face_1_rotate_counter_clockwise
- conditions:
- '{{ command == ''rotate_right'' }}'
sequence: !input face_1_rotate_clockwise
- conditions:
- '{{ command == ''slide'' }}'
sequence: !input face_1_slide
default: []
- conditions:
- '{{ activated_face == 2 }}'
sequence:
- choose:
- conditions:
- '{{ command == ''flip'' }}'
sequence: !input face_2_flip
- conditions:
- '{{ command == ''knock'' }}'
sequence: !input face_2_knock
- conditions:
- '{{ command == ''rotate_left'' }}'
sequence: !input face_2_rotate_counter_clockwise
- conditions:
- '{{ command == ''rotate_right'' }}'
sequence: !input face_2_rotate_clockwise
- conditions:
- '{{ command == ''slide'' }}'
sequence: !input face_2_slide
default: []
- conditions:
- '{{ activated_face == 3 }}'
sequence:
- choose:
- conditions:
- '{{ command == ''flip'' }}'
sequence: !input face_3_flip
- conditions:
- '{{ command == ''knock'' }}'
sequence: !input face_3_knock
- conditions:
- '{{ command == ''rotate_left'' }}'
sequence: !input face_3_rotate_counter_clockwise
- conditions:
- '{{ command == ''rotate_right'' }}'
sequence: !input face_3_rotate_clockwise
- conditions:
- '{{ command == ''slide'' }}'
sequence: !input face_3_slide
default: []
- conditions:
- '{{ activated_face == 4 }}'
sequence:
- choose:
- conditions:
- '{{ command == ''flip'' }}'
sequence: !input face_4_flip
- conditions:
- '{{ command == ''knock'' }}'
sequence: !input face_4_knock
- conditions:
- '{{ command == ''rotate_left'' }}'
sequence: !input face_4_rotate_counter_clockwise
- conditions:
- '{{ command == ''rotate_right'' }}'
sequence: !input face_4_rotate_clockwise
- conditions:
- '{{ command == ''slide'' }}'
sequence: !input face_4_slide
default: []
- conditions:
- '{{ activated_face == 5 }}'
sequence:
- choose:
- conditions:
- '{{ command == ''flip'' }}'
sequence: !input face_5_flip
- conditions:
- '{{ command == ''knock'' }}'
sequence: !input face_5_knock
- conditions:
- '{{ command == ''rotate_left'' }}'
sequence: !input face_5_rotate_counter_clockwise
- conditions:
- '{{ command == ''rotate_right'' }}'
sequence: !input face_5_rotate_clockwise
- conditions:
- '{{ command == ''slide'' }}'
sequence: !input face_5_slide
default: []
- conditions:
- '{{ activated_face == 6 }}'
sequence:
- choose:
- conditions:
- '{{ command == ''flip'' }}'
sequence: !input face_6_flip
- conditions:
- '{{ command == ''knock'' }}'
sequence: !input face_6_knock
- conditions:
- '{{ command == ''rotate_left'' }}'
sequence: !input face_6_rotate_counter_clockwise
- conditions:
- '{{ command == ''rotate_right'' }}'
sequence: !input face_6_rotate_clockwise
- conditions:
- '{{ command == ''slide'' }}'
sequence: !input face_6_slide
default: []
default: []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment