Search code examples
alexa-skills-kit

Alexa intent schema issues


I've been playing with Alexa skills and looking to do some basic home automation. I have defined the following basic intent schema to start:

{
  "intents": [
    {
      "intent": "Lock",
      "slots": [
        {
          "name" : "Door",
          "type" : "AMAZON.LITERAL"
        }
      ]
    },
    {
      "intent": "Unlock",
      "slots": [
        {
          "name" : "Door",
          "type" : "AMAZON.LITERAL"
        }
      ]
    }
  ]
}

And then the sample utterances:

Lock lock {slot value|Door}
Lock lock door {slot value|Door}
Lock lock the door {slot value|Door}
Unlock unlock {slot value|Door}
Unlock unlock door {slot value|Door}
Unlock unlock the door {slot value|Door}

The idea being that the door names would have to be freeform, since they won't be known ahead of time. However, when i try out a phrase like:

lock door front

It finds the right intent, but the "Door" slot value contains extra words:

"intent": {
  "name": "Lock",
  "slots": {
    "Door": {
      "name": "Door",
      "value": "door front"
    }
  }
}

Is this normal, or is it a byproduct of using an AMAZON.LITERAL? I've also tried a custom slot type, but multiple word device names don't seem to work well with it, and it always uses the last word in that case.


Solution

  • I would define utterances as ending with 'door' word:

    Lock lock {slot value|Door} door
    

    So, user will have to say:

    Alexa, ask Lock lock kitchen door
    

    So you would mostlikely receive only one word as a door type. Then you parse the string. You might want to test not for exact equality, but for inclusion. I have to admit that I never use LITERAL type, as it is not advised by Amazon tutorials, so I would define a custom type and list possible values for door type.

    Turning on/off lights/thermostats is a different story. You have to use Alexa SmartHome API for that. Then 'turn on/off', 'set value', etc become reserved key words for Alexa. There will be no intents like these (in your question) in SmartHome API, no utterances and no custom slot types. All you need is to implement processing Discovery request and Control request. I think user sets device names in official apps/accounts of device vendor, and when Alexa discovers device (due to Discovery request), the skill just fetches the devices descriptions from vendors server and provides it for Alexa. That is how Alexa will know the names of available devices.