I’m not sure this will help, because the original version contains now() if should evaluate every minute anyway.
What exactly do you mean by reset? The sensor that you had is 0 at every first minute of the day, and the average you had every other moment of the day. The template sensor does not affect any other value during the day. The trigger based one does pretty much the same, but it stays 0 until a new average sensor value comes in.
I think what you need is a statistics sensor that calculates the average of the thing that is being averaged. In that sensor you can specify what the period to be averaged is. If you already have an average, it is unclear what the time scope of that average is. You cannot remove information from how that was calculated.
You need to specify a template for datetime value min and max, and set it to keep the last recorded sample, because it might otherwise be undefined at midnight…
But shortly after it returns to the original value.
Let me explain what I am trying to achieve, This installation of HA is used in an old-dutch windmill. We use it to measure the speed of the mill when it is running. In such a mill we express the speed in enden/min (ends/min) An end is a blade passing by. If you divide it by 4, you get the revs/min. This works fine. Now we would like to see the average speed during a day, so evry midnight we start at 0 enden/min. And also if we stop the mill during the day for a few minutes (or longer) we donot want that to effect the average speed.
I do have:a sensor.‘endenteller’ that gives me the speed in enden/min
I created an extra sensor: molen_draai_snelheid_actief
pict2 shows what I want. The orange line show the actul speed. the blue line shows the average speed. The blue line going to 0 at app 11:20u is when I iomplemented your code yesterday.
What I want is what you see in pict2, but with the blue line going to 0 at midnight and staying there. (unless we start the mill again during the rest of the day
Since we did not know anything about your sensor then we can only answer you based on what you ask for.
And naturally if {{ s }} is not zero then it will just skip back up to the same value again.
I’m not sure I understand it all, but it seems as you need a utility sensor. Utility Meter - Home Assistant
Or base the template on sensor.molen_draai_snelheid_actief and not the other sensor (sensor.gemiddelde_molensnelheid_vandaag).