Turn off any smart bulb automatically after X minutes

I have FEIT smart bulbs at my home and for the most part they work very well with Alexa and Google Home app. What I am unable to figure out, for the life of me, is how to set all lights to close automatically after x amount of time they have been turned on. I know I can do that by going into each single one’s setting (I have over 30 so that is not an option). I want to set a routine/automation where if a light is turned on it shuts off automatically after X minutes. Is this achievable via Home Assistant?

You can create a for each action that loops over all lights and if one has been in on state for more than x minutes turns it off.

Another less elegant way could be to simply add them all as automation state triggers with the for parameter set to the desired max on time and the id as the light id. Then on a Call a Service action turn off the light entity by trigger.id.

Thank you. Do I have to specifically add each item in the foreach list or I can just say “foreach light” and execute the desired commands? Or something like “for all devices with type light”…