Dynamic entity_id in scripts

I’ve a broadlink IR controller in 2 rooms to control the A/C
Both A/C are the same so when I teach one of my broadlink the IR commands it can be applied to the other broadlink as well.

I’ve created all the needed scripts to call the IR send command in one of the rooms and it work great,
now - I would like to duplicate it to the second room but just change the target entity.

I’ve tried to call the script with a dynamic entity_id but it doesn’t work - I either done something wrong or it’s not supported.

Here is my script:

alias: A/C Off
sequence:
  - service: remote.send_command
    data:
      device: A/C
      command:
        - Power Off
    target:
      device_id: '{{ data.entity_id }}'
mode: single
icon: mdi:fan-off

The device name A/C is identical in both rooms.

And here is the way how I call the script from the dashboard (using a button):

type: horizontal-stack
title: Master Bed Room A/C
cards:
  - type: vertical-stack
    cards:
      - show_name: true
        show_icon: true
        type: button
        tap_action:
          action: toggle
        entity: script.a_c_on_cold24auto
        name: ❄️ A/C Cold 24'C Auto
        icon_height: 50px
  - type: vertical-stack
    cards:
      - show_name: true
        show_icon: true
        type: button
        tap_action:
          action: toggle
        entity: script.a_c_off
        icon_height: 50px
        data:
          entity_id: 4d0ef0dad66651b949659d663179aa64

Any suggestions?

You haven’t called the script or supplied the data in your tap action.

  - type: vertical-stack
    cards:
      - show_name: true
        show_icon: true
        type: button
        entity: script.a_c_off
        tap_action:
          action: call-service
          service: script.a_c_off
          data:
            device_id: 4d0ef0dad66651b949659d663179aa64
        icon_height: 50px

alias: A/C Off
sequence:
  - service: remote.send_command
    data:
      device: A/C
      command:
        - Power Off
    target:
      device_id: '{{ device_id }}'
mode: single
icon: mdi:fan-off

mmm…
I’m not an expert here (barely a newbie :sweat_smile:) but it’s working for me
at least when I’m not using a template but having the entity_id hard-coded at the script side for one of the broadlinks.

I’m going to try the action that you suggest :slight_smile:

Yeah sorry I missed that. But you still need to pass the data like I did.

1 Like

Cool, it’s working - Thank you
Now for one more small question:

I’ve several commands and it’s dump to define the entity_id for each command call
is there a way to define a local variable at the top of the YAML to be used in each command in my dashboard?