Turn something on for a set time

Think of the challenge in reverse. If something has been on for 10 minutes, turn it off. That what the State Trigger achieves in CO_4x4’s first example. It triggers after the light’s state changes to on and remains unchanged for at least 10 minutes.

Of course, if Home Assistant is restarted during that 10 minutes, the automation is reset and never turns off the light. The delay statement in the second example suffers the same fate.

That’s why it’s prudent to limit the use of for and delay to short periods of time in order to reduce the odds of being reset by a restart. For longer time periods, there are other techniques that can survive a restart (thereby making the automation more robust and reliable). What I posted is one way but there are others (such as Edwin_D’s suggestion to use a timer entity). Which is best depends on the application.

The following may interest you:

Evolution of an automation. Turn a light on/off at sunset/sunrise - Share your Projects! - Home Assistant Community (home-assistant.io)

FWIW, it’s fairly common for one automation to use multiple triggers to control equipment.