History-stats: count - strange results

A simple sensor:

  - platform: history_stats
    name: number_of_on
    entity_id: input_boolean.test_boolean
    state: "on"
    type: count
    end: "{{ now() }}"
    duration:
      minutes: 5

Goal - count transitions “off → on” within 5 minutes.

And this sensor does not grow > 1.
Test card:

type: entities
entities:
  - entity: input_boolean.test_boolean
  - entity: sensor.number_of_on
  - type: custom:hui-history-graph-card
    hours_to_show: 0.08333
    entities:
      - sensor.number_of_on

If I toggle between “on/off” slowly, the sensor changes between 0/1:
x

Note - if the toggling id done quickly, the the sensor may become > 1.

I am 100% sure that this worked properly till some HA version.