I have this flow. The UI switch is set by a signal from the LAN, but I also need to control it manually from the dashboard without generating a "loop", so I thought to include a "gate" function, but it is not working. The message is always passing thru.
[{"id":"c5bf3fb2.c7589","type":"inject","z":"fddf53d3.68236","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":240,"y":180,"wires":[["409f56cb.81b608"]]},{"id":"409f56cb.81b608","type":"ui_switch","z":"fddf53d3.68236","name":"","label":"Device","tooltip":"","group":"d98cf33c.c487e","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"gate","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":450,"y":60,"wires":[["5e469e53.4219b"]]},{"id":"5e469e53.4219b","type":"function","z":"fddf53d3.68236","name":"gate","func":"if (msg.topic === \"gate\") {\n return msg; // pass the message to following node\n}\n\nreturn null; // or drop it","outputs":1,"noerr":0,"initialize":"","finalize":"","x":650,"y":60,"wires":[["a419a442.0e8858"]]},{"id":"a419a442.0e8858","type":"debug","z":"fddf53d3.68236","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":60,"wires":[]},{"id":"d98cf33c.c487e","type":"ui_group","name":"Group 1","tab":"a0d76ec8.d2f6e","order":1,"disp":false,"width":"6","collapse":false},{"id":"a0d76ec8.d2f6e","type":"ui_tab","name":"Sinottico automazioni","icon":"mi-flip_to_front","order":1,"disabled":false,"hidden":false}]