# Mutiple paths in single payload

**URL:** <https://discourse.nodered.org/t/mutiple-paths-in-single-payload/44641>\
**Category:** General\
**Created:** [24 April 2021 02:19 UTC](https://discourse.nodered.org/t/mutiple-paths-in-single-payload/44641 "2021-04-24T02:19:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stu1811](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@stu1811](https://discourse.nodered.org/u/stu1811)\
**Post date:** [24 April 2021 02:19 UTC](https://discourse.nodered.org/t/mutiple-paths-in-single-payload/44641/1 "2021-04-24T02:19:31Z")

</div>

I'm trying to trigger on a event from my Inovelli LZW30-SN (light switch). I only want to do something when payload.event.label == "Scene 003" and payload.event.value == "KeyPressed". What is the best way to do multiple conditions on the same payload with different paths? If possible I'd like to use a flow since I'm just starting my node red adventure.

Edit: I figured out how to use the function block and check for both paths then edit the msg payload. It's very clunky. I assume there is a better way..

Edit 2: I'm using now red in home assistant. Not sure if that matters.

```auto
if (msg.payload.event.label == "Scene 003" &&
msg.payload.event.value == "KeyPressed")
{
var yay_msg = msg;
yay_msg.payload.event_type = "yay";
return yay_msg;
}
else
{
var del_msg = msg;
del_msg.payload.event_type="none"
return del_msg;
}

```

---

<div class="post-metadata">

**Author:** ![leftymuller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leftymuller/32/102326_2.png) [@leftymuller](https://discourse.nodered.org/u/leftymuller)\
**Post date:** [24 April 2021 03:14 UTC](https://discourse.nodered.org/t/mutiple-paths-in-single-payload/44641/2 "2021-04-24T03:14:15Z")

</div>

Gday stu.. welcome to the forum

Pretty sure, if I read this right you could of achieved the same with a switch node with 2 outputs

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [24 April 2021 03:43 UTC](https://discourse.nodered.org/t/mutiple-paths-in-single-payload/44641/3 "2021-04-24T03:43:47Z")

</div>

You could consider creating an actual flow that builds the logic, easier to debug;

2 examples (flow and function node):

 ![Screenshot 2021-04-24 at 05.43.08](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/b/6be69ebc708a61ce7921333944492208b96ce3c6.jpeg)

example flow

```auto
[{"id":"a897ae3a.504908","type":"switch","z":"1735df89.7d022","name":"scene ?","property":"payload.event.label","propertyType":"msg","rules":[{"t":"eq","v":"Scene 003","vt":"str"},{"t":"eq","v":"Scene 004","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":396,"y":144,"wires":[["d11c944a.2030f"],[]]},{"id":"d11c944a.2030f","type":"switch","z":"1735df89.7d022","name":"Event Value ?","property":"payload.event.value","propertyType":"msg","rules":[{"t":"eq","v":"KeyPressed","vt":"str"},{"t":"eq","v":"KeyReleased","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":584,"y":120,"wires":[["68f64a94.0c8a84"],["e4a9b55a.dcab2"]]},{"id":"68f64a94.0c8a84","type":"change","z":"1735df89.7d022","name":"yay","rules":[{"t":"set","p":"payload.event.type","pt":"msg","to":"yay","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":96,"wires":[["f9d93252.3b527"]]},{"id":"e4a9b55a.dcab2","type":"change","z":"1735df89.7d022","name":"none","rules":[{"t":"set","p":"payload.event.type","pt":"msg","to":"none","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":144,"wires":[["f9d93252.3b527"]]},{"id":"f9d93252.3b527","type":"debug","z":"1735df89.7d022","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":962,"y":120,"wires":[]},{"id":"565e074d.a86eb","type":"function","z":"1735df89.7d022","name":"","func":"let event = msg.payload.event\n\nif (event.label == \"Scene 003\" && event.value == \"KeyPressed\"){\n msg.payload.event.type = \"yay\";\n}\nelse{\n msg.payload.event.type = \"none\";\n}\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":420,"y":312,"wires":[["8a61f0d3.a2a8f"]]},{"id":"8a61f0d3.a2a8f","type":"debug","z":"1735df89.7d022","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":578,"y":312,"wires":[]},{"id":"3cb432b8.2698f6","type":"inject","z":"1735df89.7d022","name":"scene 003 - keypressed","props":[{"p":"payload.event.label","v":"Scene 003","vt":"str"},{"p":"payload.event.value","v":"KeyPressed","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":196,"y":120,"wires":[["a897ae3a.504908"]]},{"id":"a8430db1.fcbff","type":"inject","z":"1735df89.7d022","name":"scene 003 - keypressed","props":[{"p":"payload.event.label","v":"Scene 003","vt":"str"},{"p":"payload.event.value","v":"KeyPressed","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":196,"y":288,"wires":[["565e074d.a86eb"]]},{"id":"bb9e7a66.ec0098","type":"inject","z":"1735df89.7d022","name":"scene 003 - keyreleased","props":[{"p":"payload.event.label","v":"Scene 003","vt":"str"},{"p":"payload.event.value","v":"KeyReleased","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":206,"y":168,"wires":[["a897ae3a.504908"]]},{"id":"17fbfc81.c626d3","type":"inject","z":"1735df89.7d022","name":"scene 003 - keyreleased","props":[{"p":"payload.event.label","v":"Scene 003","vt":"str"},{"p":"payload.event.value","v":"KeyReleased","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":206,"y":336,"wires":[["565e074d.a86eb"]]}]

```

---

<div class="post-metadata">

**Author:** ![stu1811](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@stu1811](https://discourse.nodered.org/u/stu1811)\
**Post date:** [24 April 2021 11:30 UTC](https://discourse.nodered.org/t/mutiple-paths-in-single-payload/44641/5 "2021-04-24T11:30:55Z")

</div>

Thanks for the flow. I was able to modify your flow to work. The relabeling at the end really helped.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [8 May 2021 11:31 UTC](https://discourse.nodered.org/t/mutiple-paths-in-single-payload/44641/6 "2021-05-08T11:31:29Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
