I want to use previous received value from sensor, if current received value seems corrupt

Now and then I receive a corrupt temperature-value (from an arduino-mqtt - temperature component).
If the received value is not between -40 to 50 degrees celsius, I replace it with the value -1.
This is how the value_template looks like:
value_template:

{% if value_json.temperatur | float < 50 and value_json.temperatur | float > -40 %} {{ value_json.temperatur }} {% else %}-1.0{% endif %}

Is it possible to in stead of using -1, use latest value not considered corrupt?
(- I do not find how to refer to latest value displayed in my template-script…)

try using

{% if value_json.temperatur | float < 50 and value_json.temperatur | float > -40 %}
  {{ value_json.temperatur }}
{% else %}
  {{ states('<ENTITY_ID OF THIS SENSOR>') }}
{% endif %}

That did the job. Thank You :slight_smile: