Hello,
I’m making my first steps in HA and I jumped directly in the deep water of YAML without having any knowledge. Anyway, I’ve done some interesting things but now I hit a wall. I’m trying to organize everything in scripts to avoid double work. I had a script that was called from Alexa and when called, it returns tts to Alexa. I decided to create a separate script alexa_tts which to use everytime I want alexa to say something. The script very basic (as of now):
The problem is that when I tried to call it from the other scrip with a message, it can’t pass it. After spending some time trying, I decided to do a test with automation and it worked, so the problem is not with the above script with how the other script is calling it. Can you help me, please?
This automation works:
alias: New Automation
trigger:
- platform: state
entity_id:
- light.bedroom_main_light
to: "on"
action:
- service: script.alexa_tts
data:
message: test
mode: single
This script - doesn’t:
alias: Test2
sequence:
- service: script.alexa_tts
data:
message: "{{ test }}"
mode: single
I tried all options in the message - test, “test”, “{{ test }}” - none of the worked.
The original script is much more complicated, so I decided to use the above just to simplify the problem.
It doesn’t matter how I call it. The moment I save it, I’m getting an error. It says undefined message.if I run it, nothing happens.
I’m calling the original script with alexa but as I said, that’s not the problem.
In the example that you say doesn’t work, you’re essentially trying to output the value of an undefined variable called “test”. You can see the error if you stick that in the template dev tool. Your indentation is a bit off as well, with 4 spaces rather than the 2 that you’re using everywhere else. test, "test" and "{{ 'test' }}" should all work.
alias: Test2
sequence:
- service: script.alexa_tts
data:
message: "{{ test }}"
mode: single
The moment I saved it, I did not get an error message. I don’t know what you did to get an error. Obviously you’ll have to fix it because it’s pointless to try to run it.
In my case, the way I would call it would be like this:
- service: script.test2
data:
test: Hello world
BTW, maybe it’s a copy-paste typo but script.alexa_tts contains doubled colons. You should remove one.