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
123
(Taras)
June 23, 2024, 1:49pm
3
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
Clicking the button produced the following notification:
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
If you’re interested, you can reduce your automation to this:
alias: Room Togglers
description: ""
trigger:
- platform: state
entity_id:
- input_boolean.rooma_toggle
- input_boolean.roomb_toggle
- input_boolean.roomc_toggle
from: "off"
to: "on"
condition: []
action:
- variables:
rooms:
- input_boolean.rooma_toggle
- input_boolean.roomb_toggle
- input_boolean.roomc_toggle
- service: input_boolean.turn_off
target:
entity_…
Passes variable named tentity
I designed the script to use climate.f1a1 by default if it doesn’t receive a value for tentity.
The results of your test prove that the script is not receiving a value for tentity.
I suggest you try the version I had suggested which uses service_data instead of data.
tap_action:
action: call-service
service: script.toggle_heater
service_data:
tentity: climate.f1a2
double_tap_action:
action: more-info