Zigbee2mqtt aqara cube nodered

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....

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:

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".

Testing flow:

[{"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":""}]
1 Like

Good morning Andrei,

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

1 Like

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.

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.