Thank for the lengthy reply. Would one of these comparators work?

https://a.aliexpress.com/_vFHhhU
I have the data sheet for the sensor but can't upload it. It's 24v supply

Load capacitance max. at Ue1 µF Min.
operating current Im0 mA
No-load current Io max., damped5 mA
No-load current Io max., undamped2 mA
Operating voltage Ub10...30 VDC
Output resistance Ra33.0 kOhm + D Protection classII Rated insulation voltage Ui250 V AC
Rated operating current Ie200 mA
Rated operating voltage Ue DC24 V
Rated short circuit current100 A
Ready delay tv max.21 ms