For this situation, and similar ones, there are simple solutions. For example, in this situation, the timer should always be running (and resets when the light changes). When a car triggers the sensor, the light should change if the timer is > N. If the timer is not there yet, wait until timer is N.
No AI required, just basic thoughtfulness and requirements gathering.