SmartThings Community

[RELEASE] Xiaomi Magic Cube Controller (Advanced DTH)

dth_remotes

#1

This is an advanced DTH for Xiaomi Magic Cube Controller.
It is based on code by @DroidSector and wouldn’t be possible without his work.

To pair your Xiaomi Magic Cube Controller with SmartThings HUB follow the instructions outlined here: Xiaomi Zigbee Outlet (Steps to Pair any Xiaomi Zigbee device!)

This DTH offers 3 modes of operation (that can be changed in the settings):

  1. Simple (set by default)- designed for backwards compatibility with previous DTH - presents only 7 buttons for basic gestures like shake, 90 degree flip, 180 degree flip, slide, knock, rotate right and rotate left.
  2. Advanced - presents 36 buttons for maximum functionality. Buttons are assigned as follows:
  • buttons 1 to 6 - “push” event on face 0 to 5 activation (corresponds to face pointing up)
  • buttons 7 to 12 - “push” event on slide gesture with faces 0 to 5 pointing up
  • buttons 13 to 18 - “push” event on knock gesture with faces 0 to 5 pointing up
  • buttons 19 to 24 - “push” event on right rotation with faces 0 to 5 pointing up
  • buttons 25 to 30 - “push” event on left rotation with faces 0 to 5 pointing up
  • buttons 31 to 36 - “push” event on shake gesture with faces 0 to 5 pointing up
  1. Combined - with this DTH will present 43 buttons assigned as follows:
  • buttons 1 to 7 - basic actions just like in Simple mode
  • buttons 8 to 43 - actions from Advanced mode moved by 7 positions.
    Just Keep in mind - in this mode DTH will send double button events on every action.

I recommend using the Advanced mode

DTH also offers emulated “Three Axis” capability for easy usage in SmartApps like Mood Cube. It is dependent on selected face and affected by limitation mentioned below.

Due to limitations imposed by data sent by the hardware there are some things to keep in mind:

  • The device sends orientation only on those gestures:
  • 90 degree flip
  • 180 degree flip
  • slide
  • knock
  • Because of that orientation data for rotation and shake events is based on last known orientation.
  • Device does not send any data if gesture is unrecognized - rotating the cube randomly in the air and placing it down will most likely not send any event.
  • The DTH will correct last known orientation and send missing flip/face activation events if needed as soon as it’s gets the orientation data form the device.
  • Due to the above rotation and shake events can execute for wrong faces if the flip gestures are not performed correctly (like rotating the cube randomly in the air)

[UPDATE] 2017-04-26

  • Fixed a bug that caused DTH to report wrong number od buttons.

Pics:

Link:


[RELEASE] Xiaomi Mi Cube / Magic Controller
FAQ: Full list of buttons and remotes confirmed to work with SmartThings
Xiaomi integration with ST's
Original & Aqara Xiaomi Zigbee Sensors (contact, temp, motion, button, outlet, leak, etc)
(DavidK) #2

Thanks!! Just installed and so far works great.

Question on battery, I am not getting battery. I think I am getting all other events.

All the other events work but just a dash for battery.


#3

It reports battery every hour or so. Just wait. But to be honest I’m not sure if the reading will be correct as it takes too much time to debug it (due to reporting only once every hour)


(DavidK) #4

Thanks for the device type.

My xiaomi buttons show battery, but the mood cube never showed battery with the other device type also.


#5

I’ve rewritten battery portion of this DTH completely. It reports battery for me but it reports it once an hour. Check in an hour if there is battery info.


(DavidK) #6

Thanks! I will!


(DavidK) #7

It just reported battery!!

Thanks!’


(Darren) #8

Nice work @ClassicGOD

I was looking at using core to use the cube to turn on lights by moving the cube and turning and twisting it, but didn’t get too far.

What type of device should i associate the Cube in core. I went through a few and from button I got some options but not many. Any advise would be most helpful.


#9

Hi.
Sorry! There was an bug in reporting the number of buttons that reported only 7 in advanced mode. I fixed it just now so you can update the DTH code and try again.

You should set up the DTH to Advanced Mode in Settings and then set up the Cube as button in Core and you should get 36 buttons to choose from :slight_smile: refer to the first post for information which button does what.


(Tim Raynor) #10

I’m getting this error code when I try to update…

groovy.lang.MissingMethodException: No signature of method: script1493237537944990010906.metadata() is applicable for argument types: (script1493237537944990010906$_run_closure1) values: [script1493237537944990010906$_run_closure1@4756a32d]
Possible solutions: getMetadata(), getState(), setState(java.lang.Object), metaClass(groovy.lang.Closure)

any ideas how to resolve please?


(Darren) #11

@ClassicGod, thanks for the info. I updated to the new DTH, checked to make sure my cube was in advanced and then went to core. Selected button, cube and attribute Button. I only get 7 button options.

If I understand you correctly, there should now be 36!!


#12

Make sure you pres Done not back on the settings page.


#13

Make sure you coppy the entire code form github using the “Raw” button on github.
I have no idea what this error is but no code line number points to it no being in my code.


(Darren) #14

@ClassicGod bingo, i moved from 36 to 7 and saved and then went back to 36 and re-saved (acting like it was cached), 36 buttons now showing up.

Quick question. Is my thinking right here:-

Button 1 = 0 Face
Button 2 = 1 Face
Button 3 = 2 Face

Therefore when 0 Face is up
Button 7 relates to slide on 0 Face
Button 8 relates to slide on 1 Face

Button 13 relates to knock on 0 Face
Button 14 relates to knock on 1 Face
etc


#15

Exactly correct :slight_smile:


(Darren) #16

@ClassicGod - cheers mate. Let the mayhem begin :slight_smile:


(Gavin Melling) #17

I’m going to swap to this DTH - as got a couple of minor annoyances with the old one.
Does anybody have a good use case scenario for the different sides yet and what have you done to mark them? Also what happens if you pick it up, flip it around lots looking for the right one then out it down. Does it detect ok?


#18

Read the hardware limitations in the first post. In short: it doesn’t. But if after doing all that you slide or knock the cube it will correct itself. Also if you flip it after that it will know the correct face.

It’s a limitation imposed by hardware. It simply doesn’t send any data after you do what you described.

When it comes to scenarios - Right now I’m rewriting my smartapps so my Cube is not assigned to anything but I had it set so 4 of the faces were assigned to colors (R G B and W) od my Fibaro RGBW and rotating left and right was changing the lever for a given color.


(Darren) #19

@ClassicGOD, worked like a charm. Just did a basic lights on twist left, lights off twist right, dim slide, shake brighten.

Now I’ve just get to get more inventive :slight_smile:

Would love to hear what configurations others are using the cube for. Love to pick up some ideas.


(Gavin Melling) #20

Thanks - I did read that and thought I understood it right, but wasn’t 100% sure.

I’ve got 2 lights I currently control as a group, with a “knock” to toggle SONOS as a bonus. I’m tempted to get rid of flips completely and have on the cube

“Both Lights”, “1st Light”, “2nd light”, “SONOS” then whichever is face up is what I control. But then I’m thinking I use this when half asleep and it might just be more annoying than useful. This is nothing against the DTH or the effort put into it; just my use case.