Rotate to the left or right in Xiaomi Magic Cube?

I’ll check… Thanks

Hello, I’m still not ableto do it…

platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor…
action_type: rotate
action_value: 90

Last lines is what I’m not sure how to do it

Hi,

I use it too. And you can see how much it was rotated. I use it to turn the HT volume up/down. What i have:

automation:

  • alias: ‘Cube rotate’
    trigger:
    platform: event
    event_type: cube_action
    event_data:
    entity_id: binary_sensor.cube_xxxxxxxxxx
    action_type: rotate

    action:

    • service_template: >-
      {% if trigger.event.data.action_value | float > 18 %}
      shell_command.ht_volplusup
      {% elif trigger.event.data.action_value | float > 0 %}
      shell_command.ht_volup
      {% elif trigger.event.data.action_value | float < -18 %}
      shell_command.ht_volplusdown
      {% elif trigger.event.data.action_value | float < 0 %}
      shell_command.ht_voldown
      {% endif %}
1 Like

Great… I’ll try…
Thanks

Hello again, could you help me a little bit,
My action looks like that:

action:
- service: switch.turn_on
entity_id: switch.focos_tele_comedor


I’m not sure how do it… I just want tu turn ON the light with that switch, If I turn to the right
And another if I turn to the left

Thanks in advance…

like below if rotate right increase volume, rotate left it decreases volume

  - alias: "Cube rotate - Volume livingroom home"
    initial_state: 'on'
    trigger:
      platform: event
      event_type: cube_action
      event_data:
        entity_id: binary_sensor.cube_158d00011a0108
        action_type: rotate
    action:
      - service: media_player.volume_set
        data_template:
          entity_id: media_player.living_room_home
          volume_level: >
                      {% set state = states.media_player.living_room_home.attributes.volume_level + (trigger.event.data.action_value|float)/90 -%}
                      {%-  if state > 1 -%}
                         {%- set state  = 1 -%}
                      {%-  elif state < 0 -%}
                         {%- set state  = 0 -%}
                      {%- endif %}
                      {{ state }}
4 Likes

It’s hard to export the idea, just to turn on the light!! :slight_smile: I thnik I understand the concept… but

Hard? no. The cube reports positive values when you rotate it to right, and negative when you rotate to the left. You just have to use the service_template. Look here: https://home-assistant.io/docs/scripts/service-calls/), “USE TEMPLATES TO DECIDE WHICH SERVICE TO CALL”. I guess it’s exactly what you want.

1 Like

Thanks… I’ll try

  • alias: Encender Focos Zona Tele Con Rotacion
    trigger:
    platform: event
    event_type: cube_action
    event_data:
    entity_id: binary_sensor.cube_158d0001041c9f
    action_type: rotate
    condition:
    condition: state
    entity_id: switch.focos_tele_comedor
    state: ‘off’
    action:
    #- service: switch.turn_on
    • service_template: >
      {% if states.binary_sensor.cube_158d0001041c9f.state | float > 15 %}
      switch.turn_on
      {% endif %}
      entity_id: switch.focos_tele_comedor

Isn’t working…
Here I don’t know what I have write
{% if states.binary_sensor.cube_158d0001041c9f.state | float > 15 %}

What you want to do? Turn on the lights when you rotate to right and turn of when to the left? Or just turn on, without turn off?

I have two couples of light in the living room… then I want…

Turning Right:
If lights are OFF, turn them ON
If lights are ON, turn then OFF

Turning Left:
If lights are OFF, turn them ON
If lights are ON, turn them OFF

Right now, without templates, I can turn the cube in any direction and lights in one side turn ON or OFF, that is easy… But, I just want to be abble to do that…

Thanks

You dont have to test the condition as you can just use the “toggle” service. You may need something like:

  • service: switch.toggle
    data_template:
    entity_id: >
    {% if states.binary_sensor.cube_158d0001041c9f.state | float > 0 %}
    switch.focos_tele_comedor
    {% else %}
    switch.focos_another_one
    {% endif %}

I’ll try too… thanks

  • alias: Encender Focos Zona Tele Con Rotacion
    trigger:
    platform: event
    event_type: cube_action
    event_data:
    entity_id: binary_sensor.cube_158d0001041c9f
    action_type: rotate
    action:
    • service: switch.turn_on
      entity_id: switch.focos_tele_comedor

I’m not abble… It should be easy, but Im not abble to do that, with templates…

I’ll tried

service: switch.toggle
data_template:
entity_id: >
{% if states.binary_sensor.cube_158d0001041c9f.state | float > 0 %}
switch.focos_tele_comedor
{% else %}
switch.focos_another_one
{% endif %}

And nothing

Hi,

My bad… there’s error in the automation. Change the line:

{% if states.binary_sensor.cube_158d0001041c9f.state | float > 0 %}

to

{%if trigger.event.data.action_value | float > 0 %}

as the action_value is the variable which holds how much did you rotate the cube.

2017-08-22 20:46:46 ERROR (Thread-2) [homeassistant.util.yaml] while scanning for the next token
found character ‘%’ that cannot start any token
in “/home/homeassistant/.homeassistant/automation/focos_techo_comedor.yaml”, line 91, column 10
2017-08-22 20:46:46 ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/homeassistant/.homeassistant/configuration.yaml: while scanning for the next token
found character ‘%’ that cannot start any token
in “/home/homeassistant/.homeassistant/automation/focos_techo_comedor.yaml”, line 91, column 10

Sorry for being so nerd… I’ll apreciate a lot if you could write me down all the sentence,

alias: Encender Focos Zona Tele Con Rotacion
trigger:
platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d0001041c9f
action_type: rotate
action:
service: switch.turn_on
entity_id: switch.focos_tele_comedor

Thanks a lot again…

Finally! Thanks

Im trying to create an automation which increases the volume of my Chromecast Group when rotating to the right and decreases the volume when rotating to the left. Somehow this is not working for me:

- alias: Xiaomi Cube - Volume Rotate
  trigger:
    platform: event
    event_type: cube_action
    event_data:
      entity_id: binary_sensor.cube_158d000101bded
      action_type: rotate
  action:
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.home_group          
        volume_level: >
          {%if trigger.event.data.action_value | float > 0 %} 
          {{  states.media_player.home_group.attributes.volume_level | float + 0.1 }} 
          {% else %}
          {{  states.media_player.home_group.attributes.volume_level | float - 0.1 }} 
          {% endif %}

Error:

2017-11-06 20:37:46 ERROR (MainThread) [homeassistant.core] Invalid service data for media_player.volume_set: expected float for dictionary value @ data['volume_level']. Got "'0.29999997317790983'"
2017-11-06 20:37:47 ERROR (MainThread) [homeassistant.core] Invalid service data for media_player.volume_set: expected float for dictionary value @ data['volume_level']. Got "'0.29999997317790983'"

Can anyone help me out, It is expecting a float and for as far as I can see it’s getting one right?

UPDATE: Removing the quotes did the trick :slight_smile:. I also removed them in the code above so that code is working.

Why doesn’t this work?

- alias: Xiaomi Cube - Brightness [Rotate]
  trigger:
    platform: event
    event_type: cube_action
    event_data:
      entity_id: binary_sensor.cube_xxxxxxxx
      action_type: rotate
  condition:
      - condition: state
        entity_id: input_select.cube_mode
        state: 'Light'   
  action:
    - service: light.turn_on
      data_template:
        entity_id: light.pc      
        brightness: >
          {%if trigger.event.data.action_value | float > 0 %} 
          {{  states.light.pc.attributes.brightness | int + 10 }}
          {% else %} 
          {{  states.light.pc.attributes.brightness | int - 10 }}
          {% endif %}