article

KAIYIN@AMAZON.COM avatar image
KAIYIN@AMAZON.COM posted

Use Smart Home gitHub sample Skill to test your response

When developing Smart Home Skill, one of the frequently asked questions we got from developers is: "Is this the correct way to call the Smart Home APIs?"

Without messing up your huge and complex Smart Home Skill, you can actually test the Smart Home API response format from the Sample Skill in Python provided by Alexa gitHub repository.

To begin with, follow the instruction on https://github.com/alexa/alexa-smarthome/wiki/Build-a-Working-Smart-Home-Skill-in-15-Minutes to build this Sample skill on your developer account.

Let's use Lock as an example, in the tech doc it described the response format:

https://developer.amazon.com/docs/device-apis/alexa-lockcontroller.html#response

Since we already have sample Lock device and capability for Lock, what's missing in the sample code is the response in Python, we can simply follow the current existing sample response, but make a Lock one:

if request_namespace == "Alexa.LockController":if request_name == "Lock": response ={
"context":{
"properties":[
{
"namespace":"Alexa.LockController",
"name":"lockState",
"value":"LOCKED",
"timeOfSample":get_utc_timestamp(),
"uncertaintyInMilliseconds":1000
}
]
},
"event":{
"header":{
"namespace":"Alexa",
"name":"Response",
"payloadVersion":"3",
"messageId":get_uuid(),
"correlationToken": "dFMb0z+PgpgdDmluhJ1LddFvSqZ/jCc8ptlAKulUj90jSqg=="

"endpoint": {

"scope": {

"type": "BearerToken",

"token": "access-token-from-Amazon"

},

"endpointId": "appliance-001"

},

"payload":{

}
}
}

return response

This is very simple, you just need to figure out what request format is (namespace and value), and follow the existing Python response code to configure the response. The value of each field are coming from the tech doc. You can test the Lock device from test simulator to see if the response format is correct, then use the same response format in your real Smart Home Skill.

Now, please try to do the same for other responses for Lock. :)

smart home
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Article

Contributors

hukaiyin contributed to this article

Related Articles