Understanding the difference of optocouplers vs relays and choosing the right replacement
Optocouplers like the LTV-846 consist of an infrared LED and an NPN transistor. Output characteristics are similar to a normal bipolar transistor, except that Base current is created from light generated by the LED. This is not very efficient so despite the transistor's current gain the CTR (Current Transfer Ratio) is often less than 1.

In your circuit the LED current is about (5V-1.2V)/220&ohm; = 17mA, and the transistor has to switch 24V/1.5k&ohm; = 16mA. Therefore the CTR needs to be at least 1, preferably higher to ensure that the transistor is fully saturated for low voltage drop.

The LTV-846 is available in several 'ranks' depending on CTR. You should choose the B, C, or CD version, which have a minimum CTR of 2 or higher. 

If your supplier doesn't have the high CTR version or the price is too high then you have a few other options. One is to use the optocoupler to turn on another transistor in Darlington configuration. This has a minimum voltage drop of ~0.8V, which will reduce the resistor current by about 0.7mA at 24V. If this is a concern then you could reduce the resistance from 1.5k&ohm; to 1.4k&ohm;. 







simulate this circuit &ndash; Schematic created using CircuitLab

R4 ensures that the external transistor won't turn on due to leakage current from the optocoupler transistor. 

Since Q2's current gain is >40 you could reduce LED current, perhaps enough to eliminate the TPIC6C596. Raspberry Pi GPIO outputs have a recommended maximum output current of 3mA, which should be enough to reliably operate the circuit even with a CTR of only 0.5. R1 would then be ~(3.3V-1.2V)/3mA = 680&ohm; (nearest 5% value).