24V signal switching optccoupler
Try a more efficient optoisolator. FOD817 for example only need 1mA  https://www.onsemi.com/pub/Collateral/FOD814-D.PDF  (24V - 1.2V)/.001 = 22.8K resistor, dissipating just 0.023W