Turn an Aqara cube into a physical remote for lights and an IR speaker
Map an Aqara cube's faces and twists to light brightness, colour and an infrared speaker in Home Assistant, with working YAML and the common gotchas to check for.

It is late, the lamp is too bright and slightly too blue, and the music is a notch too loud. Voice and phone apps are clumsy for "a bit warmer" or "a touch quieter". What you want is a dial. This post shows how we turned a Zigbee cube into one: a physical remote for a colour bulb, and a second cube for a speaker that only understands infrared.
Why a cube, and when not to bother
Smart buttons only give you presses. The Aqara Cube T1 Pro reports which face is up, whether you rotated it and by how many degrees, and whether you shook, tapped, slid or flipped it.
The rotation angle is the useful part. It makes the cube a dial, and the face that is up decides what the dial controls. Nothing to learn beyond "this face up, then twist", so anyone in the room can use it.
It also runs entirely locally, with no app, account or cloud. Nothing is automatic or guessed; we chose not to use presence sensors. We prefer intentional over automatic.
When not to do this:
- You only ever switch lights on and off. A plain wireless button is cheaper and simpler.
- You have no Zigbee setup and no wish to run one. The cube needs a coordinator and some software around it.
- You want the speaker half to be perfect. Infrared is one-way, so once in a while the stored on/off state will be wrong and someone has to fix it with one tap.
What you need
- A Zigbee cube. Aqara Cube T1 Pro, roughly ₹2,000 to ₹3,000 each in India (you need two to do both the light and the speaker).
- A Zigbee coordinator (a USB stick or a small network-attached one), roughly ₹2,000 to ₹4,000, and Zigbee2MQTT (free).
- An MQTT broker such as Mosquitto (free).
- Home Assistant (free) on a small always-on computer.
- A light Home Assistant can control with brightness, colour and colour temperature. Ours is a Tuya colour bulb running locally.
- For the speaker: an infrared transmitter Home Assistant can drive. Ours is a small ESP32 board with an IR LED and an IR receiver, roughly ₹500 to ₹1,000 in parts. An off-the-shelf IR blaster, roughly ₹1,000 to ₹2,500, does the same job.

How to set it up
1. Pair the cube and set action mode
Pair the cube in Zigbee2MQTT and give it a friendly name, for example Desk Cube. That name becomes part of its MQTT topic, so pick one you will keep. In Zigbee2MQTT, open Devices, your cube, the Settings (specific) tab, and set Operation mode to action. If twists never appear in the log, you are still in scene mode; the cube may need a shake to wake before the change takes.
2. Watch what it sends
Watch the device in Zigbee2MQTT or any MQTT client. A twist looks like:
{"action": "rotate_right", "action_angle": 45, "side": 2}
actionis the gesture:rotate_left,rotate_right,shake,flip90,flip180,tap,slideand a few more.action_angleis degrees of rotation. Positive is clockwise.sideis the face pointing up, as a number. Our Zigbee2MQTT numbers the faces 1 to 6; read the numbers off the log for your version before copying the face tests below.
Zigbee2MQTT merges the last side into every message, so even a shake tells you which face is up. And action is not cached, so filtering on the actions you want means a plain state republish never fires the automation.

3. Decide the mapping
Ours for the light cube:
| Face up | Twist changes | Rate |
|---|---|---|
| 1, 5 or 6 | Brightness | about 7.5 percent per quarter turn |
| 2 | Hue | 1 degree of hue per degree of twist |
| 3 | Saturation | about 15 points per quarter turn |
| 4 | Colour temperature | about 720 K per quarter turn |
| Any | Shake toggles on and off |
Clockwise always means more. Brightness gets three faces because people change it most. Only brightness works when the light is off, turning it on dimly; the colour faces do nothing.
4. Write the light automation
A trimmed version showing brightness only, with an example entity name:
- id: desk_cube_light
alias: "Desk cube: lamp controller"
mode: queued
max: 10
triggers:
- trigger: mqtt
topic: "zigbee2mqtt/Desk Cube"
conditions:
- condition: template
value_template: >-
{{ trigger.payload_json.action | default('') in
['rotate_left', 'rotate_right', 'shake'] }}
actions:
- variables:
act: "{{ trigger.payload_json.action }}"
side: "{{ trigger.payload_json.side | default(0) }}"
angle: "{{ trigger.payload_json.action_angle | default(0) }}"
- choose:
- conditions: "{{ act == 'shake' }}"
sequence:
- action: light.toggle
target: { entity_id: light.example_desk_lamp }
- conditions: "{{ side in [1, 5, 6] }}"
sequence:
- variables:
step: >-
{% set s = (angle / 12) | round | int %}
{% if s == 0 and angle > 0 %}{% set s = 1 %}
{% elif s == 0 and angle < 0 %}{% set s = -1 %}{% endif %}
{{ [[s, -50] | max, 50] | min }}
- condition: template
value_template: "{{ step != 0 }}"
- action: light.turn_on
target: { entity_id: light.example_desk_lamp }
data: { brightness_step_pct: "{{ step }}" }
The hue branch is the same block with hs_color and a (current + step) % 360 wrap, so you can keep turning round the colour wheel. Saturation and colour temperature swap the attribute and the step size. Shake is the light.toggle option already in the choose block.
What matters in it:
- Every change is relative, so the cube and the app never fight.
- Small twists still count. The
s == 0lines force at least one step. - Big twists are capped (50 percent for brightness, 90 degrees for hue), so a fast spin cannot jump from dim to full.
mode: queuedkeeps every twist. The defaultsinglemode drops triggers that arrive mid-run.max: 10stops a runaway queue.
For colour temperature, clamp to the bulb's own limits, and start from a neutral 4000 K if the bulb is in colour mode.
5. Turn the second cube into a speaker remote
Our desk speaker only understands infrared, so the second cube drives the IR board. Ours works like this:
- Flip so face 1 lands on top: input 1. This wins over the next two.
- Flip 90 degrees to any other face: input 2.
- Flip 180 degrees to any other face: Bluetooth.
- Twist: volume, one press per roughly 20 degrees, between 1 and 10 presses.
- Shake: power.
Capture the speaker's codes
Point the speaker's remote at the board's 38 kHz receiver and log each press, with IRremoteESP8266 or an ESPHome remote_receiver dump. Ours is an Edifier bookshelf speaker on the NEC protocol. Then expose power, volume up, volume down and each input as MQTT or ESPHome button entities.
The remote only has volume up and down, so a twist becomes a burst of presses:
- variables:
presses: "{{ [[((angle | abs) / 20) | round | int, 1] | max, 10] | min }}"
target_button: >-
{{ 'button.example_speaker_volume_up' if angle > 0
else 'button.example_speaker_volume_down' }}
- repeat:
count: "{{ presses }}"
sequence:
- action: button.press
target: { entity_id: "{{ target_button }}" }
- delay: { milliseconds: 250 }
The 250 millisecond gap stops codes merging into one long press. With 20 degrees per press, a quarter turn sends four or five volume presses.

6. Test without touching the cube
Publish a fake message and Home Assistant cannot tell the difference:
mosquitto_pub -h <broker-host> -u <mqtt-user> -P '<mqtt-password>' \
-t 'zigbee2mqtt/Desk Cube' \
-m '{"action":"rotate_right","action_angle":45,"side":2}'
We verified every branch of the light cube this way: each face, each direction, small and large angles, and two shakes. Test the speaker cube by hand as well, since the point there is whether the speaker responds. The automation's trace shows the branch, the step and the exact data sent.
What goes wrong
- Small twists or quick double twists do nothing. Force a minimum step and use
mode: queued, as above. - Colour drifts slightly after lots of twisting. Some bulbs report hue and saturation rounded. Keep your own running hue and saturation in an
input_numberhelper and write from that, instead of reading the bulb's rounded value back each twist. Or ignore it; the drift is invisible and only shows in the logs. - The speaker's power button toggles. One IR code turns it on and off, and infrared is one way, so Home Assistant cannot know whether the last press landed. Our bridge program keeps a saved on or off state and flips it for every power code, including the original remote's. Home Assistant sees a switch that only sends power when the stored state differs. Without our bridge: create
input_boolean.example_speaker_power, a template switch whoseturn_onandturn_offpress the power button only when the boolean differs and then flip it, and a 3 second delay after any power press. Choosing an input while off sends power, waits 3 s, then the input. - Commands right after power-on are ignored. We tested it: 2.5 seconds lost the next command, 3 seconds is the minimum our speaker needs. Measure yours.
- The stored state is wrong after a power cut. Add a way to set the state without sending IR. Our dashboard tile shows red for on and grey for off; a long-press on the tile corrects the stored state without sending IR. In plain Home Assistant, toggle the
input_booleandirectly from its entity card. If your device has separate on and off codes, or sits on a smart plug with power monitoring, most of this goes away.
Cost and time
Roughly ₹4,500 to ₹9,500 for one cube, a coordinator and an IR transmitter, approximate and varying by seller; add ₹2,000 to ₹3,000 for the second cube. That excludes the bulb and the small always-on computer Home Assistant runs on. Far less if you already run Zigbee. The light cube is an evening's work once paired. The speaker took longer, mostly power tracking and timing.
Worth it, with one caveat
Yes, with the infrared caveat: expect to tap the power tile now and then. The gestures are the fun part; the timing, state tracking and testing make it reliable.
If you would like physical controls like this in your office or your house, rather than another app, this is the kind of thing we build.


