You could try this, but I would encourage you to try "smart humidity fan" app. With your way, if a storm comes through, or depending upon humidity in the house, your fan might not come on or it might not turn off. I have had the fan turn on when I opened the windows on a mild, but humid day using a simple percentage.
With the app, it watches for a change in humidity, and once it rises at a certain rate, the fan turns on. It watches for the humidity to fall a certain amount, and starts a countdown timer, and then after the time turns off. It also turns the fan off after X minutes if you turn the fan on manually.
Search for bathroom fan. You'll find a few community apps. You can also do it with Rule Machine 4.0 and just a single rule. However, you'll want to compare against a reference humidity. Otherwise, you'll have a fan the comes on when the ambient humidity is too high (unless you live in a very arid climate).
However, I will say that on occasion, I have had the version 4.0 rule not function exactly as I expected, and the fan was on when it should not have been. Not sure why. But this two rule version made with Rule Machine 3.0 works perfectly all the time.