Help! Car starting weird!

I have a 2008 Nissan Sentra. For the past few weeks it acts up on a cold start (typically when I leave the house for work in the morning and again when I leave work 8-10 hours later). When I start the car the needle on the rpm gauge moves back and forth between 1 and 2 and the car revs a bit. This started happening just a few seconds before the needle would settle and the car would be good to go. As the weeks have gone on it now revs several times before either being good to drive or the car will turn off and I start over again. I took it in to a local mechanic who said it was the cam sensor. Replaced it for over 200$ and the car seemed okay for a week before the problem returned. Returned to the shop explained what was going on again and left it there for the day. The mechanic called to say he drove my car around for about 35 minutes and did not encounter the issue. This was confusing because as I had told him it only occurs about twice a day when my car has been sitting for several hours. Took the car home and it’s getting worse. I went to a car part store nearby to have the alternator, starter and battery tested and they said my battery was bad. Spent $160 on a new battery today and I let the car sit. After several hours I turned the car on and the problem is still there. I was told the starter and alternator tested fine. The mechanic said I can leave my car over night so he can start it up the next morning to see the problem firsthand. I’m losing my mind over this and cannot seems to find any videos or posts of similar issues to know where to look next. Any advice or help would be greatly appreciated!

When car acts up, check if engine temperature gauge jumps up and down too.
If yes, you might have a faulty temperature sensor, like this guy found on Pathfinder: https://www.youtube.com/watch?v=mZKxXg6jy-U

Thanks for the link to the video and the response! I will check the temp gauge when I start it up again in the morning!

Turned the car on this morning and the temperature gauge did not move up and down it seemed to act normal.