Trigger on an attribute over multiple device entities

I have multiple thermostats that each have an attribute that represents boost mode.

I’m trying to write something (automation and or a sensor) that will trigger/represent any thermostat if any is in boost mode.

The logic is simply, any thermostat in boost mode then turn on boiler.
however if there are now no thermostats in boost mode, and there isn’t a normal ‘call for heat’ then turn off the boiler.

i’ve tried to work with the following snippets that I found here and in the docs:

{% for tracker in expand('device_tracker.paulus', 'group.child_trackers') %}
  {{ state_attr(tracker.entity_id, 'battery') }}
  {%- if not loop.last %}, {% endif -%}
{% endfor %}

This seems to require me to create a group for all the thermostats, although climate services can take ‘all’ as the entity_id, i can’t seem to apply that here.

value_template: "{% for player in states.media_player if player.state == 'playing' %}true{% endfor %}"

In this example I don’t need to create a new group, and I have merged this logic with the previous example.

but i need consolidate the output of the function to either TRUE if any thermostat preset_mode == Full power, or FALSE none are preset_mode == Full power.

My scripting skill in this language/construct is really holding me back - quite frustrating. I don’t have a working example to put here, or rather not one that i’m not ashamed of… ah well, here it is anyway.

{% for trv in states.climate %}
  {% if state_attr(trv.entity_id, 'preset_mode') == "Full power" %}
  TRUE
  {% else %}
  FALSE
  {% endif -%}
{% endfor %}

which outputs:

FALSE
  
  
  FALSE
  
  
  FALSE
  
  
  FALSE
  
  
  FALSE
  
  
  TRUE
  
  
  FALSE
  
  
  FALSE
  
  
  FALSE
  
  
  FALSE

any pointers would be super helpful. Thanks

got a lot closer i think

{% set result = false %}
{% for trv in states.climate %}
  {% if state_attr(trv.entity_id, 'preset_mode') == "Full power" %}
    {% set result = true %}
  {% endif -%}
{% endfor %}
{{ result }}

however, this never returns true. so I’m stumped again.

Another approach, to count the devices that have this attribute set to full power

          {% set count = states.climate | selectattr('preset_modes', 'eq', 'Full power')
                                        | map(attribute='entity_id')
                                        | list
                                        | length %}
          {{ count }}

annoyingly this doesn’t work. as if that attribute can’t be found.

This code does work, which makes me think i’m close…

          {% set count = states.climate | selectattr('state', 'eq', 'heat')
                                        | map(attribute='entity_id')
                                        | list
                                        | length %}
          {{ count }}

but that just gives me a count of all climate devices that are in heat mode, which is the primary state for these devices. so i’m failing to get down into the attributes, where preset_modes exists.

ah I think I’ve got it

          {% set count = states | selectattr('attributes.preset_mode', 'eq', 'Full power')
                                        | map(attribute='entity_id')
                                        | list
                                        | length %}
          {{ count }}

(based off a post from @megatrooooon : Selectattr to match part of the attribute - #7 by megatrooooon)

Hi, I am trying to do the same thing. Turn on boiler if any (or a list) of TRV’s call for heat. Turn boiler off if no TRV is calling for heat.

I am a complete newbie at this stuff and so could you show me the whole automation code you used?

Thanks