Mutiple paths in single payload

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.

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;
}

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

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

2 examples (flow and function node):

example flow

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

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

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