Trying to get max value of target temperature from 5 thermostates


I have a boiler and 5 radiators in my flat. I can control all 6 devices with HA.

I’d like to set the target temparature of the boiler to the highest target temperature that has been set at one of the five thermostates (radiators).

I played around with some group options, but this has only set the group target temp to the average temp of the thermostates.

I also found the min/max integration, but this is only for sensors.

I guess one could possible get that value into a varaiable or so. Forgive me, I’m rather new to HA.

Once thi is solved, I hope that I can use the variable in the action of my following automation:

# set boiler target temperature
  - service: climate.set_temperature
      temperature: (set to max of climate.set_temperature of the 5 radiators)
        - climate.hc1

Thanks in advance

You’ll create a template sensor. To develop the template goes into developer tools / templates.

Essentially you’ll create an array of values and use the max operator to find the largest.

Try this example:

{{ [6, 7, 8]| max }}

That will return 8. Now instead of that use state_attr to get the thermostats setpoint.

{{ [ state_attr("climate.thermo1", "temperature"), state_attr("climate.thermo_2", "temperature") ] | max }}

Thanks a lot, PeteRage. This works like a charm. My action now looks like this:

service: climate.set_temperature
  temperature: >-
    {{ [  state_attr("climate.hzg_wz_2", "temperature"), 
    state_attr("climate.hzg_bad_2", "temperature"), 
    state_attr("climate.hzg_kuche_2", "temperature"), 
    state_attr("climate.hzg_az_2", "temperature"), 
    state_attr("climate.hzg_sz_2", "temperature") ] | max }}
    - climate.hc1

I like it.

A consideration is the behavior of that expression if one of the thermostats is unavailable.

This expression fails

{{ [ 1, 2, 3, "unavailable"]|max }}

So what you do is cast those temperatures to an int or float with a default value

state_attr("climate.hzg_bad_2", "temperature")|float(65)

This will return 65 if the sensor is unavailable. So you’ll want to pick this default to be a good value for your situation.

The last consideration is validating that the temperature is a reasonable value. While it should be, you never really know what can happen

To do this move the calculation from the service call to an automation variable

    target_temperature: '{{ your expression here  }}'

That you can check with a condition

      - condition:  '{{ target_temperature > 49 and target_temperature < 76}}'