My wife and I both have a magic cube on our night stand. Rotating the cube to the right increases the fan speed, rotating to the left decreases the fan speed.
### Change master fan --> speed is based on rotational direction and current fan speed.
- id: cube_rotate
alias: Cube event rotate
trigger:
- platform: event
event_type: xiaomi_aqara.cube_action
event_data:
entity_id: binary_sensor.cube1
action_type: rotate
- platform: event
event_type: xiaomi_aqara.cube_action
event_data:
entity_id: binary_sensor.cube2
action_type: rotate
action:
service: fan.set_speed
entity_id: fan.master_bedroom
data_template:
speed: >
{% set speed = states.fan.master_bedroom.attributes.speed %}
{% if trigger.event.data.action_value | float > 0 %}
{% if speed == 'off' %}
low
{% elif speed == 'low' %}
medium
{% elif speed == 'medium' %}
high
{% else %}
high
{% endif %}
{% else %}
{% if speed == 'high' %}
medium
{% elif speed == 'medium' %}
low
{% elif speed == 'low' %}
off
{% else %}
off
{% endif %}
{% endif %}