The simplest way is to use a virtual switch as a timer.
Create a virtual switch, and apply all of your rules that would turn the switch off to that virtual switch.
Set up the physical lights to follow the virtual switch, so that they turn on when it turns on, and turn off when it turns off.
That way, if you control the physical light through any other means, such as Echo, a minimote, or another SmartApp, The timer won’t turn it off. It’s only when you reference the virtual switch that you will get the automatic shut off.
There’s a how to article in the community – create a wiki that gives the steps for doing this.
http://thingsthataresmart.wiki/index.php?title=How_to_create_a_virtual_timer_for_a_light
Alternatively, you can get even more sophisticated rules with more complex overrides just by using core. You probably won’t need virtual switches for that one, but it is a more complex set up.
So depending on the exact details, either of those methods should work.