Template to get highest temp from a range of sensors

Hi,

I am trying tio get the highest temp from a ranger if sensors.

I took my start point from this thread. I am just trying with 2 at the moment but cannot get it to work. Can someone give me a pointer?

template:
  - sensor:
      - name: "hottest temp"
        device_class: temperature
        unit_of_measurement: ℃
        state: >
          {% set sensors = [
            states('sensor.hallway_temp'),
            states('sensor.living_room_temp')]
            |reject('none')|list
            %}
        {{ sensors |round(1) | max }}

OK, got it. Keeping this here in case it helps someone else…

    {% set sensors = [
      states('sensor.hallway_temp') |round(1),
      states('sensor.living_room_temp') |round(1)]
      |reject('none')|list
      %}
    {{ sensors | max }}

Does anyone know what template would give the ‘friendly name’ of the hottest sensor?

Here is one way to do it:

{% set sensors = expand('sensor.hallway_temp', 'sensor.living_room_temp') %}
{% set x = sensors | map(attribute='state') | map('float') | max | string %}
{{ sensors | selectattr('state', 'eq', x) | map(attribute='name') | first }}

You could just use the min max integration:

1 Like

this is how i did it

  - platform: min_max
    name: lounge temperature max
    type: max
    entity_ids:
      - sensor.lounge_temperature
      - sensor.lounge_temperature_max

Brilliant - thanks.

I am now going to read up on expand(), map() & selectattr()

@Tom_in_HI @myle

Thanks for your replies, guys :slight_smile:

Doesn’t min_max gives you the min and max for each entity listed? I am looking for which entity is max right now.

No.

e.g. feed it 6 sensors, it will tell you the maximum value of the six states.

1 Like

Oh, fantastic - thanks for explaining that!

remember to pass it else into the min_max

  - platform: min_max
    name: lounge temperature max
    type: max
    entity_ids:
      - sensor.lounge_temperature
      - sensor.lounge_temperature_max

image

so that the max will be the max

and can do the same for the min