The best time to replace the sensor is when changing the oil. IT is located on the driver's side of the oil pan.
The switch is electrical and mechanical. IT has a magnet and a reed switch. I have seen the glass part of the switch fill with oil and cause this situation.
ASE CERTIFIED MASTER AUTO TECHNICIAN
MERCEDES SPECIALIST 11 YRS