How to use template to pass list of entity ids to call-service for browser_mod right_action_button

I cannot find a way to pass a dynamic list of entity ids to browser_mod popup call for the right_button_action.

My Home Assistant version:

  • Core 2024.3.3
  • Supervisor 2024.03.1
  • Operating System 12.1
  • Frontend 20240307.0

Steps

  1. Create a dynamic sensor to hold all light entites that are currently on
- platform: template
  sensors:
  lights_on:
          unique_id: 82ef8b36-5843-4ed8-bf73-7f178d60721e
          friendly_name: Lights On
          unit_of_measurement: entities
          icon_template: "{{ 'mdi:lightbulb-outline' if is_state('sensor.lights_on','0') else 'mdi:lightbulb-on-outline' }}"
          value_template: >
            {{ states.light
                | selectattr('state','in',['on'])
                | rejectattr('entity_id','in',state_attr('group.ignored_entities','entity_id'))
                | rejectattr('entity_id','search','(_screen)')
                | list
                | count }}
          attribute_templates:
            entities: >
              {{ states.light
                  | selectattr('state','in',['on'])
                  | rejectattr('entity_id','in',state_attr('group.ignored_entities','entity_id'))
                  | rejectattr('entity_id','search','(_screen)')
                  | map(attribute='entity_id')
                  | list }}
  1. Call the light.turn_off service on the right action button.
    ...
    right_button: ALL OFF
    right_button_action:
      service: light.turn_off
      data:
        entity_id:
          template: '{{ state_attr(''sensor.lights_on'', ''entities'') }}'

The above code shows this error.

Failed to call service light/turn_off. not a valid value for dictionary value @ data['entity_id']

Also tried providing the entity id list this way, which is the way it works if I call the service from developer tools.

        ...
        entity_id: >
          {{ state_attr('sensor.lights_on', 'entities') }}

But when I save it turns into:

        ...
        entity_id: |
          {{ state_attr('sensor.lights_on', 'entities') }}

This code does not produce an error but then it does not turn off the lights either.

what am I doing wrong?

Most cards do not allow templating, and even those that do will rarely allow it in the action/service call block. Instead you should set up your service with templated logic in a script of its own, then call that script in your card action.