Counting a trigger within a set time

Hello, I would like to convert my Node Red flows back to Home Assistant now that I understand the automations better in Home Assistant. But I’m stuck on one flow. I have a light switch that, when I turn it on, off, on, and off again within 2 seconds it triggers a Boolean.

I’ve been trying different ways of doing this but can’t seem to find anything that works.

Does anyone have any suggestions on how I may achieve this in Home Assistant, please?

Thank you.

Probably use the wait for trigger.
So use state = on first.
Then in action wait for off, then wait for on, then wait for off and lastly wait for on.
You can probably just set the timeout on each individual step not the whole sequence.
So if you set the timeout at 1 second then you get three seconds in total.
Perhaps you can set it to a fraction, never tried it.

Wow thank you - that worked

This is my code for anyone else that may stumble across this post looking for help

alias: Kitchen Motion Controller - Trigger
description: ""
trigger:
  - platform: device
    type: changed_states
    device_id: 221f90dd55ddb4175888745737606064
    entity_id: light.kitchen_ceiling_light
    domain: light
condition: []
action:
  - wait_for_trigger:
      - platform: device
        type: changed_states
        device_id: 221f90dd55ddb4175888745737606064
        entity_id: light.kitchen_ceiling_light
        domain: light
    timeout:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
    continue_on_timeout: false
  - wait_for_trigger:
      - platform: device
        type: changed_states
        device_id: 221f90dd55ddb4175888745737606064
        entity_id: light.kitchen_ceiling_light
        domain: light
    continue_on_timeout: false
    timeout:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - wait_for_trigger:
      - platform: device
        type: changed_states
        device_id: 221f90dd55ddb4175888745737606064
        entity_id: light.kitchen_ceiling_light
        domain: light
    continue_on_timeout: false
    timeout:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: input_boolean.toggle
    data: {}
    target:
      entity_id:
        - input_boolean.kitchen_motion_controller
mode: queued
max: 10