Turn down Honeywell thermostats at once

I was triggered by this automation: Howto create battery alert without creating a template for every device. It checks for battery levels and sends a message is lower than X.

I was wondering if I could do something similar for my Honeywell thermostats. When I go to bed (set an input_boolean) is there a way to select all thermostats higher than X and set them to Y?

Struggling once again with the code.

Thanks!

How many thermostats do you have, may be easier to just hard code this info.

About 10. Would prefer to automate because of reducing overall code.

How about something like this:

automation:
  - alias: Turn down thermostats at night
    trigger:
      platform: state
      entity_id: input_boolean.NAME
      to: 'on'
    condition:
      condition: template
      value_template: >
        {{ states.climate|selectattr('attributes.temperature','gt',X)|list|count > 0 }}
    action:
      service: climate.set_temperature
      data_template:
        entity_id: >
          {% for state in states.climate if state.attributes.temperature > X %}
            {% if not loop.first %},{% endif %}{{ state.entity_id }}
          {% endfor %}
        temperature: Y

EDIT: Oops, forgot to handle the case where no thermostats are above X. Changed solution above accordingly.

That’s some beautiful code right there! This would have taken me ages… Thanks!

I do however get an error message:

  Error executing service <ServiceCall climate.set_temperature (c:4a0e44e4fb944af4aacbd938a5113526): entity_id=['climate.kitchen', 'climate.study'], temperature=10.0>

All looks pretty good in the template:

    - alias: Turn down thermostats at night
      trigger:
        platform: state
        entity_id: input_boolean.test
        to: 'on'
      condition:
        condition: template
        value_template: >
          True
      action:
        service: climate.set_temperature
        data_template:
          entity_id: >
            
              climate.kitchen
            
              ,climate.study
            
          temperature: 10

Do you see the INFO line in home-assistant.log that shows the actual service call? And are there any errors about the service call in that log, that is, more than just the line that says it didn’t work?

Not sure what to make of this. But maybe it doesn’t like the extra newlines. If so, maybe this will work better:

automation:
  - alias: Turn down thermostats at night
    trigger:
      platform: state
      entity_id: input_boolean.NAME
      to: 'on'
    condition:
      condition: template
      value_template: >
        {{ states.climate|selectattr('attributes.temperature','gt',X)|list|count > 0 }}
    action:
      service: climate.set_temperature
      data_template:
        entity_id: >
          {% for state in states.climate if state.attributes.temperature > X -%}
            {% if not loop.first %},{% endif %}{{ state.entity_id }}
          {%- endfor %}
        temperature: Y

Just read there was an issue with Honeywell servers. Ran the code again today and it seems to be working. Thanks for the feedback guys, much appreciated!