Xiaomi cube in Home Assistant as remote control
The Xiaomi cube is a zigbee remote control (The official name is “Xiaomi Aqara smart home cube”). It can detect how you turn the cube (detect which face up is up), shake, tap and rotation. When I bought this I did not know exactly what I was going to do with it. I just thought it would be fun to play with it.
I have made it an internet radio remote control for a chromecast using Home Assistant automations. I have an internet radio channel on each side of the cube, and flipping the cube will start the channel facing up. I made channel logos on each face of the cube. Turning the cube will increase or decrease the volume. Shaking the cube will stop the audio.
This video is a small demo of how it works:
I have it connected to Home Assistant via zigbee2mqtt using a CC2531 usb stick. (I will not go more into details about this because that could be a big post by itself).
Home Assistant Automations
The following automation is for handling the flip and tap events:
alias: CubeFlip
trigger:
- platform: mqtt
topic: 'zigbee2mqtt/xiaomicube'
condition:
- condition: template
value_template: '{{ "flip90" == trigger.payload_json.action or "flip180" == trigger.payload_json.action or "tap" == trigger.payload_json.action }}'
action:
- service: media_player.play_media
data_template:
entity_id: media_player.chromecaststuen
media_content_id: >-
{% if state_attr('sensor.xiaomicube_action', 'side') == 0 %} http://live-icy.gslb01.dr.dk:80/A/A22H.mp3
{% elif state_attr('sensor.xiaomicube_action', 'side') == 1 %} http://live-icy.gss.dr.dk:80/A/A03H.mp3
{% elif state_attr('sensor.xiaomicube_action', 'side') == 2 %} http://live-icy.gss.dr.dk:80/A/A04H.mp3
{% elif state_attr('sensor.xiaomicube_action', 'side') == 3 %} http://live-icy.gss.dr.dk:80/A/A14H.mp3
{% elif state_attr('sensor.xiaomicube_action', 'side') == 4 %} http://radiojazzcopenhagen.out.airtime.pro:8000/radiojazzcopenhagen_a?1579041243843
{% elif state_attr('sensor.xiaomicube_action', 'side') == 5 %} http://live-icy.gslb01.dr.dk:80/A/A05H.mp3
{% endif %}
media_content_type: 'audio/mp4' </code></pre>
This automation will make the audio stop when you shake the cube:
alias: CuberShake
trigger:
- platform: mqtt
topic: 'zigbee2mqtt/xiaomicube'
condition:
- condition: template
value_template: '{{ "shake" == trigger.payload_json.action }}'
action:
- service: media_player.media_stop
data:
entity_id: media_player.chromecaststuen</code></pre>
This automation will turn up the volume when you turn the cube clock wise:
alias: CubeRotateRight
trigger:
- platform: mqtt
topic: 'zigbee2mqtt/xiaomicube'
condition:
- condition: template
value_template: '{{ "rotate_right" == trigger.payload_json.action }}'
action:
- service: media_player.volume_up
data:
entity_id: media_player.chromecaststuen</code></pre>
And here is the automation to turn down the volume when turning the cube counter clock wise:
alias: CubeRotateLeft
trigger:
- platform: mqtt
topic: 'zigbee2mqtt/xiaomicube'
condition:
- condition: template
value_template: '{{ "rotate_left" == trigger.payload_json.action }}'
action:
- service: media_player.volume_down
data:
entity_id: media_player.chromecaststuen
Notice the volume is just up or down. You can get a rotation angle from the cube events, but because the events a kind of slow (about 1 second) I could not get to work probably.
Battery lifetime
When I received the cube the battery was already in, and it died within 1 hour. Probably because if has been awake during all the transportation because of the movement. I have only been using it a few weeks so I can’t really say how good it is yet. I will write about it here when it dies. (The battery is a CR2450 3v)
Where to buy
If you want to have fun with it your self you can buy it here:
AliExpress.com – Xiaomi Aaqara Cube
AliExpress.com – Wireless Zigbee CC2531
Final notes
I have been using the cube now for a few weeks, and I really like it. I used to be controlling internet radio using a google home, but using the cube is faster, and I think I will keep using it. The only downside is that when it “goes to sleep” the tap event is not always happening. Flipping the cube will wake it, so I just have to switch channel twice (if I want to play the channel that is already facing up at the beginning)
You could also use it to control other stuff. Like have different light “Scenes” for each face of the cube. The events a a bit slow so using the rotation for dimming lights up/down is probably no so good an idea unless you do it in a few predefined levels.
Comments
The comments below has been imported from the old website. Currently comments are readonly, meaning you can not make new comments. You will be able to do that when it is ready. For now if you want to get in touch, you can send me an email. If you have problems with something that has a github repository, please make a github issue.