Individual template evaluation for each device in a group

I have an automation that controls radiator thermostats offset to mitigate wrong temperature from a sensor in thermostat. So I have an external sensor that is used as the actual temperature value, then target temperature of the radiator thermostat is set based on the difference between thermostat current temperature and the actual temperature.
Now, I have several radiator thermostats in the same room. And I have a template to define a new target temperature for thermostat. I want to simplify my automation to use just area and label instead of enumeration of all thermostats in the room. Is there any way for a template to be evaluated separately for each device and, if so, how to reference the device?
So instead of repeating actions for each device, like this:

action: climate.set_temperature
metadata: {}
data:
  temperature: >-
    {{(states('input_number.heating_target_temperature_main_bedroom') | float) -
    (states('sensor.main_bedroom_t_h_temperature') | float -
    states('sensor.radiator_thermostat_1_current_temperature')
    | float)}}
target:
  device_id: 123456

I’m looking or something like this:

action: climate.set_temperature
metadata: {}
data:
  temperature: >-
    {{(states('input_number.heating_target_temperature_main_bedroom') | float) -
    (states('sensor.main_bedroom_t_h_temperature') | float -
    this.current_temperature | float)}}
target:
  label_id: thermostat
  area_id: main_bedroom

where it’s going to be evaluated for each device individually

It is not clear to me exactly what you are trying to do, but I think you likely want a Repeat for Each action with a templated for_each. If you can clarify how the different entities, areas, and labels are related, we may be able to provide more specific help.

Points of confusion:

  1. this.current_temperature: In an automation of script the variable this references the state object of the automation of script… which will not have an attribute current_temperature.
target:
  label_id: thermostat
  area_id: main_bedroom
  1. Targets follow Union logic. Each of the types, like “Label” or “Entity ID”, creates an independent list and those lists are added together. So, a climate.set_temperature action with the target shown above will be performed on all climate entities in the Main Bedroom and all the climate entities labeled thermostat… Is that what you actually want to happen?

I have several radiator thermostats in the room, they are assigned to an area and a label. I want to assign target temperature individually for each of them

‘this’ was mentioned as an example, but apparently not a correct one.

I’d like to perform an action on all entities within the area and label. So it should be all climate entities in the main bedroom that have label thermostat. the mentioned behaviour looks more like OR action - all entities that have area “main bedroom” or have label “thermostat”

what is the right way to get a list of all entities for forEach that are in an area and have a label?

repeat:
  for_each: |
    {{ area_entities('main_bedroom') | select('match', 'climate.')
    | select('in', label_entities('thermostats')) | list }}
  sequence:
    - action: climate.set_temperature
      metadata: {}
      data:
        temperature: >-
          {% set h_target = states('input_number.heating_target_temperature_main_bedroom') | float %}
          {% set offset = states('sensor.main_bedroom_t_h_temperature') | float -
          state_attr(repeat.item, 'current_temperature') %}
          {{ h_target - offset }}
      target:
        entity_id: "{{ repeat.item }}"

this is what I have come up with for universal automation to control all thermostats in all areas:

alias: Update heating target temperature
description: ""
triggers:
  - trigger: state
    entity_id:
      - ...
conditions: []
actions:
  - variables:
      trigger_area: "{{ area_id(trigger.entity_id) }}"
  - repeat:
      sequence:
        - variables:
            device_area: "{{device_attr(repeat.item, 'area_id')}}"
        - if:
            - condition: template
              value_template: "{{ device_area == trigger_area }}"
          then:
            - variables:
                current_temperature: >-
                  {{ states((expand(device_entities(repeat.item)) |
                  selectattr('attributes.device_class', 'eq', 'temperature') |
                  first).entity_id) | float }}
                climate_entity_id: >-
                  {{ ((expand(device_entities(repeat.item)) |
                  selectattr('attributes.hvac_action', 'ne', Undefined)) |
                  first).entity_id }}
                reference_temperature: >-
                  {{ states(area_entities(device_area) | select ('in',
                  label_entities('temperature')) | first) | float }}
                offset: "{{ (reference_temperature - current_temperature) | float }}"
                target_temperature: >-
                  {{ states(area_entities(device_area) | select ('in',
                  label_entities('target_temperature')) | first) | float -
                  offset }}
            - action: climate.set_temperature
              metadata: {}
              data:
                temperature: "{{ target_temperature }}"
              target:
                entity_id: "{{ climate_entity_id }}"
      for_each: "{{ label_devices('thermostat') }}"
mode: queued
max: 20

Entities list include all reference temperature sensor, thermostat temperatures and target temperatures.
In each area there are entities for target and reference temperatures. So when automation is triggered, target temperature for triggered area is evaluated, thermostats from the area are selected and temperature updated