ESPHome adds a counter sensor for accumulating events such as pulses from a liquid-flow sensor. It can count each update from another sensor or each on transition from a binary sensor, and restores its saved total after a restart by default.
Clyde Stubbs also supplies actions to set the count or adjust it by a chosen amount. Counting sensor updates counts the events themselves, rather than adding the measurement values. J. Nick Koston reviewed the addition.