They are not this simple; if so, an RLS (Rain / Light Sensor) assembly would cost 50 cents. To do a proper job, you need an array of IR emitters, and an array of detectors; and they need to be properly integrated into your windshield glass.
The RLS is usually a part of the rearview mirror supporting structure.
It also has to also work for hail and snow/sleet. Again, it's not as simple as you suggest.