# Too stupid to use switch node and/or function with Aqara magic cube T1 Pro :(

**URL:** <https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102>\
**Category:** General\
**Tags:** function-node, switch-node\
**Created:** [28 December 2023 20:23 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102 "2023-12-28T20:23:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ikarisan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ikarisan/32/86698_2.png) [@ikarisan](https://discourse.nodered.org/u/ikarisan)\
**Post date:** [28 December 2023 20:23 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/1 "2023-12-28T20:23:55Z")

</div>

Hi!

I hate to admit it, but I'm too stupid for the "switch-node". ☹  
I receive a msg.payload from my new "Aqara magic cube T1 Pro" that contains a msg.payload object with

payload.side : int (1...6)  
payload.action : string  
payload.operation\_mode : string (scene, action)  
[...]

I would like to switch depending on the "side" value. So I added a switch node with "msg.payload.side" as proptery. Then I added six outputs with number cases "== 1" till "== 6". But regardless of which value "side" has, the first output (side == 1) is always triggered.

I thought that I used the "switch-node" a wrong way. So I created a function node with a switch/case for "msg.payload.side" and six outputs. But again, the case of msg.payload.side seems to be always "1". The debug output of msg.payload.side clearly says otherwise. ☹

This is an example of the msg.payload, sent by the cube:

```auto
msg.payload =
{
	"action": "1_min_inactivity",
	"battery": 100,
	"current": 0,
	"device": {
		[...]
	},
	"last_seen": "2023-12-28T21:17:47+01:00",
	"linkquality": 134,
	"operation_mode": "scene_mode",
	"power": 1,
	"power_outage_count": 6,
	"side": 3,
	"voltage": 3177
}

```

Any ideas? 😉

---

<div class="post-metadata">

**Author:** ![meeki007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/meeki007/32/12499_2.png) [@meeki007](https://discourse.nodered.org/u/meeki007)\
**Post date:** [28 December 2023 20:30 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/2 "2023-12-28T20:30:56Z")

</div>

Are you sure your using a number (int) ? and not a string

 ![Screenshot from 2023-12-28 15-29-04](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/76d97033cb57276e2991f818dfff22af3ce91409.jpeg)

care to share your flow so we can import it 🙂

---

<div class="post-metadata">

**Author:** ![ikarisan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ikarisan/32/86698_2.png) [@ikarisan](https://discourse.nodered.org/u/ikarisan)\
**Post date:** [28 December 2023 20:49 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/3 "2023-12-28T20:49:27Z")

</div>

Yes, I am using "number". I would upload the flow, but as a new user I am not allowed to. ☹  
Here the inline version:

```auto

[{"id":"bf510de9c34b4fc2","type":"tab","label":"T1 tests","disabled":false,"info":"","env":[]},{"id":"16725a2ced4bf3d4","type":"debug","z":"bf510de9c34b4fc2","name":"Output Cube","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":950,"y":40,"wires":[]},{"id":"d5a17cf54d1a5eb3","type":"mqtt in","z":"bf510de9c34b4fc2","name":"","topic":"zigbee2mqtt/CubeT1","qos":"2","datatype":"json","broker":"c9d3faa6.3fe16","nl":false,"rap":true,"rh":"1","inputs":0,"x":180,"y":60,"wires":[["16725a2ced4bf3d4","6888240a1a195272"]]},{"id":"421b575a6df35bf8","type":"debug","z":"bf510de9c34b4fc2","name":"Seite 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.side","targetType":"msg","statusVal":"","statusType":"auto","x":940,"y":80,"wires":[]},{"id":"6888240a1a195272","type":"switch","z":"bf510de9c34b4fc2","name":"Seite 1-6","property":"payload.side","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"num"},{"t":"eq","v":"4","vt":"num"},{"t":"eq","v":"5","vt":"num"},{"t":"eq","v":"6","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":7,"x":580,"y":120,"wires":[["421b575a6df35bf8"],["4158c6d1a3366f6f"],[],[],[],["18ba52d91de89334"],[]]},{"id":"4158c6d1a3366f6f","type":"debug","z":"bf510de9c34b4fc2","name":"Seite 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.side","targetType":"msg","statusVal":"","statusType":"auto","x":940,"y":120,"wires":[]},{"id":"801a4591ca0efcea","type":"inject","z":"bf510de9c34b4fc2","name":"","props":[{"p":"payload.side","v":"6","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":230,"y":120,"wires":[["6888240a1a195272"]]},{"id":"18ba52d91de89334","type":"debug","z":"bf510de9c34b4fc2","name":"Seite 6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.side","targetType":"msg","statusVal":"","statusType":"auto","x":940,"y":160,"wires":[]},{"id":"c9d3faa6.3fe16","type":"mqtt-broker","name":"MQTT Server","broker":"10.10.0.42","port":"1883","clientid":"","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":"5","keepalive":"30","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

```

O.O

---

<div class="post-metadata">

**Author:** ![ikarisan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ikarisan/32/86698_2.png) [@ikarisan](https://discourse.nodered.org/u/ikarisan)\
**Post date:** [28 December 2023 21:01 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/4 "2023-12-28T21:01:31Z")

</div>

![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/d/cdf5a10f06cebde0bb372788be4fea7f9628d63c.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [28 December 2023 21:02 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/5 "2023-12-28T21:02:18Z")

</div>

> [@ikarisan](#):
>
> ```auto
> msg.payload =
> {
> "action": "1_min_inactivity",
> "battery": 100,
> "current": 0,
> "device": {
> [...]
> },
> "last_seen": "2023-12-28T21:17:47+01:00",
> "linkquality": 134,
> "operation_mode": "scene_mode",
> "power": 1,
> "power_outage_count": 6,
> "side": 3,
> "voltage": 3177
> }
> 
> ```

~~This is not a valid JSON, can we see a expanded debug of the payload.~~  
Scratch that i see you have posted one.

Your flow seems to work fine with the payload added in the inject node.

---

<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:** [28 December 2023 21:09 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/6 "2023-12-28T21:09:30Z")

</div>

> [@ikarisan](#):
>
> Here the inline version

That is the recommended way to post flows here.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [28 December 2023 22:25 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/7 "2023-12-28T22:25:57Z")

</div>

Your flow works fine for me too, once I put a debug node on the `msg.payload.side == 3` output

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [29 December 2023 07:33 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/8 "2023-12-29T07:33:44Z")

</div>

Isn't it ` msg.payload.object.side`?

---

<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:** [29 December 2023 09:43 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/9 "2023-12-29T09:43:24Z")

</div>

There is no object named `object` in that sample payload.

To avoid typos and simplify things, the op should use the tools provided:

### Canned text

There’s a great page in the docs ([Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

---

<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:** [29 December 2023 10:54 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/10 "2023-12-29T10:54:32Z")

</div>

> [@stefan24](#):
>
> Isn't it ` msg.payload.object.side`

The debug output is possibly a bit confusing there. Arguably it might be better if it said `payload` there.

---

<div class="post-metadata">

**Author:** ![ikarisan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ikarisan/32/86698_2.png) [@ikarisan](https://discourse.nodered.org/u/ikarisan)\
**Post date:** [29 December 2023 12:38 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/11 "2023-12-29T12:38:16Z")

</div>

Interesting. Output 1 is always triggered for me, even if msg.payload.side==3.

---

<div class="post-metadata">

**Author:** ![ikarisan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ikarisan/32/86698_2.png) [@ikarisan](https://discourse.nodered.org/u/ikarisan)\
**Post date:** [29 December 2023 12:46 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/12 "2023-12-29T12:46:02Z")

</div>

![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/f/7f55ed5c785e2e8a8c9c4b078c8f57d17ce1ccf1.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:** [29 December 2023 13:31 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/13 "2023-12-29T13:31:00Z")

</div>

> [@ikarisan](#):
>
> Output 1 is always triggered for me, even if msg.payload.side==3.

It is working ok for me

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/8/a8e938e078b6593a9267a623215a7fabb6832e00.png)

```auto
[{"id":"421b575a6df35bf8","type":"debug","z":"bf510de9c34b4fc2","name":"Seite 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.side","targetType":"msg","statusVal":"","statusType":"auto","x":940,"y":120,"wires":[]},{"id":"6888240a1a195272","type":"switch","z":"bf510de9c34b4fc2","name":"Seite 1-6","property":"payload.side","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"num"},{"t":"eq","v":"4","vt":"num"},{"t":"eq","v":"5","vt":"num"},{"t":"eq","v":"6","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":7,"x":580,"y":160,"wires":[["421b575a6df35bf8"],["4158c6d1a3366f6f"],["72ad560e4064d430"],[],[],["18ba52d91de89334"],[]]},{"id":"4158c6d1a3366f6f","type":"debug","z":"bf510de9c34b4fc2","name":"Seite 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.side","targetType":"msg","statusVal":"","statusType":"auto","x":940,"y":160,"wires":[]},{"id":"801a4591ca0efcea","type":"inject","z":"bf510de9c34b4fc2","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"action\":\"1_min_inactivity\",\"battery\":100,\"current\":0,\"last_seen\":\"2023-12-28T21:17:47+01:00\",\"linkquality\":134,\"operation_mode\":\"scene_mode\",\"power\":1,\"power_outage_count\":6,\"side\":3,\"voltage\":3177}","payloadType":"json","x":230,"y":160,"wires":[["6888240a1a195272"]]},{"id":"18ba52d91de89334","type":"debug","z":"bf510de9c34b4fc2","name":"Seite 6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.side","targetType":"msg","statusVal":"","statusType":"auto","x":940,"y":240,"wires":[]},{"id":"72ad560e4064d430","type":"debug","z":"bf510de9c34b4fc2","name":"Seite 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.side","targetType":"msg","statusVal":"","statusType":"auto","x":940,"y":200,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![ikarisan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ikarisan/32/86698_2.png) [@ikarisan](https://discourse.nodered.org/u/ikarisan)\
**Post date:** [29 December 2023 13:35 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/14 "2023-12-29T13:35:42Z")

</div>

It works fpr me, too if I inject the captured payload.  
But every time the device sends its own message output 1 and output 3 is triggered.  
Output 1 seems to be triggered by "msg.payload.side == 3" and output 3 is triggered by "zigbee2mqtt/Cube1: msg.payload.side == 3".

it doesn't matter whether side is 1,2,3,4,5 or 6. Output 1 reacts every time. ☹

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [29 December 2023 13:43 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/15 "2023-12-29T13:43:04Z")

</div>

Can you use a debug node to capture and share a message that doesn't work?

---

<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:** [29 December 2023 13:52 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/16 "2023-12-29T13:52:34Z")

</div>

And expand the device object please, at least to the next level

---

<div class="post-metadata">

**Author:** ![ikarisan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ikarisan/32/86698_2.png) [@ikarisan](https://discourse.nodered.org/u/ikarisan)\
**Post date:** [29 December 2023 13:55 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/17 "2023-12-29T13:55:24Z")

</div>

This is a compltete captured message from the device itself:

```auto
{
	"topic": "zigbee2mqtt/CubeT1",
	"payload": {
		"action": "1_min_inactivity",
		"battery": 100,
		"current": 0,
		"device": {
			"applicationVersion": 26,
			"dateCode": "20230303",
			"friendlyName": "CubeT1",
			"hardwareVersion": 1,
			"ieeeAddr": "0x54ef44100093e119",
			"manufacturerID": 4447,
			"manufacturerName": "LUMI",
			"model": "CTP-R01",
			"networkAddress": 35391,
			"powerSource": "Battery",
			"softwareBuildID": "0.0.0_0026",
			"stackVersion": 2,
			"type": "EndDevice",
			"zclVersion": 3
		},
		"last_seen": "2023-12-29T14:56:14+01:00",
		"linkquality": 87,
		"operation_mode": "scene_mode",
		"power": 1,
		"power_outage_count": 6,
		"side": 4,
		"voltage": 3141
	},
	"qos": 0,
	"retain": false,
	"_msgid": "cb2f205a85615b5f"
}

```

---

<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:** [29 December 2023 14:00 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/18 "2023-12-29T14:00:48Z")

</div>

That works for me if I paste it into an Inject mode set to `{}`.  
Can you stop node-red and start it again in a command window and paste the full output here please.

---

<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:** [29 December 2023 14:03 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/19 "2023-12-29T14:03:10Z")

</div>

Also could you change the debug node Seite 1 to output complete message and see what it shows.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [29 December 2023 14:11 UTC](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102/20 "2023-12-29T14:11:54Z")

</div>

Your image shows the output to debug node named `Side 3`

Not `Side 1`

Looks like the switch node is functioning correctly. Unless output 1 is connected to debug `Side 3`?

[Next page](https://discourse.nodered.org/t/too-stupid-to-use-switch-node-and-or-function-with-aqara-magic-cube-t1-pro/84102.md?page=2)
