Using templating for the entity_id of a choose node

Hi,

I’m trying to make a script that will toggle a climate entity from off to cool and back. This is what I have so far:

alias: climateToggle
fields:
  entity_id:
    name: Entity ID
    description: "Climate Entity ID"
    selector:
      entity:
        domain: climate
sequence:
  - choose:
      - conditions:
          - condition: state
            entity_id: '{{ entity_id }}'
            state: 'off'
        sequence:
          - service: climate.turn_on
            target:
              entity_id: '{{ entity_id }}'
    default:
      - service: climate.turn_off
        target:
          entity_id: '{{ entity_id }}'
mode: single

However when I try to save it, I get the following error:

Message malformed: Entity ID {{ entity_id }} is an invalid entity ID for dictionary value @ data['sequence'][0]['choose'][0]['conditions'][0]['entity_id']

It seems it doesn’t like the templating in the choose node’s condition. Is this not possible?

No, the state condition does not accept templates there. You will have to use a template condition.

Shorthand notation:

sequence:
  - choose:
      - conditions: "{{ is_state(entity_id, 'off') }}"
        sequence:
          - etc...

Or the full form:

sequence:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ is_state(entity_id, 'off') }}"
        sequence:
          - etc...
1 Like

Ah, bummer. The newer versions of HA allows for using entity ids in more places (like values), but guess not there.