OK.
This is not perfect but here is a summary of the recipe to use the Mi / Aqara / Xiaomi Magic Cube in Home Assistant through Deconz. This is unique to Deconz!
First you pair the device in Phoscon. It seems to go best if you pair it while flipping and rotating it.
Deconz now actually created TWO devices. As they are created they will be called Switch## where ## is a number that depends on how many devices you have. Home assistant auto discover these.
It is a really good idea if you before restarting Home Assistant go to the Event viewer and listen for “deconz_event” and note which switch number is reported when to flip the cube or move it and which switch number is reported when you rotate the cube. If you rotate counter-clockwise you see negative event numbers. Note these two numbers and which does which.
The minute you reboot Home Assistant one of the two devices get renamed to the name that Phoscon/Deconz auto creates which is “Mi Magic Cube”. The other remains a Switch ##
What we need to do now is to rename these two devices in Deconz that that requires some hacking via the Rest API of Deconz. But don’t worry. It is geeky but easy when you follow this guide.
First we need to get an API key to be able to send rest commands to Deconz. You can create a new but the easiest is to use the one that Home Assistant has stored and uses. It is stored in …/.storage/core.config_entries
.storage is a hidden directory in the same directory where you have your configuration.yaml file.
Do a
cat core.config_entries | grep "api_key"
That should only return on line and that will be the api key for your Deconz
The easy way to send Rest API commands is to use curl from command line
The syntax is
curl -i -X PUT -H 'Content-Type: application/json' -d '{"parameter": "value"}' http://IP-address-of-Deconz:port/api/APIKEY/sensors/...
The port is 80 if Deconz is a standalone installation on bare metal and if you use the Home Assistant Addon the port is by default 40850
So the goal now is to change the names of the two sensors so that Home Assistant gets different names of events depending on rotation vs other gestures
So here is an example of changing the name of sensors 83 and 84 to Magic Cube Rotation and Magic Cube Gestures. The example IP is 192.168.1.15, Deconz as HA addon, and API key 0075B5E71E
curl -i -X PUT -H 'Content-Type: application/json' -d '{"name": "Magic Cube Rotation"}' http://192.168.1.15:40850/api/0075B5E71E/sensors/83
curl -i -X PUT -H 'Content-Type: application/json' -d '{"name": "Magic Cube Gestures"}' http://192.168.1.15:40850/api/0075B5E71E/sensors/84
If you did not record the numbers of the switches or do not want to re-pair, you can list all your sensors by simply looking up
http://192.168.1.15:40850/api/0075B5E71E/sensors
That returns all your sensors in a compressed JSON format which you can paste into a JSON beautifier (plenty of them on the net) and you can then find the two device numbers for your Cube
When you have renamed your two sensors you have to restart home assistant.
And then the gestures and rotation events should have the two names you chose.
It is a bit of a work around but at least it creates predictable names that you can use in many many automations. Should you ever need to re-pair the cube again, just repeat the renaming steps and all fits again even if the switch numbers changed.