question

newuser-1385ae83-500a-41cf-bf34-99342bd3f87c avatar image

Virtual device is unresponsive

I have written custom skill which discovers virtual devices. When I run it on emulator is returns positive acknowledgement 'OK'. But when I try to access the current status of that device through alexa app it shows device is unresponsive and always show device is off.

lambda Function :

exports.handler = function (request, context) {
    if (request.directive.header.namespace === 'Alexa.Discovery' && request.directive.header.name === 'Discover') {
        log("DEBUG:", "Discover request",  JSON.stringify(request));
        handleDiscovery(request, context, "");
    }
    else if (request.directive.header.namespace === 'Alexa.PowerController') {
        if (request.directive.header.name === 'TurnOn' || request.directive.header.name === 'TurnOff') {
            log("DEBUG:", "TurnOn or TurnOff Request", JSON.stringify(request));
            handlePowerControl(request, context);
        }
    }


    function handleDiscovery(request, context) {
        var payload = {
            "endpoints":
            [
                {
                    "endpointId": "6f31dc57-d033-4cbd-8020-6bbb516bcab",
                    "manufacturerName": "Smart Device Company",
                    "friendlyName": "Bedroom Outlet",
                    "description": "Smart Device Switch",
                    "displayCategories": ["LIGHT"],
                    "isReachable": true,
                    "cookie": {
                        "key1": "arbitrary key/value pairs for skill to reference this endpoint.",
                        "key2": "There can be multiple entries",
                        "key3": "but they should only be used for reference purposes.",
                        "key4": "This is not a suitable place to maintain current endpoint state."
                    },
                    "capabilities":
                    [
                        {
                            "type":"AlexaInterface",
                            "interface":"Alexa.ColorTemperatureController",
                            "version":"3",
                            "properties":{
                                "supported":[
                                {
                                  "name":"colorTemperatureInKelvin"
                                }
                            ],
                            "proactivelyReported":true,
                            "retrievable":true
                            }
                        },
                        {
                            "type": "AlexaInterface",
                            "interface": "Alexa.PowerController",
                            "version": "3",
                            "properties": {
                            "supported": [ {
                                "name": "powerState"
                            } ],
                            "proactivelyReported": true,
                            "retrievable": true
                            }
                        },
                        {
                            "type":"AlexaInterface",
                            "interface":"Alexa",
                            "version":"3"
                        },
                        {
                            "type":"AlexaInterface",
                            "interface":"Alexa.ColorController",
                            "version":"3",
                            "properties":{
                                "supported":[
                                {
                                    "name":"color"
                                }
                            ],
                            "proactivelyReported":true,
                            "retrievable":true
                            }
                        }
                    ]
                }
            ]
        };
        var header = request.directive.header;
        header.name = "Discover.Response";
        log("DEBUG", "Discovery Response: ", JSON.stringify({ header: header, payload: payload }));
        context.succeed({ event: { header: header, payload: payload } });
    }


    function log(message, message1, message2) {
        console.log(message + message1 + message2);
    }


    function handlePowerControl(request, context) {
        // get device ID passed in during discovery
        var requestMethod = request.directive.header.name;
        // get user token pass in request
        var requestToken = request.directive.endpoint.scope.token;
        var powerResult;


        if (requestMethod === "TurnOn") {


            // Make the call to your device cloud for control 
            // powerResult = stubControlFunctionToYourCloud(endpointId, token, request);
            powerResult = "ON";
        }
       else if (requestMethod === "TurnOff") {
            // Make the call to your device cloud for control and check for success 
            // powerResult = stubControlFunctionToYourCloud(endpointId, token, request);
            powerResult = "OFF";
        }
        var contextResult = {
            "properties": [{
                "namespace": "Alexa.PowerController",
                "name": "powerState",
                "value": powerResult,
                "timeOfSample": "2017-09-03T16:20:50.52Z", //retrieve from result.
                "uncertaintyInMilliseconds": 500
            }]
        };
        var tok = request.directive.endpoint.scope.token;
        var endpointResult = {
            "scope":  {
                "type": "BearerToken",
                "token": tok
            },
            "endpointId": "6f31dc57-d033-4cbd-8020-6bbb516bcab"
        };
        var responseHeader = request.directive.header;
        responseHeader.name = "Response";
        responseHeader.namespace= "Alexa";
        responseHeader.messageId = responseHeader.messageId + "-R";
        var response = {
            context: contextResult,
            event: {
                header: responseHeader,
                endpoint: endpointResult,
                payload: {}
            }
        };
        log("DEBUG", "Alexa.PowerController ", JSON.stringify(response));
        context.succeed(response);
    }
};

test - event :
***************************

{
  "directive": {
    "header": {
      "namespace": "Alexa.PowerController",
      "name": "TurnOn",
      "payloadVersion": "3",
      "messageId": "1bd5d003-31b9-476f-ad03-71d471922820",
      "correlationToken": "dFMb0z+PgpgdDmluhJ1LddFvSqZ/jCc8ptlAKulUj90jSqg=="
    },
    "endpoint": {
      "scope": {
        "type": "BearerToken",
        "token": "access-token-from-1111"
      },
      "endpointId": "demo_id",
      "cookie": {}
    },
    "payload": {}
  }
}

********************************************

Response : 

 **************************************************************************
Response:
{
  "context": {
    "properties": [
      {
        "namespace": "Alexa.PowerController",
        "name": "powerState",
        "value": "ON",
        "timeOfSample": "2017-09-03T16:20:50.52Z",
        "uncertaintyInMilliseconds": 500
      }
    ]
  },
  "event": {
    "header": {
      "namespace": "Alexa",
      "name": "Response",
      "payloadVersion": "3",
      "messageId": "1bd5d003-31b9-476f-ad03-71d471922820-R",
      "correlationToken": "dFMb0z+PgpgdDmluhJ1LddFvSqZ/jCc8ptlAKulUj90jSqg=="
    },
    "endpoint": {
      "scope": {
        "type": "BearerToken",
        "token": "access-token-from-1111"
      },
      "endpointId": "6f31dc57-d033-4cbd-8020-6bbb516bcab"
    },
    "payload": {}
  }
}
alexa skills kitalexa smart homelambdaresponsedevice discovery
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

Anand@Amazon avatar image
Anand@Amazon answered

Hello there,

Please provide skill id for further debugging.

2 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.

I would also like some help with this issue as my virtual devices are all unresponsive

Skill ID: amzn1.ask.skill.c06eba03-0506-4486-9efa-e6aecd324405

0 Likes 0 ·

Hello there,

For this issue I will suggest to add "Alexa.EndpointHealth" interface also as capability which represent information about overall health of a smart home device.

Please also send "stateReport" for ReportState event and also send ChangeReport event to Alexa event gateway to get latest endpoint state.

Check this link to learn more about EndpointHealth interface.

0 Likes 0 ·