Trigger if state has changed within a certain amount of time

Is there a way to monitor a state and trigger an automation to do something if the state has changes lets say 3 times in 10 seconds. IE toggle an input boolean if I flick a switch 3 times within 10 seconds.

You could use the wait_for_trigger three times in row

- wait_for_trigger:
    - platform: state
      entity_id: input_boolean.YOUR_ENTITY
- wait_for_trigger:
    - platform: state
      entity_id: input_boolean.YOUR_ENTITY
- wait_for_trigger:
    - platform: state
      entity_id: input_boolean.YOUR_ENTITY

Or you could create a counter.
Default 0
When counter changes from 0 start delay for 10 seconds
At end of delay reset counter to 0
Have an automation increment counter when you flick your switch
Automation triggers on counter reaching 3