Adding a time filter to counter possible?

I have a simple counter that represents how many times a given task has been done in total.

I’d like to continuously calculate and display the sum of how many times the task has been done the last 7 days.

I’ve been looking at different helper types, but I’m not sure which one, if any, is the right fit.

I have the counter already defined and incrementing it accordingly. It represents the total.

Let’s say it’s currently 14.

What I’m looking for is how to calculate the total of increments made during the last 7 days, which could be, say, 8 or some such.

So you want the counter to reset every seven days?

You can do that with an automation.

You could also forego the counter completely and use this to automatically count the number of state changes in a week:

The total counter should keep counting and never reset.

But yes, Historical stats helper could work. I’m trying to test it by setting startdate to today and duration 7D.

The thing is that a counter can be increment and decremented. I don’t want just the number of state changes, but the sum of the time window. So the sum should ideally be sum of increments minus sum of decrements within the time window…

(I know that there could be other ways to solving this, for example such as maintaining a separate counter that represents. sum of 7 days coupled with long-running automations that span or wait 7 days to trigger, that will then remove the number they represent, but seems like a slightly over-engineered path and I’m currently more interested in solving it with the tools already present in HA).

You can’t use the History Stats sensor with a counter. You use it with whatever is incrementing the counter.