Choose the lowest/highest temperature

Hello
I have 4 HVAC.
I turn on/off based on solar panel power .
The power on is simple, use an helper that tells the automation the lowest room temperature.

The power off should be slithly different:

  1. list the hvac that are heating
  2. power off hvac in the room with highest temperature. (the list is dinamically generate base on 1)

how can I do?

A simpler approach would be to write an “hvac off” automation for each room.

Numeric state trigger: room temp >= max of all room temperatures (use a min/max helper for the max sensor).

State condition: room hvac heating

Action: room hvac off.

The advantage of doing it this way is that it is easy to override with another condition if you manually want to heat or not heat a room.

Thanks for your input.
I would like to integrate in my current automation.
I thought to a template that create an HVAC sublist with only the device that are heating and than choose the one with highest temperature. This is my goal.

I found a solution like this but doesn’t work.

this is the result
TemplateSyntaxError: Encountered unknown tag ‘repeat’.

I don’t know what is wrong


{% repeat:
    for_each:
      ['climate.lg_room1', 'climate.lg_room2', 'climate.lg_room3', 'climate.lg_room4'] | select('is_state', 'heat') | list  
    sequence:
      - action: climate.set_hvac_mode
      - data:
          hvac_mode: "off"
        target:
          entity_id: "clima.{{ repeat.item}}"
%}