TTS and message templates

Hi.

I am having trouble making my TTS work with message templates.
I am trying to do a welcome home announcement, depending on who just arrived home. The trigger works just fine, but I cant get my message to be played out, when I try working with if/else.

The service of my automation looks like this:

  action:
    - service: tts.google_say
      data_template:
        entity_id: media_player.livingroom
        message: >
          {% if (states.sensor.stue_motion_sensor_temp.state < 20) %}
            "Velkommen hjem, WonderMoose. Temperaturen i stuen er '{{ states.sensor.stue_motion_sensor_temp.state | round(0) }}' grader. Måske du burde overveje, at tænde op i brændeovnen."
          {% else %}
            "Velkommen hjem, WonderMoose. Temperaturen i stuen er '{{ states.sensor.stue_motion_sensor_temp.state | round(0) }}' grader."
          {% endif %} 
        language: "da"
    - service: input_boolean.turn_off
      entity_id: input_boolean.wondermoose_lige_kommet_hjem 

The input boolean turns on when I arrive home, and turns off automatically after 3 minutes, or through this automation.
I cant seem to figure, where the message part dies. I have done this by looking at several examples. The tts works just fine, if I do a simple message with no if/else stuff. And then the boolean also turns off.
With the if/else stuff, the message is not read out, and the boolean is not turned off.

1 Like

try removing the quotation marks from around the outside of the messages. I had that bite me once on a message sent to alexa over tts.

And just to be sure force the 20 to an int

message: >
  {% if (states.sensor.stue_motion_sensor_temp.state | int < 20) %}
    Velkommen hjem, WonderMoose. Temperaturen i stuen er '{{ states.sensor.stue_motion_sensor_temp.state | round(0) }}' grader. Måske du burde overveje, at tænde op i brændeovnen.
  {% else %}
    Velkommen hjem, WonderMoose. Temperaturen i stuen er '{{ states.sensor.stue_motion_sensor_temp.state | round(0) }}' grader.
  {% endif %}

Did you try the automation tts? I’m not sure the language part is defined in the automation, but in the tts setup in the configuration.yaml

Forcing it to int worked! Thanks! :slight_smile:

2 Likes

Stærkt :slight_smile: Den napper jeg da lige til at lave lidt sjov herhjemme :metal:

1 Like