It don't start right away

I drive a 2003 Nissan Xterra. For the last 2 mornings I have gone out to start the car and all my electrical works and comes on but the car will not start. I have noticed that when I push the button or wiggle the automatic transmission shifter and try to start it again it usually starts right up. For the rest of the day it starts with no problem. Has anyone else had this problem, or know what it might be caused by?

There’s a switch that senses if the transmission is in park or neutral in order to allow it to be started. Sounds like it’s worn.

Thanks.