If you add the capacitor and diode into the schematic, you do not have to worry about filtering the output of the OPTO.
You can now treat the signal on pin 2 as if it was any other switch.
If you need to, tune the value of C1 try: 1uF or 0.1uF or 10uF.