Conditional service not working in blueprint

Hi all,
I’m having an issue with a particular blueprint I’m developing. All of the below code works as expected in the Template tab of Developer Tools, but produces an error when read in as an automation. Does anyone see any obvious issues?
is_zha_group is a custom variable set in my blueprint. The object of the code is to send a zigbee group command if the entity is a zigbee group, and send a zigbee cluster command if the entity is a single device.

sequence: >
  {% if is_zha_group == true %}
    - service: zha.issue_zigbee_group_command
      data:
        group: "{{ zha_group }}"
  {% else %}
    - service: zha.issue_zigbee_cluster_command
      data:
        ieee: "00:0d:6f:00:16:43:6f:c2"
        endpoint_id: 1
        command_type: server
  {% endif %}
        cluster_id: 0x0008
        command: 0x0000
        args:
          - 254
          - 150

You can’t use a Jinja2 template to generate YAML. A Jinja2 template can only be used to generate a value for a YAML key.

This is valid (a template generating a value for a YAML key named group):

group: "{{ zha_group }}"

This is invalid (a template generating YAML):

  {% if is_zha_group == true %}
    - service: zha.issue_zigbee_group_command
      data:
        group: "{{ zha_group }}"
  {% else %}

The Template Editor is for testing Jinja2 templates. It has no idea that you r template is generating YAML. As far as it’s concerned, it’s just text.

It fails in the automation because that’s where the distinction between Jinja2 and YAML are understood.

Gotcha, thank you. I thought I saw examples of others doing this, but I must have misread. Back to the drawing board.

Use choose to determine which service call should be used.