Ensure no light stays on more than x seconds


I want to ensure that no light in or outside the house stays on for more than a certain amount of time e.g. 5 minutes. It happens from time to time that a sensor drops or notification is just missed and one motion driven light stays on.

Is there a possibility to have a blue print which selects all lights in HA and traces how long they are switched on, and switch them off after a configurable amount of time? Would be very very helpful.