# Zigbee2mqtt aqara cube nodered

**URL:** <https://discourse.nodered.org/t/zigbee2mqtt-aqara-cube-nodered/19260>\
**Category:** General\
**Created:** [17 December 2019 14:37 UTC](https://discourse.nodered.org/t/zigbee2mqtt-aqara-cube-nodered/19260 "2019-12-17T14:37:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![berndmoerstedt](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@berndmoerstedt](https://discourse.nodered.org/u/berndmoerstedt)\
**Post date:** [17 December 2019 14:37 UTC](https://discourse.nodered.org/t/zigbee2mqtt-aqara-cube-nodered/19260/1 "2019-12-17T14:37:55Z")

</div>

Hi, I' a newbie on nodered.  
I try to switch my aqara-plug through my aqara-cube.  
Cube and plug are already registered on zigbee2mqtt (raspi).  
By Alexa-node and mqtt-out I can switch the plug already by voice. These construct was simple.  
But now I'have a problem how to tell my plug to turn on when I rotate the cube.  
With mqtt.fx I subscribed zigbee2mqtt/kubus and when I rotate the cube left  
{"battery":91,"voltage":2985,"linkquality":94,"side":4,"angle":-55.82,"from\_side":2,"to\_side":4,"action":"rotate\_left"}  
On the other hand zigbee2mqtt/plug/set switches my plug on and off.  
So which nodes should I use and connect ? mqtt-in, function, swicht?  
I googeled an red a lot over the last days. But I got no glue to solve my problem by myself.  
So please help me a little bit....

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [17 December 2019 16:19 UTC](https://discourse.nodered.org/t/zigbee2mqtt-aqara-cube-nodered/19260/2 "2019-12-17T16:19:07Z")

</div>

> [@berndmoerstedt](#):
>
> zigbee2mqtt/plug/set switches

You seems to be very close. I put together a proposed solution but I don´t have how to test for lacking an aqara-cube.

The flow would be something like below:

 ![a-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f81f297280a944204a965162dff7a47ba77fc5d3.png)

The upper part is just to simulate the aqara-cube.

The main part of the flow is the switch node that will extract the property msg.payload.action and set a new payload (on of off) depending if the action is "rotate\_left"" or "rotate\_right".

 ![a-02](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e17a8c2754a5cde9660b81f6cb63d7f77f8b624a.png)

Testing flow:

```auto
[{"id":"995fdf64.12d92","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"eca678b4.d6c798","type":"switch","z":"995fdf64.12d92","name":"Cube Action","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"rotate_left","vt":"str"},{"t":"eq","v":"rotate_right","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":260,"wires":[["d8de4f37.733dc","16e48f9a.9944c"],["97c9ba.9c040648","26c1a659.0dea4a"]]},{"id":"8ca98e9f.a30ee","type":"json","z":"995fdf64.12d92","name":"","property":"payload","action":"obj","pretty":false,"x":330,"y":260,"wires":[["eca678b4.d6c798"]]},{"id":"fc016a1.d875098","type":"mqtt in","z":"995fdf64.12d92","name":"","topic":"zigbee2mqtt/kubus","qos":"2","datatype":"auto","broker":"fa586ae2.bd1868","x":160,"y":260,"wires":[["8ca98e9f.a30ee"]]},{"id":"b8b442a6.b981f","type":"inject","z":"995fdf64.12d92","name":"rotate_left","topic":"","payload":"{\"battery\":91,\"voltage\":2985,\"linkquality\":94,\"side\":4,\"angle\":-55.82,\"from_side\":2,\"to_side\":4,\"action\":\"rotate_left\"}","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":60,"wires":[["f6a9c4d5.7ad348"]]},{"id":"f6a9c4d5.7ad348","type":"mqtt out","z":"995fdf64.12d92","name":"","topic":"zigbee2mqtt/kubus","qos":"2","retain":"false","broker":"fa586ae2.bd1868","x":410,"y":60,"wires":[]},{"id":"d8de4f37.733dc","type":"change","z":"995fdf64.12d92","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":240,"wires":[["704991e1.c304a"]]},{"id":"704991e1.c304a","type":"mqtt out","z":"995fdf64.12d92","name":"","topic":"zigbee2mqtt/plug/set","qos":"2","retain":"false","broker":"fa586ae2.bd1868","x":880,"y":260,"wires":[]},{"id":"97c9ba.9c040648","type":"change","z":"995fdf64.12d92","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":280,"wires":[["704991e1.c304a"]]},{"id":"521c544d.dd32ac","type":"mqtt in","z":"995fdf64.12d92","name":"","topic":"zigbee2mqtt/plug/set","qos":"2","datatype":"auto","broker":"fa586ae2.bd1868","x":220,"y":400,"wires":[["44d70096.efb1"]]},{"id":"44d70096.efb1","type":"debug","z":"995fdf64.12d92","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":480,"y":400,"wires":[]},{"id":"16e48f9a.9944c","type":"debug","z":"995fdf64.12d92","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload.action","targetType":"msg","x":670,"y":180,"wires":[]},{"id":"26c1a659.0dea4a","type":"debug","z":"995fdf64.12d92","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload.action","targetType":"msg","x":670,"y":320,"wires":[]},{"id":"db477138.800d5","type":"inject","z":"995fdf64.12d92","name":"roteate_right","topic":"","payload":"{\"battery\":91,\"voltage\":2985,\"linkquality\":94,\"side\":4,\"angle\":-55.82,\"from_side\":2,\"to_side\":4,\"action\":\"rotate_right\"}","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":100,"wires":[["f6a9c4d5.7ad348"]]},{"id":"fa586ae2.bd1868","type":"mqtt-broker","z":"","name":"Mosquitto","broker":"192.168.1.40","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<div class="post-metadata">

**Author:** ![berndmoerstedt](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@berndmoerstedt](https://discourse.nodered.org/u/berndmoerstedt)\
**Post date:** [19 December 2019 08:27 UTC](https://discourse.nodered.org/t/zigbee2mqtt-aqara-cube-nodered/19260/3 "2019-12-19T08:27:00Z")

</div>

Good morning Andrei,

and thanx a lot. It works! Wow.  
Switch, change and json together.  
I've to learn much more.  
Merry Christmas

---

<div class="post-metadata">

**Author:** ![queelyte](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/queelyte/32/30160_2.png) [@queelyte](https://discourse.nodered.org/u/queelyte)\
**Post date:** [25 August 2020 02:12 UTC](https://discourse.nodered.org/t/zigbee2mqtt-aqara-cube-nodered/19260/4 "2020-08-25T02:12:24Z")

</div>

I’m trying to get my aqara cube registered via ZHA on rasp pi in home assistant to rotate left or right to dim or brighten a light in 10% increments. Can you possibly help me create a flow for this. I am a node red newbie.

---

<div class="post-metadata">

**Author:** ![berndmoerstedt](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@berndmoerstedt](https://discourse.nodered.org/u/berndmoerstedt)\
**Post date:** [26 August 2020 12:36 UTC](https://discourse.nodered.org/t/zigbee2mqtt-aqara-cube-nodered/19260/5 "2020-08-26T12:36:57Z")

</div>

Hello queelyte,

sorry I was several day absent.....  
I can't help you by binding zigbee to homeassistant. I'm running zigbee2mqtt and nodred on my raspi.

---

<div class="post-metadata">

**Author:** ![ChrisF](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@ChrisF](https://discourse.nodered.org/u/ChrisF)\
**Post date:** [20 January 2023 19:31 UTC](https://discourse.nodered.org/t/zigbee2mqtt-aqara-cube-nodered/19260/6 "2023-01-20T19:31:46Z")

</div>

sorry for the question but somehow I have a problem with the Arara window contact:  
how can i extract the messages on and get only true or false and convert them to ON and OFF:

![Bildschirm­foto 2023-01-20 um 20.27.04](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/31592a775adeca1ff54b25be1c6afe7cbcaa5567.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 January 2023 09:56 UTC](https://discourse.nodered.org/t/zigbee2mqtt-aqara-cube-nodered/19260/7 "2023-01-21T09:56:44Z")

</div>

You could use a Switch node that sends the `true` out on one output and the `false ` out on the other. Then use Change nodes in those two paths to set msg.payload to string on or off. If you don't know how to do that then I assume you are a beginner to node-red so I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 January 2023 12:25 UTC](https://discourse.nodered.org/t/zigbee2mqtt-aqara-cube-nodered/19260/8 "2023-01-21T12:25:37Z")

</div>


