If statement using state of sensor identified by Alexa slot variable

I’ve gotten this to work up to this point, but so far, no matter what I try I’m missing something in the HA intent config. Below is my intent config as it is. The door is shut, but it always comes back saying it’s open. The last update I made was to the “The Door is open.” text to add the replace part just to make sure that worked and it does. It responds with “The front_door is open.” And, just to confirm, I did have it working properly when specifically saying binary_sensor.front_door before changing things up to make it more flexible.

    DoorStatusIntent:
      speech:
        text: >
          {% if is_state("binary_sensor.{{ Door | replace(' ','_') }}", "off") %}
            The {{ Door }} is closed.
          {% else %}
            The {{ Door | replace(' ','_') }} is open.
          {% endif %}

This is the response I get on the Alexa test page when I use “Front Door Status” to activate it.

    {
      "version": "1.0",
      "response": {
        "outputSpeech": {
          "text": "The front_door is open.",
          "type": "PlainText"
        },
        "speechletResponse": {
          "outputSpeech": {
            "text": "The front_door is open."
          },
          "shouldEndSession": true
        }
      },
      "sessionAttributes": {}
    }

And this is the Alexa Intent config.

    {
      "intents": [
        {
          "intent": "DoorStatusIntent",
          "slots": [
            {
              "name": "Door",
              "type": "Doors"
            }
          ]
        }
      ]
    }

And the slot config.

Type 	Values 	
Doors 	Front Door | Back Door

Got it finally, thanks to this post.

Changed the intent to this:

DoorStatusIntent:
  speech:
    text: >
      {% if is_state("binary_sensor." ~ (Door | replace(' ','_')), "off") %}
        The {{ Door }} is closed.
      {% else %}
        The {{ Door }} is open.
      {% endif %}
1 Like