Well no need for functions as far as i can tell - just one filter and two change nodes...
which I would argue is simpler than writing your own.
[{"id":"f162589ba24889b7","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"8629dac32f0ac352","type":"inject","z":"f162589ba24889b7","name":"","props":[{"p":"payload"},{"p":"lightid","v":"L1","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"On","payloadType":"str","x":140,"y":150,"wires":[["2a0d5979cdee5fcf"]]},{"id":"2a0d5979cdee5fcf","type":"rbe","z":"f162589ba24889b7","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"lightid","x":330,"y":240,"wires":[["21faae49b0c71370","85d240898546e208","b9e55b78a4b53459"]]},{"id":"21faae49b0c71370","type":"change","z":"f162589ba24889b7","name":"","rules":[{"t":"set","p":"lights[msg.lightid]","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":575,"y":180,"wires":[[]]},{"id":"149ca931fd4b9099","type":"inject","z":"f162589ba24889b7","name":"","props":[{"p":"payload"},{"p":"lightid","v":"L1","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Off","payloadType":"str","x":140,"y":195,"wires":[["2a0d5979cdee5fcf"]]},{"id":"53e4dd580ce39f06","type":"inject","z":"f162589ba24889b7","name":"","props":[{"p":"payload"},{"p":"lightid","v":"L2","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"On","payloadType":"str","x":140,"y":285,"wires":[["2a0d5979cdee5fcf"]]},{"id":"646c457519eabb09","type":"inject","z":"f162589ba24889b7","name":"","props":[{"p":"payload"},{"p":"lightid","v":"L2","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Off","payloadType":"str","x":140,"y":330,"wires":[["2a0d5979cdee5fcf"]]},{"id":"85d240898546e208","type":"link out","z":"f162589ba24889b7","name":"","mode":"link","links":[],"x":510,"y":270,"wires":[]},{"id":"040ab24a97263c25","type":"inject","z":"f162589ba24889b7","name":"Query L1","props":[{"p":"lightid","v":"L1","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":160,"y":420,"wires":[["5c8ed49550eed77c"]]},{"id":"5c8ed49550eed77c","type":"change","z":"f162589ba24889b7","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"lights[msg.lightid]","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":365,"y":420,"wires":[["f4940ad0951f7a19","5d13aff6ca09ccae"]]},{"id":"f4940ad0951f7a19","type":"link out","z":"f162589ba24889b7","name":"","mode":"link","links":[],"x":530,"y":420,"wires":[]},{"id":"f40b6b0269dcf9c0","type":"inject","z":"f162589ba24889b7","name":"Query L2","props":[{"p":"lightid","v":"L2","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":165,"y":465,"wires":[["5c8ed49550eed77c"]]},{"id":"5d13aff6ca09ccae","type":"debug","z":"f162589ba24889b7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":585,"y":465,"wires":[]},{"id":"b03c5e2504e1cc94","type":"comment","z":"f162589ba24889b7","name":"Use this for immediate updates","info":"","x":655,"y":225,"wires":[]},{"id":"1aaddd6c3624e495","type":"comment","z":"f162589ba24889b7","name":"Use this for queries","info":"","x":635,"y":375,"wires":[]},{"id":"b9e55b78a4b53459","type":"debug","z":"f162589ba24889b7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":565,"y":315,"wires":[]}]