Rooms Manager: Smarter Rooms: Personalized home automation with Occupancy

heres a simple one i am thinking of starting with in rooms manager:

if bathroom occupancy changes to vacant
   if humidity has gone up at least X% from when room changed to occupied or engaged then
      keep running exhaust fan till it goes down below humidity level set in the rules then turn off
   else
      if bathroom was occupied or engaged for less than Y minutes then
         turn off exhaust fan
      else
         run exhaust fan for at least Z minutes
      end if
   end if
end if