Home Home Automation Xiaomi Aqara cube in NodeRED

Xiaomi Aqara cube in NodeRED

There is a cube in your NodeRED

I got the Xiaomi Aqara cube a couple of weeks ago. It’s a very creative controller which can be used to control lights or as a security system. To see what else the cube could be capable it was time to use Xiaomi Aqara cube in NodeRED.

Xiaomi Aqara cube in NodeRED

To use the Xiaomi Aqara cube in NodeRED you have to have the Xiaomi Mi Home Gateway. Read this article to learn the basic concept of sending the information back and forth between the gateway and NodeRED. You will need this to use the events from the cube.

Buy Aqara Cube

Buy it using these links to support NotEnoughTech.

How does Aqara cube work?

To save power, cube goes to sleep after 1 min of inactivity. When touched, the cube sends an alert message over the Zigbee protocol to the hub and it will start reporting the gestures. Thanks to this reporting I can intercept extra information than the Mi Home app.

When a debug node is connected to the gateway, Xiaomi Aqara cube in NodeRED will report with messages “report”. These will contain the cube information and the type of event that causes the cube to send the update.

	"cmd": "report",
	"model": "sensor_cube.aqgl01",
	"sid": "158d0xxxxxx",
	"short_id": 49508,
	"data": {
		"status": "alert"

The standard gestures are (status data available as msg.payload.data.status):

  • shake (“shake_air”)
  • push (“move”)
  • rotate (“rotate”:”XX,YYY”)
  • flip 90° (“flip90”)
  • flip 180° (“flip180”)
  • double tap (“tap_twice”)

Thanks to “report” entries we can also see:

  • “alert” – the moment where the cube is woken up
  • “plane rotation” – access to direction and degrees
List of all raw 'reports' from the Aqara Cube


{ "cmd": "report", "model": "sensor_cube.aqgl01", "sid": "158d0xxxxxx", "short_id": 49508, "data": { "status": "alert" } }





“flip 90 degrees”


“flip 180 degrees”


“double tap”


“rotate” – counterclockwise


“rotate” – clockwise


Looking at the Cube node available in the NodeRED – it acts just like a filter. It is designed to act only when a specific cube has passed the information and output the information in two available formats:

Just Values

	"status": "alert",
	"duration": null,
	"lux": null,
	"previous_status": "tap_twice",
	"voltage": 2.985,
	"voltage_level": "high",
	"time": 1546716697006,
	"device": "Cube"

As you can see, in this setting I have additional information about the battery voltage. This is great, as ideally, I’d like to be notified if the battery needs changing.

Full Data

	"cmd": "report",
	"model": "sensor_cube.aqgl01",
	"sid": "158d00xxxxx",
	"short_id": 49508,
	"data": {
		"status": "tap_twice"

In this mode, we get the raw output from the gateway. It’s interesting to see that battery information is not available even if I change the debug node to the “object” mode.

At first, I thought I could skip the Aqara cube node entirely, having the battery information is useful, and for now, I’m not aware of getting the battery information in any other way. Having the node deployed you can use the msg.payload.status to filter your gestures. Pay attention to rotation action as in this case the rotation info is stored in a different object. 

The flow above shows you how to intercept all the gestures. What’s great about NodeRED is that we can actually create contexts for the gestures itself. That way I can chain the gestures into 2-3 gesture commands multiplying the numbers of controls from 6 to over 12.

Nothing stops you from changing the way the controls work based on the room that you are in using ie Alexa’s or Google Assistant’s “The cube is in the kitchen”, “The cube is in the office”  commands enabling different devices for the motion control.

To couple up the controls you can use batcher node:

sudo npm install node-red-contrib-batcher

The node will await Xms for another input and couple the inputs together if another message arrives on time. If you shake the cube and tap it twice you will receive msg.payload:


Which can be used to control yet another device. I’d advise you to use this with less time-sensitive actions. You don’t want to perform 10 gesture routine just to put the lights on! I applied a filter to remove the “alert” message from the commands. Now that you know how to filter the gestures you can like the motion control to a smart socket, light bulb or other devices.


The Aqara cube becomes even more useful in NodeRED. Chaining commands and creating additional conditions enable extra functionality and fun ways to interact with everyday objects. Just imagine incredibly intricate alarm system where you have to shake the cube once, tap it twice, shake it again and push it to disable the sound! With that said… it’s time to shoot that video for Instagram 🙂 Did I mention, you can control computers with the cube too? Or generate online insults with a shake of the fist? Check this out.

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.


Nothing says "Thank you" better than keeping my coffee jar topped up!


Support me on Patreon and get an early access to tutorial files and videos.


Bitcoin (BTC)

Use this QR to keep me caffeinated in style with crypto-currency

Smart Ideas with

Automate your space in with these ecosystems and integrate it with other automation services

Learn NodeRED

NodeRED for beginners: 1. Why do you need a NodeRED server?

To server or not to server? That's a very silly question!

Best Automation Projects

ESP8266 WIFI lights under $5

Your Sonoff device can't do this!

Free wireless doorbell (Amazon Dash button hack)

The most terrifying situation I can imagine* is missing a parcel

New Amazon Dash Buttons

You can teach new buttons old tricks!

ESP8266 ceiling light – demo

Testing the ESP8266 as a WIFI light controller

Try Tasker and Raspberry Pi for your home automation needs!

Raspberry Pi can help you with your Tasker profiles

Smart Home

Army of robots: SwitchBot Curtain

An army of SwitchBot Curtains - adorable CurtainBots to open and close practically any curtains!

Zemismart Roller Shade Driver

Frustrated with UK's roller measurements I reached out for Zemismart Roller Shade Driver

Most affordable smart lightbulbs: Sonoff B02 & B05

ITEAD just dropped a range of very affordable smart Sonoff lightbulbs

Creepy Alexa for Halloween

Turning Amazon Echo into a Creepy Alexa monster for Halloween

How to make Sonoff ZB Mini and ZigBee2MQTT work together

It's time to make Sonoff ZB Mini and ZigBee2MQTT work together!