HomeHome AutomationXiaomi 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 with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

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

Nora – Google Assistant in NodeRED

Integrate Google Assistant with NodeRED thanks to Nora - NodeRED home automation

NEST your old thermostat under $5

Nest-ing up your older thermostat under $5

Tuya SDK for beginners: Intro to Tuya Cloud API

Working with Tuya Cloud API. A guide to Cloud automation for beginners, get started with REST!

Sonoff R3 DIY mode & why it sucks

Long awaited Sonoff R3 DIY mode is even worse than I expected.

Things they don’t tell you about IKEA Trådfri

There are things you should know about IKEA Tradfri before you make your purchase

Smart Home

Is Sonoff NSPanel the future we all wanted?

First look at Sonoff NSPanel - a touch screen display for your light switch! Is this the future of automation?

Getting started with Sonoff ZIGBEE 3.0 USB DONGLE PLUS

Testing Sonoff ZIGBEE 3.0 USB DONGLE PLUS against CC2531 and zzh (electrolama) - is it the best upgrade to your Zigbee network?

Can touch this: M5Stack Core2

M5Stack Core2 brings touch interface to the table, new UIFlow options which make programming super easy

Aqara Roller Shade Driver E1 & Zigbee2MQTT

Taking Aqara E1 apart, adding it to Zigbee2MQTT and NodeRED. This time with sunset/sunrise and temp controls

Testing Imou Ranger 2C 2MP & 4MP

Imou Ranger 2C comes in 2 flavours 1080P and 2K so let's compare them side by side and see which one is for you