
Playing with Magic Cubes in Home Assistant
Well, In this post we are going to try to explain the whole process we need to start the magic cubes, these from Xiaomi or Aqara… and be able to use them to automate a task in our Home Assistant. Let's freak out!
We are talking about These cubes that you can buy cheap on Aliexpress or similar websites. They are amazing, We can use them to do the action that interests us, since we can know their position, or if we turn them, or if we throw them into the air, Or if we shake them, or if we double-click on them (with your fingers) on some particular face, or if we bang them on the table… Each cube has sensors that will allow us to know in detail what has been said, and we at Home Assistant can do the action that interests us.
Quick example, We put the logo of a radio channel on each of its faces, or Spotify lists (I don't know…), and it depends on which position you leave him in and double tap him, Or shake it 2 times against the table then that radio channel puts you on Volume and reproduces it with Snapcast on all speakers in your home. And if we throw it in the air and take it for music. And if we shake it up, it says over the loudspeakers that it's time to eat and that everyone at the table. And of course, If you want, If you turn it to one side or the other, Turn the volume up or down!
What we need? Well, a cube of the aforementioned ones that are Zigbee from Xiaomi Aqara and go with a CR2450 type battery. You may also need a Zigbee gateway like this one ConBee II. This is necessary to be able to set up a Zigbee net if you don't have one, and we can attach the cubes to our network so that we can detect their status.
We connect the gateway in the Home Assistant, if it is a Raspberry Pi then without problems on the USB and if it is a virtual machine then the same, but we will pass through to the VM from the host. We will have to know the device that is, how Home Assistant recognizes it; for this, since “Supervisor” > “System” > “Host System” > “Hardware” we'll have it and it'll put something like:
serial: ... - /dev/ttyACM0 - >- /dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DEXXXXXXX-if00 ...
So now we can install deCONZ, we will look for it from “Supervisor” > “Add-on Store”. And of course we install it. The only thing to keep in mind before starting the service is that in the “Configuration” we will then indicate who the Zigbee gateway appliance is, that is, the ConBee by means of this simple line:
device: /dev/ttyACM0
In the deCONZ Add-on click on “Open Web UI”, there to “Phoscon”.
We will need to set a password to access our Phoscon-GW,
And we ignore these wizards and close by pressing “Proceed without lights”,
Within the GUI we will go to “Devices” > “Switches” and click on “Add new switch”.
It will be time to pair our Zigbee device, in this case we are talking about a magic cube of these from Xiaomi. To do this,, We open the bucket carefully, It will have a slit on one side where we can put the accessory that came to us or a thin screwdriver to access a button that has, that we will simply press it 1 time.
After that, we will see how the cube detects us, Click on “Ready”, We already have it!
Now we can see in detail the state of the cube, where we will see the status codes and the angle of rotation.
Come, Let's play around now a bit and find out how the cube works, Let's see how I explain it… First things, The code is 4 Digits, The first digit will be the side of the face that is currently above. I recommend that you write the corresponding numbering on each side with a pencil. By turning the cube from side to side, code will show A00B, when A we have said that it is the current side that faces up, and B will be the side of the one who comes. If we slide it a little (Mild shaking) will replace us B with a 0. If we give you 2 tapping on or against the table/surface, B will replace it with A, Remaining A00A (I repeat, the A being the side that is facing upwards). If we shake it hard we will get the code 7007. If we throw it into the air and catch it we will get the code 7008. And so we spent the afternoon, We have some more code, but to start enough, isn't it?. We'll play around with the turns/angles another time.
Total, that if we go to our Home Assistant, we will see what the deCONZ gateway has detected, And if it doesn't, We can seek integration ourselves. In this case we would click on “Configure”. And I don't remember, But if the gateway doesn't detect you, restart Home Assistant and thus make sure to complete the cycle and it may detect it faster.
Yes baby, Say, “Send”,
And we click on “Finish” nothing, we don't put it in any particular area, Yes, that's it, Another day.
From Home Assistant, we will also be able to listen to the events broadcast by deCONZ, for this, since “Developer Tools” > “Events” > “Listen to events”, We write 'deconz_event’ and to “Start listening”. And we move the cube, etc and we will see how it reflects the result in the collected event.
And then it will be doing automations, so that depending on the code we get it does something, Play a song, a Spotify playlist, a TV channel… In this case, upon receiving the code 7007 Well, he will say over the speakers that it is time to eat, also with random phrases, so that I don't always bore with the same.
Then you put some stickers on it, or you print it and stick it and that's it! One more smart object at home, which is super curious and I'm sure that at home you like, or ideal for a gift to a geeky amig@, to do with the hij@s…