Pass template to RESTful command?

Is it possible to pass a template to a rest_command? This doesn’t work, but shows the intent:

service: rest_command.rhasspy_speak
data_template: >-
  "Today is {{ now().strftime("%A") }} the {{ now().strftime("%-d")}} {{ now().strftime("%B") }} {{ now().strftime("%y") }}"

I formerly used the Hermes Session controller, but rhasspy will no longer let me use an external MQTT. Doing so breaks the microphone input on rhasspy. I can use the internal MQTT to pass events to HA, but now need to use rhasspy speak to get speech back. Is there a way to use a template with rhasspy speak? Thanks.

A few things:

  • data_template: was deprecated years ago. Just use data:
  • You appear to have missed the payload: tag. You can’t just put the message after data:
  • The docs do indicate that you can use a template for the payload: tag:

payload template (optional)
A string/template to send with request.

  • If you’re introducing a multi-line template with >-, do not surround the template in quotes

More in the docs: https://www.home-assistant.io/integrations/rest_command/

Thank you for the prompt response. Here is the automation now:

service: rest_command.rhasspy_speak
data:
  payload_template: >-
    Today is {{ now().strftime("%A") }} the {{ now().strftime("%-d")}} {{
    now().strftime("%B") }} {{ now().strftime("%y") }}

Trace says that the payload parses correctly, but rhasspy is silent. It plays the wakeup sound, so audio output is okay. here is the config for the rest command:

rest_command:
  rhasspy_speak:
    url: 'http://192.168.0.130:12101/api/text-to-speech'
    method: 'POST'
    content_type: 'text/plain'
    payload: "{{ payload }}"

where 192.168.0.130 is the IP for the pi that rhasspy is running on. HA is at 192.168.0.109. Do you see anything wrong with the automation or the config?

I should also add that when I enter sample text in the rhasspy Text to Speech setting and click speak, it will speak the text.

this setup works for me. My rest_command.yaml is:

rhasspy_speak:
 url: '{{ ipnum }}/api/text-to-speech'
 method: 'POST'
 headers:
   accept: 'text/plain'
   Content-Type: 'text/plain'
 payload: '{{ payload_data }}'

and then in my HA automation I have a time trigger that I was just using to test if it would work. obviously use whatever trigger you wanted. note that even though yaml for rest_command has ‘payload’ when i use it in automation yaml it’s ‘payload_data’. You seem to be using ‘payload’ when maybe it should be ‘payload_template’ in your rest_command since that’s what you call it in the automation. hope that helps

alias: rhasspy_send_text_for_speech
description: ''
trigger:
  - platform: time
    at: '00:00:00'
condition: []
action:
  - data_template:
      ipnum: http://192.168.1.134:12101
      payload_data: hello from home assistant
    service: rest_command.rhasspy_speak
mode: single

Yes, on the rhasspy forum, I learned that data should carry the template, but not payload. Like this:

data_template:
  payload: >-

Thanks, Jared.