Hi, I am trying to set up a basic button on my dashboard that has a slider which establishes an input, and then pass that value to alexa via the send_text_command.
I have tried several variants to make this work, but the send_text_command just sends the straight text to Alexa, it does not seem to parse the {{ }} as variables. I can go look at my alexa logs and see that HA is just sending the full string.
I have also tried is with text_command: Set bedroom fan fan to {{states(āinput_number.bedroom_fan_inputā)}}%
Both of these parse correctly in the debugger on the card configuration of the dashboard, but both just pass the text as typed directly to alexa, which of course doesnāt work.
Am I doing something wrong, or is there another way to pass a variable as text_command to alexa?
There is nothing wrong with your template, itās where you are trying to use it that is the problem.
The vast majority of cards do not support templates at all, and even those that do rarely support them in card actions. The standard workaround is to move your templated action to a script and call the script from your card.
It works, but the text command has to be set without the brackets surrounding the entire command. Hereās an example that I use -
action: alexa_devices.send_text_command
metadata: {}
data:
device_id: 77c812c0bf615f6516b5686c6560e6a3
text_command: change volume to {{ states('input_number.all_echo_volume') | int }} percent
EDIT notice the " | int "? Iām thinking thatās where yours is failing. Alexa is expecting a number and without it states is only providing a string.
Well isnāt that the whole point of the pipe? To apply a filter and turn the string into an integer (number)? Or maybe Iām misunderstanding how jinja works⦠idk. Iām thinking the issue is how Alexa wants and expects to receive the command. Because my command works and theirās at itās current iteration does not.
The rest of the text command value will force it to be a string⦠the int makes no difference.
OPās issue has nothing to do with Alexa. They are trying to use a template where it isnāt supported i.e. a card action. Your command would also not work in a card action.
Ahhh, I see what youāre saying. I apologize. I reread the OP and your following post.
So instead of a card action, perhaps the OP should use the template directly in an automation with the input_number helper? Or a script like you had recommended. Thatās what Iām doing to control the volume. Then theyād only need to include the helper in an entity card.
What I meant by string, as opposed to integer, was the number itself within the text command. Without the | int, the number, itself, would appear in quotations to Alexa. When Alexa Devices first rolled out this feature, that was an issue. I donāt know if it still is and I donāt really care to test it to find out, lol. My command works as-is. Sorry for the misunderstanding
Thank you both for the prompt replies. I have this working now. I will share what I am doing for others that might benefit. I am not sure if this is the most efficient way to do this, so open to other feedback.
I created a script:
sequence:
- variables:
fan_percent: "{{ states('input_number.bedroom_fan_input') | int}}"
- action: alexa_devices.send_text_command
data:
device_id: 0420c740dc12a164f59744a83e242acb
text_command: Set bedroom fan fan to {{fan_percent}}