Your idea quite clever, see attached sim.
Of course an LED >Diode (Reverse LED protection) > R on the AC side, photo transistor on the 5V side, would give
one approach. Essentially an opto coupler.
Not sure in either case UL impact, never having done a UL design.
Regards, Dana.