joq3
September 12, 2024, 2:26pm
1
I cannot get this to work. I want a tap action to run a script from the frontend, and the script to use the entity I pass to the script?
This is what I tried to do after some searching on the forums:
tap_action:
action: call-service
service: script.volym_ner
data:
entity: media_player.vardagsrum
And the script:
action: media_player.volume_set
metadata: {}
data_template:
volume_level: |
{{ state_attr(entity, 'volume_level') | float - 0.02 }}
What am I doing wrong here?
123
(Taras)
September 12, 2024, 2:38pm
2
Where does it fail? Does the card’s tap_action
fail to execute the script or fail to pass the value of entity
to the script?
The script’s trace can reveal the answers.
joq3
September 13, 2024, 7:22am
3
I get this error:
must contain at least one of entity_id, device_id, area_id, floor_id, label_id.
I tried changing entity
to entity_id
but it still doesn’t work.
123
(Taras)
September 13, 2024, 1:06pm
4
joq3:
must contain at least one of entity_id, device_id, area_id, floor_id, label_id.
The media_player.volume_set
action in your script should specify which media_player will have its volume set.
action: media_player.volume_set
target:
entity_id: "{{ entity }}"
data:
volume_level: "{{ state_attr(entity, 'volume_level') | float - 0.02 }}"
joq3
September 16, 2024, 5:46am
5
Yes, but I want to pass the entity from the tap_action, otherwise I need to make duplicates of every script for each entity.
123
(Taras)
September 16, 2024, 12:11pm
6
The example I posted supplies the action with whatever is passed by the tap_action. Only one script is needed to control the volume of any media_player.