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

“alert”

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

“shake”

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

“push”

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

“flip 90 degrees”

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

“flip 180 degrees”

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

“double tap”

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

“rotate” – counterclockwise

{"cmd":"report","model":"sensor_cube.aqgl01","sid":"158d0xxxxxx","short_id":49508,"data":{"rotate":"-27,500"}}

“rotate” – clockwise

{"cmd":"report","model":"sensor_cube.aqgl01","sid":"158d0xxxxxx","short_id":49508,"data":{"rotate":"3,360"}}

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:

["shake_air","tap_twice"]

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.

Conclusion

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.

PayPal

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

Patreon

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

image/svg+xml

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

client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image

Learn NodeRED

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

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

Best Automation Projects

Tuya SDK for beginners: Intro to Tuya Cloud API

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

NEST your old thermostat under $5

0
Nest-ing up your older thermostat under $5

Nora – Google Assistant in NodeRED

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

DIY Smart Washing Machine – for about 15 bucks!

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

Sonoff Zigbee Bridge – review

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

Smart Home

Remotes aren’t done with us yet: SwitchBot Remote

0
If you hate having 20 remotes hidden in your sofa, or your parents despise talking to Alexa to turn the lights on - SwitchBot Universal Remote is here to deal with all this!

We’ve seen this before: SwitchBot K10+ PRO

0
This is an odd one. Building on the success of SwitchBot K10+ they released SwitchBot K10+ PRO - but is the experience actually better?

Is this the smart panel we have waited for?

0
ITEAD has released a new smart panel: Sonoff NSPanel Pro 120 - have they learned the lesson from the terrible launch of the original Pro? Let's see what's new.

Aqara FP1E detects motionless humans

0
This isn't exactly a new device, it's an interaction of the original Aqara presence sensor. Aqara FP1E brings Matter, ZigBee and new triggers to your smart home

SwitchBot S10: cleaning re-imagined!

0
SwitchBot S10 promises unattended vacuuming and mopping so you can focus on things you love and care for. Does it deliver?