I don’t see any easy way to make that 817 module work. The GRBLDuino boards you were using would work if you replaced the 220 ohm (.11w @ 5v) input resistors with 4.7k (.12w @ 24v), the 1k pull-ups should be fine.
It took me a while to get the common anode input and switching to ground, e.g. 24v > 4.7k > PC817 pin 1, pin 2 is NPN signal or switch/touch plate + (switching to 24v gnd completes the circuit and triggers the PC817), pin 4 is the Arduino input which can have a 1 - 4.7k external pull-up (I’ve had no issues with just the internal pull-up), pin 3 is Arduino ground. Images already posted: Sometimes I get this happening - #12 by dalrun… Updated GRBLDuino image