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.

    light_switch:
      name: Lights Switch
      description: 
      selector:
        target:
          entity:
            domain: 
              - 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.

variables:
  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.

          sequence:
            - service: light.turn_on
              target: "{{light_entities}}"
              data:
                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': [
      'switch.family_room_light_2',
      'light.water_tank_1_light',
      'light.water_tank_2_light'
  ]
} %}

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