I shamelessly stole this from someone else and it works well for me, but I’m not sure it is possible to get a true equivalent to a smooth analogue dial with the cube:
trigger:
platform: event
event_type: xiaomi_aqara.cube_action
event_data:
entity_id: binary_sensor.cube_xxxxxxxxxxx
action_type: rotate
action:
- service: media_player.volume_set
data_template:
entity_id: media_player.kitchen
volume_level: >
{% set state = states.media_player.kitchen.attributes.volume_level + (trigger.event.data.action_value|float)/90 -%}
{%- if state > 1 -%}
{%- set state = 1 -%}
{%- elif state < 0 -%}
{%- set state = 0 -%}
{%- endif %}
{{ state }}
Nice. I should have warned you that have to have typos :-). A long time ago when I was testing my cube I used to “tail -f” the homeassistant log and see what HA reported when I moved the cube. I was expecting something like the angle you moved the cube (90 = quarter turn) but it wasnt, so I had to test/try which values make senses. As you say, it’s not like a good analog volume knob and it will never will, first because the cube does not report values as you are moving it but only when you finish moving and second it’s not that precise with the values.
I use my cube to control the volume of my tv but since I can’t set absolute values (I’m using IR) what I do is increment/decrement a single “unit” when I do a small rotation and increment/decrement 4 units when I do a bigger rotation. Not ideal but acceptable :-).
I still have that idea of using a cheap midi controller with sliders to do that kind of thing…
“you are moving it but only when you finish moving and second it’s not that precise with the values.”
And this is the downside of the whole cube and should be mentioned everywhere. I thought that it reports continuously. Now I see why it is working like this.
Hi everyone,
I’m a beginner and I need your help:
I tried this automation to adjust the light of the gateway, but it does not work,
can you tell me where I’m wrong?
well, the last else if will never be hit because any number less than zero will be less than zero and therefor go into the {%- elif angle < 0 -%} script.ph_vol_down_1. Reverse -50 and 0 and it will work.
I’ve tried your automation without any success (yes I have set the scripts up). My volume is controlled sending packets through a broadlink rm-mini. I am wondering though, all communication between my aqara cube is via a xiaomi gateway and home assistant. To get the extra info about rotation of the cube, must you use a Zigbee2mqtt stick?