Template to calculate a more reliable sensor temperature

Hi. I’m not very experienced with templates, and I need your help. :grimacing:
To measure the outdoor temperature, I placed several thermometers outside, intending to calculate the average value. Unfortunately, one of the values is “skewed” by the sun when it shines on that specific spot.
So, I’d like to take all the values, remove the highest one, and then calculate the average of the remaining ones.
Can someone help me? :pray:

Hello Marco,

It would help if you could to provide some code so we can see what you’ve done so far… We won’t be able to help if all we have is ‘I want to do this thing with this other thing’.
How to help us help you - or How to ask a good question.

{% set thermometers = [ 'sensor.temperature_1', 'sensor.temperature_2',
'sensor.temperature_3', 'sensor.temperature_4' ] %}
{{ (thermometers | select('has_value') | map('states') 
| map('float', 0) | sort)[:-1] | average | round(1) }}

Thank you… I’ll try to understand :grinning:
I was thinking about writing this:
{{ ( ( ( states('sensor.sensor1') | float ) + ( states('sensor.sensor2') | float ) + ( states('sensor.sensor3') | float ) - ( states('sensor."sensor_max by helper"') | float ))/2 ) | round(1) }}"