Rotate to the left or right in Xiaomi Magic Cube?

You can use the Xiaomi Gateway no problem, I do. I use the rotation to control my amplifier via a Broadlink RM mini 3. It works perfectly.

  - alias: 'Cube-Volume [Rotate]'
    initial_state: 'on'
    trigger:
      - platform: event
        event_type: xiaomi_aqara.cube_action
        event_data:
          entity_id: binary_sensor.cube_158d00010fd152_2
          action_type: rotate
    action:
      - service_template: >  
            {%if trigger.event.data.action_value | float > 0 %} 
                  media_player.volume_up
            {% else %} 
                  media_player.volume_down
            {% endif %}
        entity_id: media_player.onkyo_amp

If your control of the remote device is via switches rather than a media_player entity, see my post above. Thats my old code.

1 Like

Hey Dave,

Thanks so much for the reply. I used your older code as my system is also setup via switches and it works perfectly.
(My broadlink rm mini sends a packet to my yamaha amp adjusting volume by 5 units at a time and this works great with your automation).

Cheers

George

:smiley:

Thanks for the example! The roku media_player doesn’t support volume_level, but it does support media_player.volume_up and media_player.volume_down. I got my Mi Cube to control Roku volume on the first try.

Hi, I created the following automation for the cube:

############################################################
# XIAOMI CUBE
############################################################
## Master Bedroom Cube
- alias: Cube Open/Stop/Close Master Curtain
  trigger:
    platform: event
    event_type: xiaomi_aqara.cube_action
    event_data:
      entity_id: binary_sensor.cube_158d00027d01c3
#
  action:
    service_template: >
      {% if trigger.event.data.action_type == 'rotate' and trigger.event.data.action_value < -45 %}
        cover.open_cover
      {% elif trigger.event.data.action_type == 'rotate' and trigger.event.data.action_value > 45  %}
          cover.close_cover
      {% else %}
        cover.stop_cover
      {% endif %}
    entity_id: cover.curtain_158d0002b87738

It’s working fine, however I’m continously get the following error:

Cube Open/Stop/Close Master Curtain: Error executing script. Error rendering template for call_service at pos 1: UndefinedError: 'dict object' has no attribute 'action_value'

I monitor the event using dev tools listen to events and lister to xiaomi_aqara.cube_action, it seems that in some event’s the action_value attribute not avail, even in the rotate event.

So until now, still have no idea how to get rid this error, though the automation is working fine.

Solved:

check “trigger.event.data.action_value is defined” before using it.

############################################################
# XIAOMI CUBE
############################################################
## Master Bedroom Cube
- alias: Cube Open/Stop/Close Master Curtain
  trigger:
    platform: event
    event_type: xiaomi_aqara.cube_action
    event_data:
      entity_id: binary_sensor.cube_158d00027d01c3
#      action_type: rotate
#
  action:
#    service: cover.toggle
    service_template: >
      {% if trigger.event.data.action_type == 'rotate' and trigger.event.data.action_value is defined %}
        {% if trigger.event.data.action_value < -45 %}
          cover.open_cover
        {% elif trigger.event.data.action_value > 45  %}
          cover.close_cover
        {% endif %}
      {% else %}
        cover.stop_cover
      {% endif %}
    entity_id: cover.curtain_158d0002b87738

Hello!
There is a cube of aqara and yeelight lamp.
I’m trying to adjust the brightness of the lamp when turning the cube. I took such automation from this topic.

- id: 'Cube rotate'
  alias: Cube rotate
  initial_state: true   
  trigger:
    platform: event
    event_type: xiaomi_aqara.cube_action
    event_data:
      entity_id: binary_sensor.cube_158d00027d9f6c
      action_type: rotate
  action:
  - service: light.turn_on  
    data_template:  
      entity_id: light.yeelight_color_1
      brightness: >-
          {%- set delta = 40 %}
          {%if trigger.event.data.action_value | int > 0 %}
            {%- set bright = states.light.yeelight_color_1.attributes.brightness | int + delta %}
          {% else %}
            {%- set bright = states.light.yeelight_color_1.attributes.brightness | int - delta %}
          {% endif %}
          {% if bright > 255 %}
            255
          {% elif bright < 0 %}
            0
          {% else %}
            {{bright}}
          {% endif %}

Faced with the fact that the event of “rotation” occurs and the brightness adjustment does not occur. I do not understand what’s the matter. Help