This is especially true with light fixtures that use incandescent light bulbs. If the switch is off and light is on its probably a bad switch.
Motorcycle Alarm Number 3
Light switch turns off by itself. A manual mains switch with a coil inside that will flip it to the off position following the application of 5v for 50ms. When the switch falls down it breaks the circuit and turns off the light. After your car has failed to pass those 3 test it takes 40 passes in order for the light to turn itself off. Could be that the contacts in the switch have gotten loose and cant hold the switch in the up position. It is most likely just the switch that needs replacing and not a more involved electrical problem. For example you can use a finger to.
What is happening is the recessed can lights have a high temp safety switch mounted into the top of the enclosure which will turn the light off if it gets too hot. The light fixture then cools down and after a few minutes it will come back on. The answer is yes. It takes 2 failures for the light to turn on. When the switch falls down it breaks the circuit and turns off the light. If the switch is flipped on the either you or your wife have a sleep walking problem memory problem ghosts or one of those crazy people living in your closetattic.
This one by wemo will calibrate itself to any type of light bulb. Could be that the contacts in the switch have gotten loose and cant hold the switch in the up position. Omron has released such a thing. Unlike a latching relay the coil cannot set it to the on position. How about a mains switch that turns itself completely off. The switch also has some interesting design touches that place it ahead of the competition.
When some car system fails to pass a test the check engine light turns on.