I second the Smarter Humidity Fan app. The revised fork by @jtp10181 ....[APP] Smarter Humidity Fan *FORK for Testing* allows you to compare the bathroom humidity to another sensor, like the one in your hallway. I have been using it for some time and it works great.
This fork, like the original app developed by @erniemiller, allows you to set a max runtime on the fan. This option will shut off the fan if the lower humidity setpoint is not reached within a set amount of time.