Categories

Keywords

Xiaomi cube in Home Assistant as remote control

Xiaomi cube with channel logos

Xiaomi cube with channel logos

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.

Hi! Have exactly the same configuration as you (HA + CC2531 + z2m + Aqara Cube), and I've got a problem with setting up of all this. At the moment I was able to reflash CC2531 with Z-Stack 1.2 and launch z2m, but then I can't pair cube with z2m (https://github.com/Koenkk/zigbee2mqtt/issues/3020#issuecomment-633549099). Also I found ZHA/zigpy, tried that and it doesn't work either. If you can post all your steps that you did to set this up - that would be really helpful! Thanks!I do not have the exact steps because I had the zigbee2mqtt running way before I added the cube. I am using the docker image koenkk/zigbee2mqtt and eclipse-mosquitto for the mqtt server - no special setup. Docker is running on an Odroid N2. Make sure the have the cube placed right next to the CC2531 when pairing. I also have an Ikea Hub and I need to turn that off when pairing new zigbee devices, because it will interfeer with the signal. Original the CC2531 was connected to an usb hub, and that was causing me a lot of problems. Probably because the hub was without power and the devices use too much power. After connecting it to a seperate dedicated usb port on the odroid it has been running without problemsHej Jens Super gode projekter du deler - mange tak for det. Jeg har kopieret Aquara cube setup’et og kan nu pause/play når jeg ryster cube og skue op og ned når jeg drejer. MEN jeg kan ikke hitte ud af at skifte radio station på min Sonos integration - media.select.source. Kan du dele af dine erfaringer/tips ???Jeg kender ikke til hvordan sonos virker, men eftersom den er en mediaplayer i HA burder den også kunne bruge media_player.play_media service funktionen - ligesom jeg har gjort med chromecast. media.select.source er til at skifte "source" som f.eks. på en forstærker hvor du kan skifte imellem hvilkem indgang der skal spilles.For Sonos, set media_content_type: 'music'hmm my side 2 URL will keep loading on 90 180 or tap , no other urls get loaded ?
(c) 2010-2023 dingus.dk