Hey so I recently tried to control my HA via API, I set it up to get the speaker to say whatever I sent over. something like:
POST
http://localhost:8123/api/services/tts/google_say
{
"cache": false,
"entity_id": "media_player.office_2",
"message": "Hello!"
}
Which works fine. However, if I try to send a message that requires templates, i.e. “The current time is {{ now() }}”, HA doesn’t process the templates first, it just outputs “The current time is now” in the speaker.
I am thinking if I could use a script to put the message into template translator before sending it to tts. Something like:
dynamic_tts_announcer:
alias: Dynamic TTS Announcer
sequence:
- variables:
cache: "{{ cache }}"
media_player_entity_id: "{{ media_player_entity_id }}"
raw_message: "{{ message }}"
- service: script.evaluate_message
data:
message: "{{ raw_message }}"
- service: tts.google_say
data:
cache: "{{ cache }}"
entity_id: "{{ media_player_entity_id }}"
message: "{{ states('input_text.tts_processed_message') }}"
mode: single
evaluate_message:
sequence:
- service: input_text.set_value
data_template:
entity_id: input_text.tts_processed_message
value: "{{ message }}"
This doesn’t work, it still just return “current time is now”. I am thinking if there is a way to explicitly trigger the template translator in evaluate_message
? or some better idea to get this working?