I have been using an HCPL3700 to detect 24VAC, but they are large and relatively expensive. I have tested the design shown in the figure (AC input to the diode, and measuring output collector-emitter voltage to determine if AC is on or off) and it works fine on the bench. My concern is that the diode in the optocoupler is not rated for use as essentially a rectifier. I use 12k resistors all around (capacitor is 10uF), so power dissipation maximum ratings aren't a problem. Can general purpose optocouplers (LTV-816 in this case) handle this duty?
Put a bridge in front (you can get a 0.8A bridge SMT mount for a very reasonable price) and you'll be able to detect the input faster than if you just block the current with a reverse diode. But do one or the other.
It's not a good idea to subject the optoisolator IR LED to reverse voltage in excess of the absolute maximum ratings.
There are also purpose-built AC-input optoisolators with back-to-back LEDs that are available in quad version and I would probably pick that option myself.
You must not apply a reverse voltage of more than 6 V to the LED. (In practice, the actual breakdown voltage will be higher than that, but 24 VAC certainly is high enough to be too risky.)
- use a bridge rectifier to route both half waves of the input through the LED, or
- connect an antiparallel diode to the optocoupler's LED pins to limit the reverse voltage to the forward voltage of the diode, or
- put a properly rated diode in series with the optocoupler's LED to prevent the LED from being destroyed by the breakdown current.