Unable to access reponse variable in if block

I have the following script and I’m trying to access the response variable blind_status in an if block which returns however it always comes back empty. But if I do a stop action outside the if block that seems to work ( it is disabled in the example below) How can I access the blind_status in my if block?

alias: "[Switchbot] Get Blind Status"
sequence:
  - service: script.response_variables_get_blind_device_id
    data:
      what: "{{what}}"
    response_variable: blind
    enabled: true
  - service: rest_command.switchbot_blind_status
    data:
      device_id: "{{blind.blind_device_id}}"
    response_variable: blind_status
    enabled: true
  - stop: ""
    response_variable: blind_status
    enabled: false
  - if:
      - condition: template
        value_template: "{{ attribute == \"response\" }}"
    then:
      - stop: ""
        response_variable: blind_status
  - if:
      - condition: template
        value_template: "{{ attribute == \"battery\" }}"
    then:
      - variables:
          content:
            content: "{{blind_status.content.body.battery}}"
        enabled: true
      - stop: ""
        response_variable: content
        enabled: true
mode: single
fields:
  what:
    selector:
      text: {}
    name: What
    required: true
    description: >-
      kitchen_stove_right, kitchen_stove_left, den_right, den_left,
      family_room_right, family_room_left, master_bathroom_right,
      master_bathroom_left
  attribute:
    selector:
      select:
        options:
          - label: Battery
            value: battery
          - label: Slide Position
            value: slidePosition
          - label: Response
            value: response
    name: Attribute
    required: true

This woul be the proper way to get around if-then yaml variable scope issues.

alias: "[Switchbot] Get Blind Status"
sequence:
  - service: script.response_variables_get_blind_device_id
    data:
      what: "{{what}}"
    response_variable: blind
  - service: rest_command.switchbot_blind_status
    data:
      device_id: "{{blind.blind_device_id}}"
    response_variable: blind_status
  - variables:
      content: >
        {% if attribute == 'response' %}
          {{ blind_status }}
        {% elif attribute == 'battery' %}
          {{ blind_status.content.body.battery }}
        {% else %}
          {'value': None}
        {% endif %}
  - stop:
    response_variable: content
 

Oh interesting, I would have thought I couldn’t access a variable outside an if block. Seems weird that an if block can’t access variables outside of it. Thanks for the alternative approach

Got a follow up to this. Let’s say I want to check the status of the api call (rest_command.switchbot_blind_status.) and retry it if the blind_status.status ==500. What would be the best way to handle that such that I can still keep the response variable as I assume if I do a conditional like repeat or something similar I would have the same issue?