Couldn't this problem be stated differently, say:
When it's been 40 minutes since the last time the fan ran, turn it on for 20 minutes, like this: