1

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.

miken32
  • 42,008
  • 16
  • 111
  • 154
Matt
  • 11,523
  • 2
  • 23
  • 33

3 Answers3

2

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.

rightaway717
  • 2,631
  • 3
  • 29
  • 43
  • I would agree, literal is not optimal, but the user has the ability to make this any value they want when they set up the system. In particular, when talking about turning on and off lights / thermostats, etc.... The user would have to give them meaningful names to them. Obviously, these names could not be known ahead of time. I could create a custom slot and put some likely values, but i'm not sure what that would buy me. – Matt Jul 20 '16 at 00:28
  • smarthome api seems the right way to go, though i'm having trouble with the account linking. i'm getting the login page, and see the request going to the skill api with the state and code, but it always errors out :( – Matt Jul 20 '16 at 17:11
  • Certificate problem. Amazon for whatever reason seems to not support the list of cert authorities it claims to. So I can't exchange the auth token for an access token successfully – Matt Jul 21 '16 at 11:39
  • @Matt I don't know if it helps you, this link provides a guide to use Amazon server for authentication http://stackoverflow.com/questions/37512303/whats-an-easy-way-to-setup-oauth-for-an-amazon-alexa-connected-home-skill/37517763#comment64332252_37517763 – rightaway717 Jul 21 '16 at 13:22
  • Not really. I need the right access token for my backend system – Matt Jul 21 '16 at 19:32
1

Alexa stops with the first match it finds. So you need to move the more general utterances after the more specific.

Lock lock door {slot value|Door} Lock lock {slot value|Door}

This way "lock door front" matches with slot = "front".

If you have any utterances with no slots, be sure to put them LAST.

DavidCC
  • 315
  • 2
  • 10
0

Update: The comment I made about LITERAL going away is dated. Thanks for pointing it out. LITERAL will remain. But Alexa (and Lex) do return slot values not in the slot list. I see this often. It's nice.

For those that may stumble across this question, know that skills using AMAZON.LITERAL will no longer be approved starting in December, 2016. You should use custom slots instead. Interesting, the documentation says that even when using custom slots you can receive words not defined in the custom list, like with a literal. I've not tested for this, but it could come in handy.

ScottU
  • 75
  • 3
  • 2
    Just as a note, Amazon has changed their mind and decided NOT to deprecate AMAZON.LITERAL. – PaulPerry Jan 31 '17 at 19:17
  • 1
    @ScottU Here is the link https://developer.amazon.com/blogs/post/Tx3IHSFQSUF3RQP/why-a-custom-slot-is-the-literal-solution – Soumya Apr 07 '17 at 20:15