Using states inside sequences for alexa responses

Hi,
When using the Alexa template, I want to have a list of possible responses. I have followed the instructions from the Home Assistant Alexa docs. The problem I’m having is that I want to include the state of a sensor in the random responses.
In my yaml file that I include, I’m trying to do something like this:

“response 1 {{ states(‘sample_sensor’)}}”,
“response 2 {{ states(‘anotehr_sensor’)}}”

How can I achieve this?
Right now, the responses work, but its not substituting the states. I just get the whole string back, including the {{ states(…)}} text.
My file does include the example code as listed in the documentation. I’m not including it here for simplicity.
Hopefully this makes sense to someone.

I have a skill with the invocation “tell me the status” so I can ask

“Alexa, tell me the status of the kitchen light”

check out the speech part for the state status syntax

    statussensor:
      speech:
        type: plaintext
        text: >
          {%- for state in states -%}
            {%- if state.name.lower() == Sensor.lower() -%}
              {%- if loop.first %}The {% elif loop.last %} and the {% else %}, the {% endif -%}
              {{ state.name }} status is {{ state.state }} {{- state.attributes.unit_of_measurement}}
            {%- endif -%}
          {%- else -%}
            Sorry, I can't find the status of {{ state.name }}
          {%- endfor -%}
2 Likes

Hello,
Thanks for the example, but I’m not sure this will do what I’m trying to achieve.
What I want is to have the response I get back from the template be different every time I invoke it. I’m basically trying to have multiple ways of saying the same thing, but each time add a sensor value in the response.
This is very similar to the example in the Alexa docs for home Assistant, just adding a sensor value to each of those responses.
When i do that, the code in the braces isn’t being evaluated. I’m not sure if this is because the sequence of responses is also inside braces?