How to properly count 'pulses'

I’ve got a reflective sensor on an arduino nano (with serial-usb) that gives me a pulse (basically an X) over serial input every time it’s triggered.

This is linked to a sensor as

sensor:
  - platform: serial
    serial_port: /dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0
    baud_rate: 115200

Now, I get the things into HA … but how do i properly count this stuff?

Does the sensor change to a consistent value each time a pulse happens (and back to another value after the pulse)? If so, you could use a history stats sensor with the “count” option.

Nope. Just a value to say that it’s been triggered.

How about:

- trigger:
  - platform: state
    entity_id: sensor.serial_sensor
  action:
  - service: counter.increment
    entity_id: counter.serial_counter