Turn on fan by motion only if detected for 5 minutes

I have a sensor in a bathroom and want to turn on the fan if someone is in there for over 5 minutes. Is there a way to tell an automation to start if the sensor is triggered but delay it for 5 minutes if it’s continuing to detect motion? I thought about putting a delay in but if they leave the room before 5 minutes has passed will it still trigger after the 5 minute delay? My reasoning is no one turns on the fan when they are pooping so I want the fan to automatically turn on but not every time someone walks in the room. This is only a half bath so the only reason anyone would be in there longer than 5 minutes would be to poop.

You can accomplish that by using for (in a State trigger) or duration (in a Device trigger). Setting these variables changes the behavior of the trigger so that it only fires if the value is held for the defined amount of time.

Be aware that motion sensors can have different “cool down” periods. In some cases, a short cool down will cause the sensor to turn “off” even when someone is in the bathroom which mean you will have to use additional techniques, not just a duration setting.

I will try the duration and see what that does. Thanks for the reply.