Trying to figure out the xiaomi aqara cube

I got it all working as well, shaking, flipping, etc. But I don’t use automations any longer, it’s node-red :slight_smile:

Hi Fribse, although it is an old tread, i’m curious how you have managed to create a flow with the cube and NR.
I trying it myself and relative new to node-red and I failed in setting a correct flow
i.e if I shake the cube (buttonevent 7007/gesture:1) i want to start a flow which controls turning the lights in certain states (some off, some dimmed etc). When I twist the cube clockwise… etc

Can you please share a flow, so I might see myself what I doing wrong

TY

Sure, I have the cube handled mainly by ControllerX (appdaemon 4), but special functions are set up in node-red.

There isn’t a specific trigger for deconz, so I have an ‘all events’ that filters for deconz.
The controllerid are found with developer tools by listening for ‘deconz_event’.


image

[{"id":"cb24aa54.603028","type":"server-events","z":"5943ae8c.07f6b8","name":"Deconz event","server":"6e6a992d.094ca8","event_type":"deconz_event","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":110,"y":160,"wires":[["cbb9daf6.30c008"]]},{"id":"cbb9daf6.30c008","type":"switch","z":"5943ae8c.07f6b8","name":"Which zigbee?","property":"payload.event.id","propertyType":"msg","rules":[{"t":"eq","v":"lians_magic_cube","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":380,"y":160,"wires":[["2b6f1ec3.464f6a"],[]]},{"id":"2b6f1ec3.464f6a","type":"switch","z":"5943ae8c.07f6b8","name":"Cube Gesture?","property":"payload.event.event","propertyType":"msg","rules":[{"t":"eq","v":"7007","vt":"str"},{"t":"eq","v":"7008","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":700,"y":160,"wires":[[],[]]},{"id":"6e6a992d.094ca8","type":"server","name":"KF Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

I have also set the cube up in ControllerX (under appdaemon) which is super easy:

lians_magic_cube1:
  module: controllerx
  class: MFKZQ01LMLightController
  controller: lians_magic_cube
  integration:
    name: deconz
    type: gesture
  light: light.dinnertable
  actions:
    - 3
    - 4
    - 6
    - 7
    - 8
2 Likes

:thinking:
Not sure if I can use this solutions for me

I have de Conbee2 on a separate pi running in a docker (so in case i have to restart HA my Zigbee and Zwave remains up).
I use Deconz and Phoscon to add devices and the Deconz integration in HA.
In node red I have installed node-red-contrib-deconz, so there is a special ‘trigger’.

And due to my lack of knowledge ‘how to use’ the deconz palette in Node Red I’m stuck at the moment. I was hoping you had used the same palette and I simply could copy (lazy me) a flow to understand the ‘how’.

I will try to find a solution using the palette in Node Red and if this gives me not the solution (or I just got frustrated :smirk:) I will give your solution a try.

In either way… thank you for sharing.

1 Like

Just to point out, the deconz only gets restarted if I restart the host, not the homeassistant itself, when it’s in an addon (container) on the ha host itself.

Hi @fribse,

Could you explain which special functions you set up in node-red? Is it because you cannot set them up in ControllerX? I see in the ControllerX config that you are just including some events and leaving others out.

Regards,
Xavi M.

Yes, the basic stuff I’ve put in controllerX, but for the shaking of the cube I want something different to happen depending on the time of day. This could be added as scripts and stuff, but for me it was just easier to leave it out of the controllerx, and put it in node red.

Thank you for your response @fribse, I totally understand! I just wanted to know the use case and how ControllerX could be improved for it.

1 Like

And don’t worry, I still LOVE the ControllerX, no doubt about it :smiley:

1 Like

Hi all, I read this thread with great interest - and I’m baffled by all the problems you all had to work your way through. When I got my cube, I paried it with deConz by simply pressing the link switch. never had to touch it at all. It showed up by itself in deConz, Phoscon and HA. And I don’t need to know anything about event numbers etc. to make fancy automations. I just use the automation UI in HA: It knows automatically everything the cube can possibly do - in clear English.

1 Like

Yes, a lot has happened since this thread. Most of the actions you see now, didn’t work back then.

I see - but shouldn’t threads like this be given some sort of “obsolete” tag so that innocent new readers don’t get completely lost and depressed ?

Well, you can see the problem was from the beginning of 20’s, and if you read the thread, you can also see that it moved to node-red instead, and that was a bit more tricky, but we got it working.

I just received an Aqara cube and set up a couple simple automations.

However it seems to disconnect from the network really easily. After initial pairing it was unresponsive after maybe an hour.

I tried swapping out the battery. I have a zigbee repeater nearby where I paired it and I’m maybe 4ft from my Zigbee USB device (HUSBZB-1). I also have an old SmartThings Button in the same area that has stayed connected to the network every since I paired it weeks ago.

I believe I have read some info that Aqara devices don’t necessarily follow the zigbee protocol very strictly.

Does anyone have insight on how to get it to pair and stay connected?

I have it connected to deconz, and I’m using IKEA lights. Xiaomi doesn’t play well with certain routers, I found quite a bit of info about it on hubitats pages somewhere, but can’t seem to recall where it was.

I think this is the info we’re both referring to.

Hmmm…well this sucks. Perhaps I’ll get some more zigbee repeaters and perhaps it will help.

EDIT: I happened to have some Osram Lighify lightbulbs collecting dust. Paired one up, cube came right back onto the network.

tried setting it up for volume control using node-red, but can’t really get it to work smothly… volume just jumps up and down :frowning:
this is the flow I tried:

[{"id":"77b5dd61.4f3574","type":"tab","label":"Magic Cube Controller","disabled":false,"info":""},{"id":"e0b7f28a.22a56","type":"api-current-state","z":"77b5dd61.4f3574","name":"Ceiling yeelight","server":"45aa0aee.37a7e4","outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.ceiling_yeelight","state_type":"str","override_payload":false,"override_data":true,"x":1260,"y":160,"wires":[["af239f79.fcdce"]]},{"id":"af239f79.fcdce","type":"function","z":"77b5dd61.4f3574","name":"New brightness","func":"if(msg.data.state == \"on\"){\n    brightness = msg.data.attributes.brightness;\n    if(msg.cube_direction == \"rotate_right\"){\n        new_brightness = brightness + 50;\n    } else{\n        new_brightness = brightness - 50;\n    }\n}else {\n    if(msg.cube_direction == \"rotate_right\"){\n        new_brightness = 1;\n    } else{\n        new_brightness = 0;\n    }\n}\nif(new_brightness > 0){\n    msg.light_action = \"on\";\n    msg.light_brightness = new_brightness;\n} else {\n    msg.light_action = \"off\";\n}\n\ndelete msg[\"payload\"];\nreturn msg;","outputs":1,"noerr":0,"x":1460,"y":160,"wires":[["4bec80e4.77d7a"]]},{"id":"4bec80e4.77d7a","type":"switch","z":"77b5dd61.4f3574","name":"On/Off","property":"light_action","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":1630,"y":160,"wires":[["6affe9bd.dd2938"],["cae7ec7b.f59a7"]]},{"id":"b877915d.3752b","type":"api-call-service","z":"77b5dd61.4f3574","name":"On + brightness","server":"45aa0aee.37a7e4","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.ceiling_yeelight\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":2000,"y":120,"wires":[[]]},{"id":"cae7ec7b.f59a7","type":"api-call-service","z":"77b5dd61.4f3574","name":"Off","server":"45aa0aee.37a7e4","service_domain":"light","service":"turn_off","data":"{\"entity_id\":\"light.ceiling_yeelight\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":2030,"y":180,"wires":[[]]},{"id":"6affe9bd.dd2938","type":"function","z":"77b5dd61.4f3574","name":"Construct data","func":"msg.payload = {};\nmsg.payload.data = {\"brightness\": msg.light_brightness}\nreturn msg;","outputs":1,"noerr":0,"x":1800,"y":120,"wires":[["b877915d.3752b"]]},{"id":"5154e3c.ae8e61c","type":"server-events","z":"77b5dd61.4f3574","name":"deconz_event s","server":"80dd2db5.4a879","event_type":"deconz_event","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"x":100,"y":40,"wires":[["c04971ff.220f9"]]},{"id":"c04971ff.220f9","type":"switch","z":"77b5dd61.4f3574","name":"magic cube remote","property":"payload.event.device_id","propertyType":"msg","rules":[{"t":"eq","v":"c7528717c61e7ec68bc3c9d3b5bad45f","vt":"str"}],"checkall":"false","repair":false,"outputs":1,"x":130,"y":140,"wires":[["547934e4.27392c"]]},{"id":"547934e4.27392c","type":"function","z":"77b5dd61.4f3574","name":"","func":"const code = msg.payload.event.event;\nlet action;\nmsg.code = code;\nconst codes = {\n\"side1\": [1002, 1003, 1004, 1005, 1006],\n\"side2\": [2001, 2003, 3004, 4005, 5006],\n\"side3\": [3001, 3002, 3004, 3005, 3006],\n\"side4\": [4001, 4002, 4003, 4005, 4006],\n\"side5\": [5001, 5002, 5003, 5004, 5006],\n\"side6\": [6001, 6002, 6003, 6004, 6005],\n\"push\": [1000, 2000, 3000, 4000, 5000, 6000],\n\"doubletap\": [1001, 2002, 3003, 4004, 5005, 6006],\n\"shake\": [7007],\n\"drop\": [7008],\n\"wake\": [7000]\n};\n\nfor (let a in codes) {\n    if(codes[a].includes(code)) {\n        action = a;\n        break;\n    }\n}\n\nif (!action) {\n    const strCode = String(code);\n    if (strCode.substr(1,2) !== \"00\" || strCode.length !== 4) {\n        action = code > 0 ? \"rotatecw\" : \"rotateccw\";\n        angle = Math.abs(code);\n        if(angle < 2500)\n            msg.adjust = 0.02;\n        else if (angle < 4000)\n            msg.adjust = 0.05;\n        else if (angle < 7000)\n            msg.adjust = 0.08;\n        else if (angle < 11000)\n            msg.adjust = 0.11;\n        else if (angle >= 11000)\n            msg.adjust = 0.15;\n        if(code < 0){\n            msg.adjust = msg.adjust * -1;\n        }\n    }\n}\n\n\nmsg.payload = action || \"\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":60,"wires":[["d6ca0236.8277"]]},{"id":"d6ca0236.8277","type":"switch","z":"77b5dd61.4f3574","name":"Action","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"side1","vt":"str"},{"t":"eq","v":"side2","vt":"str"},{"t":"eq","v":"side3","vt":"str"},{"t":"eq","v":"side4","vt":"str"},{"t":"eq","v":"side5","vt":"str"},{"t":"eq","v":"side6","vt":"str"},{"t":"eq","v":"push","vt":"str"},{"t":"eq","v":"doubletap","vt":"str"},{"t":"eq","v":"shake","vt":"str"},{"t":"eq","v":"drop","vt":"str"},{"t":"eq","v":"wake","vt":"str"},{"t":"eq","v":"rotatecw","vt":"str"},{"t":"eq","v":"rotateccw","vt":"str"}],"checkall":"false","repair":false,"outputs":13,"x":470,"y":160,"wires":[["b556706f.af85b"],["b556706f.af85b"],["b556706f.af85b"],["b556706f.af85b"],["b556706f.af85b"],["b556706f.af85b"],[],[],[],[],[],["54ccf67a.98f2e8"],["54ccf67a.98f2e8"]]},{"id":"b556706f.af85b","type":"change","z":"77b5dd61.4f3574","name":"Cube side","rules":[{"t":"set","p":"cube_side","pt":"flow","to":"payload","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":120,"wires":[[]]},{"id":"54ccf67a.98f2e8","type":"switch","z":"77b5dd61.4f3574","name":"Rotate action","property":"cube_side","propertyType":"flow","rules":[{"t":"eq","v":"side1","vt":"str"},{"t":"eq","v":"side2","vt":"str"},{"t":"eq","v":"side3","vt":"str"},{"t":"eq","v":"side4","vt":"str"},{"t":"eq","v":"side5","vt":"str"},{"t":"eq","v":"side6","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":630,"y":220,"wires":[["73c5a130.37d01"],[],[],[],[],[]]},{"id":"f8e45fd0.76688","type":"debug","z":"77b5dd61.4f3574","name":"target_volume","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"target_volume","targetType":"msg","statusVal":"","statusType":"auto","x":1040,"y":240,"wires":[]},{"id":"677a4b3c.3ab964","type":"api-call-service","z":"77b5dd61.4f3574","name":"","server":"80dd2db5.4a879","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_set","entityId":"media_player.denon_avr_x2100w","data":"{\"volume_level\": msg.volume + msg.adjust}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":890,"y":320,"wires":[[]]},{"id":"73c5a130.37d01","type":"function","z":"77b5dd61.4f3574","name":"get volume","func":"const globalHomeAssistant = global.get('homeassistant');\nmsg.volume = globalHomeAssistant.homeAssistant.states[\"media_player.denon_avr_x2100w\"].attributes.volume_level;\nmsg.target_volume = msg.volume + msg.adjust;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":830,"y":200,"wires":[["f8e45fd0.76688","677a4b3c.3ab964"]]},{"id":"45aa0aee.37a7e4","type":"server","name":"Home Assistant","legacy":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open"},{"id":"80dd2db5.4a879","type":"server","name":"Home Assistant","addon":true}]

I use controllerx for standard operations, that works nicely. But it isn’t fluent, as it’s still event driven, it’s not like turning a knob on the amp.

I have a couple of them and they work well in Node Red ( using a Sonof USB Zigbee):