How do i override a DHT sensor's output with a global variable if values are NaN?

I want to have this since i want it to still display a value even if the sensor is not giving values (it turns into NaN in that case)
I dont have access to Home Assistant configurations right now.
Edited since i forgot something

A template sensor

template:
  - sensor:
      - name: "newtemperature"
        unit_of_measurement: "°C"
        state: >
          {% if states('sensor.bedroom_temperature') | float is defined %}
            {{ states('sensor.kitchen_temperature') | float | default(0)   }}
         {% else %|
            {{ states('sensor.newtemperature') | float   | default(0) }}
         {% endif %}

Use has_value().

Try:

    filters:
      - filter_out: nan