Template with array/collection

Here’s a more compact way to do it:

  action:
  - data_template:
      rgb_color:
        - >
          {% set i = (states('sensor.chinese_air_quality_index') | int) // 50 %}
          {% set r = [168, 253, 254, 254, 169, 169] %}
          {{ r[i] if i < 6 else 168 }}
        - >
          {% set i = (states('sensor.chinese_air_quality_index') | int) // 50 %}
          {% set g = [224, 215, 155, 106, 122, 122] %}
          {{ g[i] if i < 6 else 115 }}
        - >
          {% set i = (states('sensor.chinese_air_quality_index') | int) // 50 %}
          {% set b = [95, 75, 87, 105, 188, 188] %}
          {{ b[i] if i < 6 else 131 }}        
    service: light.turn_on
    entity_id: light.officehuebulb

It leverages the fact you use every additional increment of 50 (air quality index) to be represented by another color. So we use integer division to divide the air quality index by 50. The result is used to select an item from the list.