question

Fabián Romo avatar image
Fabián Romo asked

How can a single skill be linked for multiple objects created in AWS IoT independently?

Hi.

I'm developing a hardware that obeys voice commands from an Alexa skill.


The skill is associated with a lambda function that has the name of the AWS iot object and the endpoint of the skill.


Everything works very well.


But when I want to distribute my skill, it will obviously only work for my hardware.


I want to build multiple devices, that means creating multiple objects in AWS iot.


My question when the user downloads the Skill, how can it be configured so that he can enter the name of the object, of the hardware that the user has purchased.


So far the most absurd and crappy solution I can think of is to create a skill for each of the devices.


Any suggestions or comments?

submission testing distributionskillsalexa skills
10 |5000

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

1 Answer

KirkC@Amazon avatar image
KirkC@Amazon answered

When it comes to Alexa smart home skills, you as a skill developer are required to implement account linking for your skill.

The main practical benefit with regard to smart home skills specifically is that you as the developer, are supposed to maintain a "device cloud" where you associate each user with their own devices.

Therefore, when your skill receives a request, it will contain an OAuth2 bearer token located at endpoint.scope.token. You are to use this OAuth2 token to identify the user in your own database and thus you should be able to query and command their devices.

Now, as far as how you would go about interacting with devices as they are represented in AWS IoT specifically, that would be a better question to route to the AWS team.

The AWS IoT forums can be found here:
https://forums.aws.amazon.com/forum.jspa?forumID=210&start=0

AWS support can be reached out to here:
https://aws.amazon.com/contact-us/

8 comments
10 |5000

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

Or for the skill to send behind the scenes an ID for each voice command, that ID goes to the lambda function and decides which aws-iot object to interact with.

I see. This scenario you've described here seems to most closely match what happens with Alexa smart home skill requests.

When you receive an "Alexa.Discovery" "Discover" directive, your skill's Lambda function must respond with an "Alexa.Discovery" "Discover.Response":
https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-discovery.html#response

In your Discover.Response JSON, there will be a payload.endpoints array which includes one or more objects describing the metadata and capabilities of each of your devices. These values include "endpointId", which is a unique identifier associated with a particular device and "friendlyName", which is the spoken name of the device.

For example then, let's say I have the following Discover.Response JSON:

{
    "event": {
        "header": {
            "namespace": "Alexa.Discovery",
            "name": "Discover.Response",
            "payloadVersion": "3",
            "messageId": "d2ae86a8-e600-4437-9e87-8d5f028c3b90"
        },
        "payload": {
            "endpoints": [
                {
                    "endpointId": "amazon-standard-bulb-001",
                    "friendlyName": "Standard Light Bulb",
                    "description": "Standard Light Bulb",
                    "manufacturerName": "Amazon Heavy Industries",
                    "displayCategories": [
                        "LIGHT"
                    ],
                    "cookie": {},
                    "capabilities": [
                        {
                            "type": "AlexaInterface",
                            "interface": "Alexa.PowerController",
                            "version": "3",
                            "properties": {
                                "supported": [
                                    {
                                        "name": "powerState"
                                    }
                                ],
                                "proactivelyReported": true,
                                "retrievable": true
                            }
                        },
                        {
                            "type": "AlexaInterface",
                            "interface": "Alexa.EndpointHealth",
                            "version": "3",
                            "properties": {
                                "supported": [
                                    {
                                        "name": "connectivity"
                                    }
                                ],
                                "proactivelyReported": true,
                                "retrievable": true
                            }
                        },
                        {
                            "type": "AlexaInterface",
                            "interface": "Alexa",
                            "version": "3"
                        }
                    ]
                }
            ]
        }
    }
}


The above describes a light bulb which supports the Alexa.PowerController interface. The "friendlyName" of the device is "Standard Light Bulb" and it's "endpointId" is "amazon-standard-bulb-001".

Having now successfully discovered this device, when I as a user say "Alexa, turn on the 'standard light bulb'", my skill back-end will be sent the following "Alexa.PowerController" "TurnOn" directive:


{
    "directive": {
        "header": {
            "namespace": "Alexa.PowerController",
            "name": "TurnOn",
            "payloadVersion": "3",
            "messageId": "b0a86222-7b89-416f-9d37-3e70905a19c6",
            "correlationToken": "token-redacted"
        },
        "endpoint": {
            "scope": {
                "type": "BearerToken",
                "token": "token-redacted"
            },
            "endpointId": "amazon-standard-bulb-001",
            "cookie": {}
        },
        "payload": {}
    }
}


Observe that this directive includes the "directive.endpoint.endpointId" of "amazon-standard-bulb-001" so I know which device the request is intended for. Additionally, assuming you've set up account linking to your own "device cloud", you will be able to figure out which account made this request by using the directive.endpoint.scope.token to interact with your own OAuth identity provider.

In this manner, a single smart home skill and Lambda function can handle directives not only for multiple devices, but also for multiple accounts, each of which may in turn have multiple devices.

1 Like 1 ·

Thank you very much for your information, they are new concepts and I will investigate them.

I've tried adding to my custom skill, but can't find something called the Alexa.Discovery interface.

I imagine that for my case it is the Custom Interface Controller option. Am I correct?

custon-interface.png

0 Likes 0 ·

When it comes to Alexa skills, there's multiple "types" of skills that you can choose from.

Custom skills require the use of an invocation name to launch and do not natively have a concept of smart home devices per se. Within a custom skill you define "intents" and associate sample utterances with those intents. For example, if you have a trivia skill, you might have a "GetNewFactIntent" with an associated sample utterance of "tell me a new fact":
https://developer.amazon.com/en-US/docs/alexa/custom-skills/steps-to-build-a-custom-skill.html

Separately, we also have "Smart Home" skills. Smart home skills do not require the use of an invocation name and to interact with devices, the user simply uses the name of the device, rather than the name of the skill. Smart home skills are where you'll find a concept of device discovery. For more information about getting started with smart home skills, please see the following documentation:
https://developer.amazon.com/en-US/docs/alexa/smarthome/steps-to-build-a-smart-home-skill.html


0 Likes 0 ·
Show more comments

Thank you very much for answering.


What happens is that I'm developing a hardware based on a microcontroller that uses the Shadows example from FreeRTOs to access the AWS iot object.


All microcontroller manufacturers who try to provide examples for creating a controlled system with Alexa voice commands, do not use 'Smart home skills'. Create your own skill to interact with the hardware.


Now, I just created a "Smart Home" skill and by doing that, I see that I have no way to write my own JSON. (it doesn't have the "Costume" option)


So it seems to me that this is not the way to solve my problem. If so, they would start with the creation of a skill of the "Smart Home" type.

0 Likes 0 ·

I'm afraid I might not fully understand the question at hand, but if I understood correctly, it sounds like you're looking for a way to manufacture smart home devices which can be controlled by Alexa Echo devices directly, without having to create an Alexa skill at all, correct?

If so, then you might instead be interested in either of the following:

Alexa Connect Kit (ACK):

Alexa Connect Kit (ACK) allows devices to connect with Alexa without needing to manage cloud services or to create an Alexa smart home skill.

Forum Space: https://amazon.developer.forums.answerhub.com/spaces/451/index.html
Documentation: https://developer.amazon.com/en-US/alexa/devices/connected-devices/development-resources/alexa-connect-kit


Zigbee:

Certain Alexa Echo devices have built-in Zigbee hubs which can be used to control Zigbee devices.

Documentation: https://developer.amazon.com/en-US/docs/alexa/smarthome/zigbee-support.html

0 Likes 0 ·

No.

I'm designing a skill to control hardware based on voice commands.


Here what we accomplished on a development board. We are currently designing our own PCB based on that board:

Voice command control with Alexa and the PIC32MZ microcontroller


We haven't finished our custom skill yet, following the microcontroller manufacturer's guide.


For each microcontroller used, an object can be created in aws-iot


But until now I don't know how a single skill could control several microcontrollers (aws iot objects) independently.

For example, a solution could be that the skill has more than one lamnda function (one for each aws-iot object).


Or for the skill to send behind the scenes an ID for each voice command, that ID goes to the lambda function and decides which aws-iot object to interact with.


This ID would be entered after downloading the skill and executing it. Once stored somewhere, the user executes the voice commands and only interacts with the microcontroller assigned that ID.

0 Likes 0 ·