With UP Plus2 you get the "auto bed leveling" sensor, it's a 3d printed piece with a microswitch, banana connector and a magnet. You normally attach it with magnet under the extruder motor and run the bed leveling calibration. I'm using the same switch as a filament runout sensor.
Print the switch.stl, push 2 short pieces of 4mm PTFE tube inside two holes (make sure middle is free) and clip in the bed leveling sensor. Thread the filament trough the device and voila, filament in - the switch is pressed, filament out, switch is open :D
Now how to handle the signal from the switch is another issue (not for Thingiverse but what I do is I use the octoprint and filament runout plugin that reads the switch connected to the RPi - actually I use OrangePi but same thing)
Source available on onshape
NOTE: if you don't have the UP provided auto bed leveling sensor this part will don't work for you (the actual piece holding microswitch will be missing)