I like having a filament guide, but I wanted it to also act as a filament runout detector and put some tension on the filament so I don't get backups on my spool, which can cause tangling.
I started with this: https://www.thingiverse.com/thing:2917932
Print this thing so the hole is on z, standing up, and the arm lays flat.
I designed it so that it doesn't need supports to print.
You might have to drill out the filament hole, particularly if you get a lot of elephant foot or overextrusion on your printer.
You'll need to put a limit switch in it, the filament should trigger the switch when it is not empty.
Wire the base and the nc connector to the gnd / control pin of your octoprint server pi.
I had to drill out the holes to handle 2mm width bulges in the cheap PLA I use.
To observe and react to the switch, I used an octoprint plugin called Filament Sensor Reloaded: https://plugins.octoprint.org/plugins/filament_sensor_reloaded/
Alternately if you aren't using octoprint, I guess you plug it into your display controller acc pins and add it to marlin, but you're on your own there.
I used a cheap limit switch I had on hand, these are similar: https://www.amazon.com/Cylewet-20Pcs-Switch-Arduino-CYT1093/dp/B076GM7JQP
I'm planning on making an adaptation of this part for my flsun cube but I'm just going to make a different part since I have new limit switches with rollers which might be better for the minimal backpressure. I'll also redesign this thing so that it uses a piece of bowden tubing with a notch cut out of it for the guide.
If you're going direct to i/o then using a direct switch it's noisy so you either have to set a delay of 5000ms or make a less noisy circuit with a drop down 1k resistor and a 10K resistor tied to nc and 3.3v to c. Connect the 1k resistor to the i/o and the 10k to gnd. It will make way less noise and you can use sane delay values.
I probably should put a mount on it for an LED so we've got visual feedback on the state of the switch, but this was designed to be as simple as possible.