I guess @zenofmud and @bakman2 already clarified the point but let me show an alternative approach. The way they explained requires the function node to be inserted in the very same flow as the ui_switch node.
Let´s say you want to read the status of the ui_switch inserting a function node in a separate flow (or separate tab). In such case you can bind a global context to the switch. Whenever you toggle the switch in the dashboard the global context value will follows.
In order to bind the ui_switch to the global context you use a status node like shown below.
Then you can read the value of the global context from any function node.
The good thing about this second approach is that you can recover the switch status at any time whereas the first approach will allow you to recover the switch status only after a toggle event.
Testing flow:
[{"id":"6fe46f15.c0819","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"2e1eb3b8.d447ec","type":"ui_switch","z":"6fe46f15.c0819","name":"Switch 1","label":"switch 1","tooltip":"","group":"f62442d8.46a67","order":3,"width":"3","height":"1","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":500,"y":80,"wires":[[]]},{"id":"12fa0c02.036b34","type":"status","z":"6fe46f15.c0819","name":"Status 1","scope":["2e1eb3b8.d447ec"],"x":120,"y":80,"wires":[["ab076d0b.7add6"]]},{"id":"ab076d0b.7add6","type":"change","z":"6fe46f15.c0819","name":"","rules":[{"t":"set","p":"sw1","pt":"global","to":"status.text","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":80,"wires":[[]]},{"id":"2e86a72f.c8af38","type":"function","z":"6fe46f15.c0819","name":"Read Switch1","func":"msg.payload = global.get(\"sw1\");\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":240,"wires":[["d734b5c6.a9db18"]]},{"id":"1af28f3f.cb1d11","type":"inject","z":"6fe46f15.c0819","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":240,"wires":[["2e86a72f.c8af38"]]},{"id":"d734b5c6.a9db18","type":"debug","z":"6fe46f15.c0819","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":240,"wires":[]},{"id":"477ec6f7.030f28","type":"ui_switch","z":"6fe46f15.c0819","name":"Switch 2","label":"switch 2","tooltip":"","group":"f62442d8.46a67","order":3,"width":"3","height":"1","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":500,"y":140,"wires":[[]]},{"id":"bd2aa4df.3e2038","type":"status","z":"6fe46f15.c0819","name":"Status 2","scope":["477ec6f7.030f28"],"x":120,"y":140,"wires":[["4a2c0e1a.27d59"]]},{"id":"4a2c0e1a.27d59","type":"change","z":"6fe46f15.c0819","name":"","rules":[{"t":"set","p":"sw2","pt":"global","to":"status.text","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":140,"wires":[[]]},{"id":"21425a8d.29ecf6","type":"function","z":"6fe46f15.c0819","name":"Read Switch2","func":"msg.payload = global.get(\"sw2\");\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":300,"wires":[["5d7060c0.8fa11"]]},{"id":"23c4b3c7.ad4d9c","type":"inject","z":"6fe46f15.c0819","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":300,"wires":[["21425a8d.29ecf6"]]},{"id":"5d7060c0.8fa11","type":"debug","z":"6fe46f15.c0819","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":300,"wires":[]},{"id":"f62442d8.46a67","type":"ui_group","z":"","name":"Default","tab":"43bbb3c.f37894c","disp":true,"width":"22","collapse":false},{"id":"43bbb3c.f37894c","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":6,"disabled":false,"hidden":false}]