How to pass different entitles from lovelace card to script

Hi Everyone,

I’ve spent many hours trying to figure out this simple thing.
I have one card that handles multiple entities for led lights.

I’m using custom:floorplan-card.
I would like to pass the entity for the tap action to the script as a parameter.
All it does is pass the string name.

Here is a scale down version of the card:

                - entities:
                    - light.living_bookshelf_led
                    - light.hall_garage
                    - light.living_mantle_led
                    - light.living_tv_back_light
                  hold_action:
                    action: call-service
                    service: honeycomb
                    service_data:
                      xy_pad:
                        ..
                        ..
                     buttons:
                        - icon: mdi:palette
                          tap_action:
                            action: call-service
                            service: script.random_led
                            service_data:
                              led_entity: entity
                     ...
                     ...

**script below:**

random_led:
  alias: random led
  fields:
    led_entity:
      description: "The title of the notification"
      example: "State change"
  sequence:
    - service: input_text.set_value
      data:
        value: "{{led_entity }}"
      target:
        entity_id: input_text.start_living_led_random

Hmm, no response to my question.
Sadly a reoccurring issue with my posts.
Am I asking questions wrong? What’s wrong with my post?

Anyway, I figure out my issue on passing the entity Id to a script.

I assumed wrongly that you could use any parameter name to pass the entity Id.

So instead of using led_entity:

   buttons:
      - icon: mdi:palette
        tap_action:
          action: call-service
          service: script.random_led
          service_data:
            led_entity: entity

I changed the parameter name to entity_id which is odd since you defined the parameter name in the script, so why would it care the name of it. I find Yaml to be very strange. I come from a programming background and find Yaml to be odd

   buttons:
      - icon: mdi:palette
        tap_action:
          action: call-service
          service: script.random_led
          service_data:
            entity_id: entity

Your initial assumption was correct. The name of the variable passed to the script can be of your choosing.

EXAMPLE

I created the following simple script that accepts three variables named a, b, and c and posts their values as a Persistent Notification.

  foo:
    sequence:
      - service: notify.persistent_notification
        data:
          title: Foo says
          message: '{{a}} {{b}} {{c}}'

I created the following Button card:

show_name: true
show_icon: false
type: button
tap_action:
  action: call-service
  service: script.foo
  service_data:
    a: Hello
    b: To
    c: Everyone
name: Foo Test

image

Clicking the button produced the following notification:

image


Passing a custom variable name, via service_data in tap_action, has been available for many years. Here are two older examples:

Passes variable named room

Passes variable named tentity