Is there any way to stop a template sensor being updated by its own change in value

I am trying to create a template sensor that evalluates the amount of spare power from our solar panels and uses it to run an electric fire.
The sensor needs to know the amount of power being used by the fire since as soon as the fire is on the ammount of availible power will aparantly reduce by that ammount.
I am trying to save this value as the old sensor output but the sensor will be re-triggered by this change when and will then run before the sensor measuring availible power has had time to reflect the change caused by the fire being on and will thus get the wrong value.
So is there any way to stop the sensor being trigfgered by the change to its own output
I have looked at saving the value in a ‘var’ but think the same problem will occur.

Basically i want the template to run when sensor.elec_import_export changes and not when sensor.elec_export_watts changes

code so far is :-


name: "elec_export_watts"  
         device_class: power
         unit_of_measurement: W
         state: >  
           {% set temp = states('sensor.elec_export_watts') | float(0)}         
           {% if(states('sensor.elec_import_export') | float(0) + temp <= 0.1) %}
             {% set output = 0 %} 
           {% else %}              
             {% set output = states('sensor.elec_import_export') | float(0) + OldOutput %}
             {% set output = output*1000 %}
             {% set output = output | int %}
           {% endif %}  
           {% if(output > 1000) %}
             {% set output = 1000 %}             
           {% endif %}        
           {{ output }}

Add a State trigger for the sensor you are interested in the change of.

Where is the value of OldOutput coming from… it’s not defined anywhere in what you shared?

Thanks for the reply
Afraid I left a bit off the end missing code is;

action:
             service: var.set
             data_template:
               entity_id: var.old_output
               value output

old_output is the last value computed by the sensor elec_export_watts.
The problem is that changing this value will also cause the sensor to run. The other sensors in the loop will not have time to react to the change and so the computed value will be wrong. I suspect the whole system will go into some form oscilation