I try to create a simple script to set the position for a specified cover. If I use a fix entity_id in the script everything works fine but If I try to use a variable entity_id in the data_template I receive the error “not a valid value for dictionary value @ data[‘entity_id’]”.
As I understand, that should work, but i doesn’t.
set_cover_position:
sequence:
- service: cover.set_cover_position
data_template:
entity_id: "{{device}}"
position: >-
{% if modus == close %}
0
{% else %}
100
{% endif %}
anyway, I made a simple test by replacing cover.set_cover_position with persistent_notification.create and it works as expected.
that means there something not quite right with that service call rather than script variables in general.
Ah, calling scrip.turn_on requires variables. Calling the script directly as a service does not.
There are two ways to achieve this. One way is using the generic script.turn_on service. To pass variables to the script with this service, call it with the desired variables
The other way is calling the script as a service directly. In this case, all service data will be made available as variables.
EDIT: Just to clarify, the root cause of your issue is that entity_id and modus were blank because you were using data instead of service_data in your button card.
It would be much better to have data/data_templatewherever we can use service: xxx.
Edited for clarity. service requires data and it has nothing to do with templates. It’s just a question of consistency as I see it. Lack of that creates post like this.
I assume he mean’t that it should be consistent across Home Assistant. E.g. in automations it’s data and in the tap action of lovelace it’s service_data
spot on
I think I understand and appreciate why there is no consistency in HA but for me personally it does not mean that any thought about imperfection of things is heresy.
I also appreciate that people might be absolutely happy with the state of things and won’t try to disturb them in their nirvana as I’m here solely to learn and share my knowledge with those who want it.