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

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!

NEST your old thermostat under $5

Nest-ing up your older thermostat under $5

Nora – Google Assistant in NodeRED

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

Sonoff Zigbee Bridge – review

Sonoff line up will soon include Sonoff Zigbee Bridge and more Zigbee sensors - here is the first look

DIY Smart Washing Machine – for about 15 bucks!

Learn how to add washing machine notifications to your Google Home on the cheap

Smart Home

Sonoff ZigBee Bridge U isn’t what you think!

I expected Sonoff ZB Bridge U to be a next gen ZigBee bridge with Matter support. Turns out, there is much more to talk about!

Aqara “Everything” M3 Hub

When I started my home automation adventure, the current problem was the number of ecosystems needed to outfit your smart home. Aqara M3 Hub has a long list of protocols to match that!

Sonoff ZB Micro did it! (and bonus ZigBee device)

A long time ago, I took an angle grinder to the humble Sonoff Micro, will I do this again? Meet Sonoff ZB Micro and Sonoff ZB Contact (SNZB-04P) - the latest devices from the ZigBee ecosystem.

This keyless entry is PRO: SwitchBot Lock Pro

SwitchBot Lock Pro offers comprehensive upgrades over the original, combining enhanced design, stronger performance, and a faster mechanism for keyless entry

I damaged the cheapest Smart Socket with power metering for you

Sonoff S60 has an exeptional price for a smart socket with a power meter - I decided to check it out and see how flashable it is