Hello selfless helpers. So I am attempting to call services from a variety of deCONZ events published by a Aqara Cube. The issue is I can’t use a switch node until I filter or merge all these possible events. I mean I could but It would have like 40 outputs and get sloppy.
I was planning to use a function node but I am not the best with them. My question is how would you use a function node to change payload.event.event, which can multiple numbers like 1006,2005,3004,4003,5002,6001… and then set any of those events to a specific payload like “flip90”. Then I can use a switch node to output the flip90, flip180 etc.
I am guessing it’s something like: if (msg.payload.event.event, and then a set payload or sometithing, but I am unsure how to do it with multiple events coming in or how to even do that all all.
Does this make any sense? Thank you so much for any help.
Thank you Wally. Unfortunately for me I am worse with Java than Node Red. But you did inspire me to scour stackflow for a deeper dive into function nodes and javascript.
I was able to come up with a fix. Not sure if it is the most efficient but it works.
What I did was first use a change node and set msg.payload.event.event to the payload. Value of event. Then it goes through the switch where I used a JSON expression which is basically: msg.payload = 1002 or msg.payload = 1003 or msg.payload = 1004 etc. Then the switch can route the correct number through the output.