Ignore states with last_updated > x in Min/Max integration

I want to find out the coldest room in the house to control the heating. Since my temperature sensors are zigbee sensors and these do not always deliver reliable values, I would like to ignore individual sensors if they have not delivered any values ​​for >30 minutes. Does anyone have an idea how I can do this?

  - platform: min_max
    name: temperature_coldest_room
    type: min
    entity_ids:
      - sensor.aqara_room1_temperature
      - sensor.aqara_room2_temperature
      - sensor.aqara_room3_temperature
      - sensor.aqara_room4_temperature

I don’t think that functionality exists within the Min/Max integration, but you can do it with a template sensor.

template:
  - sensor:
      - name: "Temperature Coldest Room"
        state_class: measurement
        device_class: temperature
        unit_of_measurement: "°C"
        state: >
          {% set sensors = expand('sensor.aqara_room1_temperature',                               
          'sensor.aqara_room2_temperature', 'sensor.aqara_room3_temperature',
          'sensor.aqara_room4_temperature') %}
          {% set recent = sensors | selectattr('state', 'is_number')
          | selectattr('last_updated', 'gt', now()-timedelta(minutes = 30)) | list %}
          {% set low = recent | map(attribute='state') 
          | map('float', 0) | min | string  %}

          {{ recent | selectattr('state', 'eq', low) 
          | map(attribute = 'state') | join | float(0) | round(2) }}
        availability: >
          {% set sensors = expand('sensor.aqara_room1_temperature',                               
          'sensor.aqara_room2_temperature', 'sensor.aqara_room3_temperature',
          'sensor.aqara_room4_temperature') %}
          {% set recent = sensors | selectattr('state', 'is_number')
          | selectattr('last_updated', 'gt', now()-timedelta(minutes = 30)) | list %}
          {% set low = recent | map(attribute='state') 
          | map('float', 0) | min | string  %}
          {{ recent != [] }}


Thank you for your help!

  1. An ’ is missing in front of the sensor.aqara_room4_temperature. I was able to solve that myself :blush:

2. It seems the template returns 0 if a single sensor does not deliver a value within 30 minutes.
2. The template seems to return 0 if the sensor with the lowest temperature is not up to date

But I want only the one non-updated sensor to be ignored and the template to give me the lowest value of the remaining sensors

I have edited it above. I had accidentally left out one of the float-string conversions that is needed in the final comparison.

Still doesn’t seem to be working. Sometimes the min value goes to 0 without me being able to explain it.
Animation
Any idea?

It seems unlikely, but the only cause I can think of is that none of your sensors have updated within your defined window. Could some of them be related to restarts?

You should probably set an availability. That would get rid of the zeros, but the sensor would just report unavailable whenever there aren’t any values that are recent enough.