Trigger notification if at least N events occur in interval

Greetings,
I’m quite new to HA, so I’m still getting used to building automations.
Let’s say I have an unreliable sensor that sometimes fires a single erroneous event, but if it fires more than 1 consecutive events in 30 seconds, it’s definitely real so I want to receive a notification.
I can easily do this in NodeRed as before starting with HA I built my own automations in NR, but I want to try out building “native” flows.
The “standard” way of doing this is basically the first event starts a timer and a counter of subsequent events - if the counter reaches a threshold, an alarm is raised. If the timer reaches its limit, everything is zeroed out.
My problem is I have no idea where to start…

One way is to use a wait for trigger action.

trigger:
  - platform: state
    entity_id: sensor.x
    to: y
condition:
action:
  - wait_for_trigger:
      - platform: state
        entity_id: sensor.x
        to: y  
    timeout:
      seconds: 30
    continue_on_timeout: false
  - service: notify.notify
    data:
      message: your message

This approach is better for events with relatively short intervals. If you need long intervals it would be better to use multiple triggers and use the If/Then or Choose actions.