I’m trying to have a Lovelace entities card send a number parameter to a script based on user input to a text helper. I created the following YAML, which executes my script but only works if an actual value is specified for stepcount. I don’t get any error and the script is invoked but the stepcount parameter is empty. I’ve tried a number of simpler variations but nothing works.
type: entities
entities:
- entity: input_text.test_text
- type: call-service
name: " "
icon: mdi:music
action_name: Go to station
service: script.denon_favorites_reverse
data:
stepcount: "{{ 'input_text.test_text'|int(0) }}"
Entities cards do not support templating… even cards that do support templating rarely support it in actions.
Also, the expression {{ 'input_text.test_text'|int(0) }} will always return 0… you would need to use the states() function if you want to retrieve the state value of the entity.
If you post your script config, we can help you modify it to work.
That makes sense. The question I have here is how to allow for multiple conditions in the current YAML:
Stepcount could be supplied by a calling button (current YAML does this). I have Lovelace buttons that invoke the script and pass a specific stepcount value.
If stepcount not suppllied, check the value of the random helper. I have a single Lovelace button that invokes the script but does not supply a stepcount.
Now the idea is to modify the script so that if stepcount is not supplied but a helper named something like “input_number_steps” is not zero, assign the value of input_number_steps to stepcount.
So maybe that is the solution, to add that condition to the script and clear out input_number_steps at the end? In an attempt to do this, I added an if-then condition to the start of the script, but I’m stuck on how to assign the value of the helper to the stepcount field. I know I would use
"{{ states('input_number_steps' }}"
for the value, but how do I assign the value to the variable? Do I need to do this within the variable: section?
For anyone wondering about this question of how to assign an input_number value to a script variable/field in a condition. In this example, stepcount is the variable to be assigned to, Because the script resets the helper to zero at the end of the script the condition below is fulfilled only if the script is called when a value has specifically been assigned to the input_number helper: