Am I able to make a comparator on optocoupler?
Take something like below and add in current limit or protection circuit as necessary. Variations of this circuit are commonly found in isolated SMPS. The current limit box in the schematic can be a simple resistor if appropriate (when input range is not too great).

U1 can be replaced with a simple NPN transistor using the Vbe as the threshold. The accuracy would be lower, but from what you said it should be good enough.







simulate this circuit &ndash; Schematic created using CircuitLab