Why doesn't this template count work to change an icon color?

I’m trying to change an icon color to orange if the count of lights on in the room is > 0 using the following code:

                              {% set total = 0 %}
                              {% if is_state('light.front_office_overhead_lights_dimmer', 'on') %}
                                {% set total = total + 1 %}
                              {% endif %}
                              {% if is_state('light.front_office_desk_lamp', 'on') %}
                                {% set total = total + 1 %}
                              {% endif %}
                              {% if is_state('light.front_office_fan_light', 'on') %}
                                {% set total = total + 1 %}
                              {% endif %}
                              ({{total}}) Lights ON
                            icon: mdi:lightbulb-group
                            icon_color: |-
                              {% if total > 0 %}
                                orange
                              {% else %}
                                gray
                              {% endif %}

but that doesn’t work. The only way I’m able to get it to work is if I create an if statement that checks if each light is on and if so, set it to orange. Would rather do it if the count is greater than 0, to safe a lot of copy/pasting.

It evaluates correctly in Developer template tools, but the icon color doesn’t actually change.

Thanks.

Variables only have local scope… so total has no value in the icon_color.

  {% set ents = ['light.front_office_overhead_lights_dimmer', 
  'light.front_office_desk_lamp', 'light.front_office_fan_light'] %}
  {% set total = ents|select('is_state', 'on')|list|count %}
  ({{total}}) Lights ON
icon: mdi:lightbulb-group
icon_color: |-
  {% set ents = ['light.front_office_overhead_lights_dimmer', 
  'light.front_office_desk_lamp', 'light.front_office_fan_light'] %}
  {% set total = ents|select('is_state', 'on')|list|count %}
  {% if total > 0 %}
    orange
  {% else %}
    gray
  {% endif %}

Thanks! Forgot about scope.