Trigger automation based on persistent motion

I have an automation that turns the bathroom light and fan on when a Shelly motion detector detects motion. The problem I have is it turns both on even if someone simply throws something in the garbage, even if they don’t stay in the bathroom.

I’ve played with the duration value but that only seems to delay the automation.

Does anyone know how to configuration an automation to trigger only after persistent (someone is standing in the bathroom for 2-3 seconds) motion has been detected?

Thank you

  - platform: state
    entity_id: binary_sensor.bathroom_motion
    to: 'on'
    for: 3

This of course relies on your hardware motion detection turning off instantly when motion stops. Most do not do this, especially battery powered ones which can stay triggered for 30 seconds to 3 minutes to save battery power by not triggering continuously.

EDIT: yeah it looks like you are out of luck. The minimum you can set the Shelly to is one minute.

To be clear, this is a limitation of the hardware you have chosen, not Home Assistant.

You may be able to adjust the sensitivity setting of the Shelly to reject small movements.