How can a template sensor only be updated on in a spesific condition

I am trying to make use of an indexed data registry with use of a template with this code pasted here. How can I avoid the template sensor value to be “0” when the condition is false. I want to keep the last value until next true condition.

The way it works now is that the sensor “bad_1etg_sp_romtemp” is reset when the condition “sensor.index_temp_sp ') | float == 1” is false

I’m sorry for the bad description, I’m at the very beginning of my Home-Assistant programming career

     # Bad_Kjeller Sp romtemp
      bad_1etg_sp_romtemp:
       friendly_name: "Bad 1etg Sp Romtemperatur"
       unit_of_measurement: '°C'
       value_template: >-
         {% if states('sensor.index_temp_sp')|float == 1 %} 
           "{{ (states('sensor.raw_temperatur_sp') | float * 10) | round(1) }}"
         {% endif %}

Read an example here.

The sensor get’s his own value if the condition isn’t true.

Thanks, this was the solution