Statistics/ value_max

Good afternoon.
I created "statistics" with the "value_max" of a temperature sensor. I want the period of time to be until I reset a switch. Does anyone know how to do it?
Ths

I don’t think this can be done with the statistics platform, but it can be done with a state-based template sensor.

Can you provide more detail on how you’d like the sensor to behave? What should it report when the switch is on and what should it report when the switch is off?

Good afternoon… I have this:

  - platform: statistics
    name: "Temperatura Max."  
    entity_id: sensor.temperatura_1
    state_characteristic: value_max
    max_age:
      hours: 4

In this example, the sensor takes the maximum value of the last 4 hours. I want it to register the maximum value and for it to count all the time until I press a button and it counts again from that time.

I don’t think what you want is possible with a template sensor due to the rewriting of having a moving time window (the last 4 hours).

I think your only option would be an SQL sensor but for that hopefully someone else can chime in. My SQL skills are minimal.