Help with using template inside a dictionary

Hi all,
I’m trying to send a dictionary with an embedded template in an automation.
The service call works fine without the template variable but whenever I add the template, I get :
Error: Error rendering data template: Result is not a Dictionary
Here is my automation.

alias: Mqqt Speak to Rhasspy
description: ""
trigger:
  - platform: mqtt
    topic: Speak
condition: []
action:
  - service: rest_command.rhasspy_tts
    data: "{'text': {{states('sensor.mqtt_speak')}} }"
mode: single

I’ve tested the template
{{states('sensor.mqtt_speak')}}

in the Template Editor (Development tab) and it works fine.
Any help is greatly appreciated.

You should define it like this:

action:
  - service: rest_command.rhasspy_tts
    data:
      text: "{{ states('sensor.mqtt_speak') }}"

You are currently setting “data” to a string value.

1 Like

That works great. I was mixing json with yaml, doh.
Thanks for the help.