Functions in rules

That sounds like a situation in which the Expire Binding could be used. Please have a look at the following thread. @rlkoshak explains the usage at the bottom of the first post.
Design Pattern: Motion Sensor Timer