Toggle Double-Click Action when Switch Turned On then Off (or Off then On) Within 1 Second

I am aware that there is a blueprint that I can use for a double-click action, but I want to trigger my double-click action when my binary sensor switches on then off in quick succession (or off then on in quick succession), as opposed to two ‘button pushes’.

I have a Shelly Plus One connected to my bathroom light switch. The lighting is automated using a presence sensor. I want to be able to switch to manual mode if I switch the light on then off (or off then on) within 1 second.

Here’s my automation:

alias: Motion - Toggle Auto Downstairs Bathroom Light
description: ""
triggers:
  - trigger: state
    entity_id: binary_sensor.downstairs_bathroom_lightswitch_input
    from: "on"
    to: "off"
  - trigger: state
    entity_id: binary_sensor.downstairs_bathroom_lightswitch_input
    from: "off"
    to: "on"
conditions:
  - condition: template
    value_template: >
      {{ (now() -
      states.binary_sensor.downstairs_bathroom_lightswitch_input.last_changed).total_seconds()
      < 1.5 }}
actions:
  - action: input_boolean.toggle
    metadata: {}
    data: {}
    target:
      entity_id: input_boolean.auto_downstairs_bathroom_light
mode: single

But of course, this performs the action on every state change, because it’s the state change that triggers the automation and therefore the template condition is always evaluated to be true. I only want it to be evaluated to be true if it’s the second state change, as it were.

Any ideas please? Thanks in advance.