Context-aware temperature sensor for sauna (glitchy inside sensor when off)

Hi all,

I’m trying to build a context-aware temperature sensor for an electric sauna, and I’d like some feedback on the right approach in Home Assistant.

Background / problem

I have two temperature sensors:

  • sensor.temperatuur_sauna
    → inside the sauna
    reliable when the sauna is ON
    unreliable when the sauna is OFF (it keeps reporting very low values like ~2 °C instead of becoming unavailable)
  • sensor.temperatuur_buiten_sauna_auro
    → outside, near the sauna (still inside a building)
    → always reliable
    → good proxy once the sauna has fully cooled down

I also have a binary sensor:

  • binary_sensor.sauna_operating_message
    on when the sauna is actively operating
    off when it is not

This combined temperature is used for ETA calculations and scheduling, so it must be predictable and not jump to nonsense values.


Functional goal

What I want conceptually:

  1. Sauna ON
  • Always use the inside temperature
  1. Sauna OFF, short time ago (grace period, e.g. 15 min)
  • Still use the inside temperature - use the last meaningful value (any value above 20 degrees is valid);
  • Do not immediately switch to outside
  • The sauna does not cool down instantly
  1. Sauna OFF, longer than grace period
  • Use the outside temperature
  • At that point it’s a better approximation than the stale inside sensor

Important nuance:
The inside sensor does not become unavailable when wrong — it keeps reporting plausible but incorrect values (like 2 degrees Celcius). So this cannot be solved with simple availability checks.

What is the clean, maintainable HA way to model this kind of contextual sensor?

If anyone has solved a similar problem (e.g. ovens, saunas, hot tubs, boilers with bad sensors when idle), I’d love to hear how you approached it.

Thanks!

So add an availability key to the sensor that if it reads below X, make it unavailable?

Here’s one way:

template:
  - sensor: 
      - name: Combined Sauna Temperature
        unique_id: fe60a754-5039-4e59-9031-456f137a099e
        unit_of_measurement: "°C"
        device_class: temperature
        state_class: measurement
        state: >
          {% if is_state('binary_sensor.sauna_operating_message','off') and now() - states.binary_sensor.sauna_operating_message.last_changed > timedelta(minutes = 15) %}
            {{ states('sensor.temperatuur_buiten_sauna_auro' }}
          {% else %}
            {{ states('sensor.temperatuur_sauna' }}
          {% endif %}

If the sauna operating binary sensor is a template sensor then the template above can be simplified by including a delay_off option of 15 minutes in the template binary sensor. That way there would be no need to check for last_changed and the template if condition test becomes:

          {% if is_state('binary_sensor.sauna_operating_message','off')  %}

That was indeed the solution. I was trying to solve everything by building all logic in one template sensor.

But now I created one template sensor that is only available when the sauna is actually on (availability: {{ is_state(‘binary_sensor.sauna_operating_message’, ‘on’) }}).

And then I could create a second, contextual sensor that can work with the last valid state of the previously created sensor.

Thanks!

Thanks for trying to help. However, the logic I needed is more complex than that. In that 15 minute window, it should not just take the current temperature from the inside-sensor, but it should take the temperature from (up to) 15 minutes ago.