Passing dynamic data to light.turn_on

I have a script that I call in lieu of directly calling light.turn_on.

service: script.autocolor
data:
  entity_id: light.couch_lamp

The purpose of the script is to attach a color_temp to the light.turn_on call, depending on sunset/time of day. The script also accepts other data like brightness_pct and transition, or passes along default values if none was received. My script works as the following:

sequence:
  - if:
      - condition: state
        entity_id: sun.sun
        state: above_horizon
    then:
      - service: light.turn_on
        data:
          entity_id: "{{entity_id}}"
          color_temp: 153
          brightness_pct: "{{brightness_pct}}"
          transition: "{{transition}}"
    # else code removed for simplicity
variables:
  brightness_pct: "{{brightness_pct if brightness_pct is defined else 100}}"
  transition: "{{transition if transition is defined else 3}}"

But I’d like to be able to utilize that same service call to occasionally pass along brightness_step_pct instead of brightness_pct, without nesting a bunch of if-else-then statements with their own service calls. I’m trying to do something like the following but it gives me an error “two or more values in the same group of exclusion”:

  - service: light.turn_on
    data:
      entity_id: '{{entity_id}}'
      color_temp: 153
      brightness_pct: '{{brightness_pct if brightness_step_pct is not defined else 0}}'
      brightness_step_pct: '{{brightness_step_pct if brightness_step_pct is defined else 0}}'
      transition: '{{transition}}'

And it doesn’t seem like this type of thing works either-

  - service: light.turn_on
    data:
      entity_id: '{{entity_id}}'
      color_temp: 153
      {%if brightness_step_pct is not defined then%} brightness_pct: '{{brightness_pct}}'
      {%else%} brightness_step_pct: '{{brightness_step_pct}}' {%endif%}
      transition: '{{transition}}'

So is there a way I could have a single service call to light.turn_on with all the data points, but it only passes along the ones that are defined?

Providing the solution to my own question for posterity.

script.autocolor:

alias: autocolor
sequence:
  - variables:
      brightness: >-
        {{brightness_step_pct if brightness_step_pct else brightness_pct if
        brightness_pct else 100}}
      color: >
        {%- if color=="green" -%} [0.3195,0.485] {%- elif color=="warm" -%} 269
        {%- elif color=="daylight" -%} 153 {%- else -%} 1 {% endif %}
      attrs: >
        {
        {{(1==1)|iif("'entity_id'","'area_id'")}}:{{(1==1)|iif("'light.couch_lamp'","'living_room'")}},
        {{(brightness_step_pct)|iif("'brightness_step_pct'","'brightness_pct'")}}:"{{brightness}}",
        {{(color[1])|iif("'xy_color'","'color_temp'")}}:{{color}},
        "transition":"{{(transition)|iif(transition,3)}}" }
  - service: light.turn_on
    data: "{{attrs}}"

Not the prettiest code but does what I needed.

Also created another method to achieve similar end goal for a different function-

  - service_template: fan.{{iif(trigger.id=='turnon','set_preset_mode','turn_off')}}
    data: >-
      {{dict({'entity_id':'fan.purifier'}, **{'preset_mode':'auto'} if
      trigger.id=='turnon' else {})|to_json}}

…which calls either fan.turn_off with only entity_id, or fan.set_preset_mode with entity_id and appends preset_mode to the dictionary (which would throw an error for the former service)