Templated Action problem in Dialogflow Script

I’m trying to wrap my head around the syntax and formatting of intent scripts when it comes to dialogflow fulfillment. I’ve got a couple working properly, parsing variable values and returning them to the speaker. However, the toggleClimate function at the bottom always fails.

Here’s what I get from the dev-info console. (It leads me to suspect I’m somehow creating an array of length 1 with my data_template)

Error executing service <ServiceCall climate.turn_off (c:7244079fb8b84505acb360efdda5c0af): entity_id=['climate.living_room']>

The first two intents succeed. Calling the third intent always returns the default error response, and I get this in the dialog flow console log:

{
  "id": "ca5866c7-278c-4f2c-8d63-ecfa37143a5a",
  "timestamp": "2018-09-05T04:48:46.344Z",
  "lang": "en",
  "result": {
    "source": "agent",
    "resolvedQuery": "turn off the air in the living room",
    "action": "toggleClimate",
    "actionIncomplete": false,
    "parameters": {
      "room": "Living Room",
      "OnOff": "off"
    },
    "contexts": [],
    "metadata": {
      "isFallbackIntent": "false",
      "webhookResponseTime": 10001,
      "intentName": "toggleClimate",
      "intentId": "2f298b1b-74a6-48b5-9083-694576411b25",
      "webhookUsed": "true",
      "webhookForSlotFillingUsed": "false",
      "endConversation": true
    },
    "fulfillment": {
      "speech": "I tried, but I failed you.",
      "messages": [
        {
          "type": 0,
          "speech": "I tried, but I failed you."
        }
      ]
    },
    "score": 1
  },
  "status": {
    "code": 206,
    "errorType": "partial_content",
    "errorDetails": "Webhook call failed. Error: Request timeout."
  },
  "sessionId": "be81b3db-9248-4af9-5ec2-d4c3a01e9cf4"
}

Here’s the contents of intent_script.yaml:

getTemperature:
  speech:
    text: >
      {%- if room == "Master Bedroom" -%}
        It's currently {{ states("sensor.bedroom_temperature") }} degrees in the bedroom.
      {%- elif room == "Living Room" -%}
        It's currently {{ states("sensor.message_board_temp") }} degrees in the living room.
      {%- else -%}
        I didn't catch the name of the room.
      {%- endif -%}
getClimate:
  speech:
    text: >
      {%- if room == "Master Bedroom" -%}
        The AC is {{ states("climate.bedroom") }}, and the thermostat is set to {{ states.climate.bedroom.attributes.temperature }}.
      {%- elif room == "Living Room" -%}
        The AC is {{ states("climate.living_room") }}, and the thermostat is set to {{ states.climate.living_room.attributes.temperature }}.
      {%- else -%}
        I didn't catch the name of the room. The AC in the bedroom is set to {{ states("climate.bedroom") }}, and the living room is set to {{ states("climate.living_room") }}.
      {%- endif -%}
toggleClimate:
  speech:
    text: Turning the AC {{ OnOff }} in the {{ room }}
  action:
    - service_template: >
        {%- if OnOff == "on" -%}
          climate.turn_on
        {%- else -%}
          climate.turn_off
        {%- endif -%}
      data_template:
        entity_id: >
          {%- if room == "Master Bedroom" -%}
            climate.bedroom
          {%- elif room == "Living Room" -%}
            climate.living_room
          {%- endif -%}

What have I got wrong?

Typically, this isn’t possible. All jinja returns strings. Have you tried executing the service in the service template area?

also, what does the log say before that error?

You nailed it! I was calling the wrong service. Apparently, to turn on a generic thermostat, you need to call climate.set_operation_mode to “cool” rather than call climate.turn_on or turn_off.

Odd.

1 Like