Passing Entity ID to a script

I am trying to pass an entity id variable to a script from a custom:button-card so that I can use one script for several lights. I am getting an error message: Failed to call service script. Template rendered invalid Entity ids.

This works correctly when I set a specific entity id in the script.

I am fairly new to Home Assistant. I am an experienced software developer.

Thank you.

Custom:button-card

type: custom:button-card
name: ''
icon: mdi:menu-left-outline
styles:
  card:
    - height: 100px
    - border: 0px
    - background-color: transparent
  icon:
    - width: 100px
    - height: 100px
tap_action:
  action: call-service
  service: script.brightness_down_2
  data:
    light_entity_id: light.rgbw_04_5
hold_action:
  action: call-service
  service: script.brightness_down_2
  data:
    light_entity_id: light.rgbw_04_5
  repeat: 200ms

service: script.brightness_down_2

alias: Brightness Down 2
sequence:
  - service: light.turn_on
    data:
      brightness_step_pct: -10
    target:
      entity_id: "{{ light_entity_id }}"
mode: single

service_data: not data:, see https://github.com/custom-cards/button-card#action

tap_action:
  action: call-service
  service: script.brightness_down_2
  service_data: 
    light_entity_id: light.rgbw_04_5

That worked. Thank you.

1 Like