Switch as a bathroom fan timer in parallel with a humidity sensor

I replaced a mechanical timer switch with a smart one running Tasmota 9.5.0 and added a couple of automations with a Zigbee Humidity Sensor, one to turn the fan on if humidity rises above a threshold and another to turn it off when if falls below another (lower) threshold. The simple on and off actions still work at the physical switch.

In Tasmota, the rocker is configured as a button against one GPIO and the relay to another GPIO and switchmode is 0.

I’d like to add back the timer function so that if the fan is turned on with a long press or a double press, it waits a preset period and then turns the fan off. Ideally, it would ignore the fan-off-on-low-humidity automation during this period, guaranteeing a certain on period.

How do I go about doing this? I can draw a state diagram on paper but don’t know how to implement the automation.

Any guidance will be greatly appreciated.