Counting values over a time interval ESPhome

I’ve seen similar topics about this issue but they all result in HomeAssistant solutions.
I was wondering if there was a way to easily count sensor values, which are strings, much like a moving average window. Where you select a window size and receive the average (in my case the count) for ON/OFF’s of that window size.

Right now, the only solution ive found is through lambdas and global values, which is fine.
Just wondering if there was a easier way than clearing the global every 15 mins.