I am not that familiar with the language for function nodes, I mainly use the other nodes to perform the functions I need without worrying about the specific syntax. What I am trying to get is a function node that gets triggered when a light switch is turned ON or OFF. I know that would be in the msg.payload information sent to the function node. What I want in the function node is it checks if the msg.payload is on or off and then it also checks multiple other light switches current state and depending on their states it changes other light switches states. Currently, I am doing with cascading state nodes checking each light switch in order. Is there a better way to do this in a function node or doesn't it really matter?
You can give each switch a topic, then join them to create a object containing all switch states. You would then be returned an object every time a switch changed state. You can then use the oibject for comparisons etc.
e.g.
[{"id":"511279040ece5903","type":"inject","z":"da8a6ef0b3c9a5c8","name":"one 0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"one","payload":"0","payloadType":"num","x":150,"y":1100,"wires":[["6a0c16c833aee61c"]]},{"id":"6a0c16c833aee61c","type":"rbe","z":"da8a6ef0b3c9a5c8","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":330,"y":1200,"wires":[["54d60b9bef3ea2e5"]]},{"id":"686bd12b66c4befc","type":"inject","z":"da8a6ef0b3c9a5c8","name":"one 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"one","payload":"1","payloadType":"num","x":150,"y":1140,"wires":[["6a0c16c833aee61c"]]},{"id":"c01a726c2759e556","type":"inject","z":"da8a6ef0b3c9a5c8","name":"two 0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"two","payload":"0","payloadType":"num","x":150,"y":1240,"wires":[["6a0c16c833aee61c"]]},{"id":"ac378acc7ed24a10","type":"inject","z":"da8a6ef0b3c9a5c8","name":"two 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"two","payload":"1","payloadType":"num","x":150,"y":1280,"wires":[["6a0c16c833aee61c"]]},{"id":"54d60b9bef3ea2e5","type":"join","z":"da8a6ef0b3c9a5c8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":470,"y":1200,"wires":[["217e27fd051a937f"]]},{"id":"217e27fd051a937f","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 118","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":1320,"wires":[]}]
Just up the count in the join node when you add a switch.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.