Pool temp sensor - only when pump runs

I have installed an esp temperture probe next to mine pool pump.
I want a display, that shows the pool temperature only when the pump is running.
it would only be nice to show the last know temperature when the pump has run.

for the moment i have this set up:

    - name: "zwembadwater temperatuur filtered"
      unique_id: zwembadtemp_filtered
      icon: "mdi:coolant-temperature"
      unit_of_measurement: "°C"
      device_class: temperature
      state_class: measurement
      state: > 
        {% if is_state('light.pomp_verwarming', 'on') %}
            {{ states('sensor.zwembadwater_temperatuur') }}
        {% else %}
            Nb
        {% endif %}

Why?
because the temperature at the pump is not the correct value of the pool, pipes warm/cool down quickly)