Maintain temperature of multiple rooms

I have this automation which is supposed to maintain a temperature of 21°C in several rooms when we’re home:

# Maintain temperature when home
- id: "5021549414"
  alias: maintain_temp_when_home
  trigger:
    - platform: numeric_state
      entity_id:
        - climate.wiser_hallway
        - climate.wiser_bathroom
        - climate.wiser_bedroom
        - climate.wiser_living_room
      value_template: "{{ state.attributes.current_temperature }}"
      below: 21
    - platform: time_pattern
      hours: "/1"
  mode: parallel
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: binary_sensor.season_temp_threshold
        state: "on"  
      - condition: time
        after: "08:00:00"
        before: "18:00:00"
      - condition: or
        conditions:
          - condition: state
            entity_id: binary_sensor.person1_home
            state: "on"
          - condition: state
            entity_id: binary_sensor.person2_home
            state: "on"    
  action:
    - service: climate.set_temperature
      data_template:
        entity_id: >-
          {% if trigger.entity_id == 'climate.wiser_hallway'
            or trigger.entity_id == 'climate.wiser_bathroom'
            or trigger.entity_id == 'climate.wiser_bedroom'
            or trigger.entity_id == 'climate.wiser_living_room' %}
              {{ trigger.entity_id }}
          {% else %}
            {% if (state_attr('climate.wiser_hallway', 'current_temperature') < 21 ) %}
              climate.wiser_hallway
            {% elif (state_attr('climate.wiser_bathroom', 'current_temperature') < 21 ) %}
              climate.wiser_bathroom
            {% elif (state_attr('climate.wiser_bedroom', 'current_temperature') < 21 ) %}
              climate.wiser_bedroom
            {% elif (state_attr('climate.wiser_living_room', 'current_temperature') < 21 ) %}
              climate.wiser_living_room
            {% endif %}
          {% endif %}
        temperature: 21
        hvac_mode: auto

And is sort of works… but not really, the problem is in this section:

            {% if (state_attr('climate.wiser_hallway', 'current_temperature') < 21 ) %}
              climate.wiser_hallway
            {% elif (state_attr('climate.wiser_bathroom', 'current_temperature') < 21 ) %}
              climate.wiser_bathroom
            {% elif (state_attr('climate.wiser_bedroom', 'current_temperature') < 21 ) %}
              climate.wiser_bedroom
            {% elif (state_attr('climate.wiser_living_room', 'current_temperature') < 21 ) %}
              climate.wiser_living_room
            {% endif %}

I wrongly assumed that if more than one these is below 21°C, that the temperature of those entities will be set to 21°C and the hvac mode to auto. However it only ever affects the first entity which meets these criteria.

What I want to happen that the automation should affect any/all of the entities where the current temperature is below 21°C and ignore those where the temperature is above 21°C.

Thanks for any help :+1:

You can use choose action type to get this done very simply like this.

action:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: climate.wiser_living_room
            below: '21'
        sequence:
          - service: climate.set_temperature
            entity_id: climate.wiser_living_room
            data:
              temperature: 21
              hvac_mode: auto
      - conditions:
          - condition: numeric_state
            entity_id: climate.climate.wiser_bathroom
            below: '21'
        sequence:
          - service: climate.set_temperature
            entity_id: climate.climate.wiser_bathroom
            data:
              temperature: 21
              hvac_mode: auto
      - conditions:
          - condition: numeric_state
            entity_id: climate.climate.wiser_bedroom
            below: '21'
        sequence:
          - service: climate.set_temperature
            entity_id: climate.wiser_bedroom
            data:
              temperature: 21
              hvac_mode: auto
      - conditions:
          - condition: numeric_state
            entity_id: climate.wiser_living_room
            below: '21'
        sequence:
          - service: climate.set_temperature
            entity_id: climate.wiser_living_room
            data:
              temperature: 21
              hvac_mode: auto
    default: []

This is not complete but i hope you get the idea.

1 Like

Try this:

  action:
    - service: climate.set_temperature
      data:
        entity_id: >-
          {% if trigger.platform == 'numeric_state' %}
              {{ trigger.entity_id }}
          {% else %}
            {% set x = expand('climate.wiser_hallway', 'climate.wiser_bathroom', 'climate.wiser_bedroom', 'climate.wiser_living_room')
                | selectattr('attributes.current_temperature', 'lt', 21)
                | map(attribute='entity_id') | list | join(', ') %}
            {{ x if x | length > 0 else 'none' }}
          {% endif %}
        temperature: 21
        hvac_mode: auto

NOTE

I don’t have multiple thermostats so I can’t easily test it. The assumption I am making is that entity_id accepts a comma-delimited string of entity_id’s.

entity_id: climate.wiser_bedroom, climate.wiser_living_room

If my assumption is incorrect then this won’t work.

That’s exactly what I was looking for, works a treat. Thank you :grinning:

1 Like