Generate a list for a particular domain (light) from a target list that has multiple domains?

I have a blueprint with a target input. The input can have 3 domains, see below.

      name: Lights Switch
              - light
              - switch
              - scene

We then have some variables. In the input target above we can input the domains light, switch, scene we are trying to create a list of only light domain from the input. The variable below called “light_entities” is our attempt to get a list of lights in the domain light but it is not working.

  light_switch: !input light_switch
  light_entities: "{{ expand(light_switch.entity_id) | selectattr('domain', 'eq', 'light')|map(attribute='entity_id')|list }}"

we then use the “light_entities” in our target.

            - service: light.turn_on
              target: "{{light_entities}}"
                brightness_pct: !input light_brightness

But it is not working.

Would anyone know how to generate a list for a particular domain (light) from a target list that has multiple domains and use that list in a target?

All good found the fault. “target” was wrong :wink:.

Got one question if someone could help.

If the list “light_switch” was undefined how could I make it return “[]”

Below works perfectly fine in developer tools. But if you change the “light_switch” and say remove the “h” you will see it as undefined. I would like it to pass and return “[]” if light_switch is undefined. Is this possible?

{% set light_switch = {
  'entity_id': [
} %}

    {{ expand(light_switch.entity_id) | selectattr('domain', 'eq', 'light') | map(attribute='entity_id') | list }}