Hi everybody here is my template sensor, inside the template file i already use:

```
- sensor:
- unique_id: critic_room_temp
device_class: temperature
name: "critic room temp"
icon: mdi:thermometer
unit_of_measurement: "°C"
state: >-
{% set a=( states('sensor.casa_temperatura_realmente_percepita')|float(0) )|round(1) %}
{% set b=( states('sensor.terrazzo_termometro_temperatura')|float(0) )|round(1) %}
{% set c=( state_attr('climate.camera_vittorio_termosifone_termostato','current_temperature')|float(0) )|round(1) %}
{% set d=( states('sensor.camera_padronale_termometro_temperatura')|float(0) )|round(1)%}
{% set e=( state_attr('climate.salotto_pranzo_termosifone_termostato','current_temperature')|float(0) )|round(1) %}
{% set f=( states('sensor.cucina_termometro_temperatura')|float(0) )|round(1) %}
{% set g=( states('sensor.bagno_bianco_termometro_temperatura')|float(0) )|round(1) %}
{% if a <=22 %}
{% if b <= c and b <= d and b <= e and b <= f and b <= g %}
{{ b }}
{% elif c <= b and c <= d and c <= e and c <= f and c <= g %}
{{ c }}
{% elif d <= b and d <= c and d <= e and d <= f and d <= g %}
{{ d }}
{% elif e <= b and e <= c and e <= d and e <= f and e <= g %}
{{ e }}
{% elif f <= b and f <= c and f <= d and f <= e and f <= g %}
{{ f }}
{% elif g <= b and g <= c and g <= d and g <= e and g <= f %}
{{ g }}
{% else %}
{{ a }}
{% endif %}
{% elif a >22 %}
{% if b >= c and b >= d and b >= e and b >= f and b >= g %}
{{ b }}
{% elif c >= b and c >= d and c >= e and c >= f and c >= g %}
{{ c }}
{% elif d >= b and d >= c and d >= e and d >= f and d >= g %}
{{ d }}
{% elif e >= b and e >= c and e >= d and e >= f and e >= g %}
{{ e }}
{% elif f >= b and f >= c and f >= d and f >= e and f >= g %}
{{ f }}
{% elif g >= b and g >= c and g >= d and g >= e and g >= f %}
{{ g }}
{% else %}
{{ a }}
{% endif %}
{% endif %}
```

as you can see, my purpose is returning the highest temperature when the outdoor temperature is higher than 22 and the lowest temperature when the outdoor temperature is lower than 22 or equal.

i’m trying to solve this problem for days but I can’t do it.

thanks for your help