Search code examples
alexa-skills-kitalexa-smart-home-skill

Alexa Smart Home "Failed to Retrieve State"


I am playing with a sample Alexa Smart Home skill - I am not talking to any real hardware or back-end, just trying to get message flow working. I have set up a simple switch/plug/light that can just support turning On/Off - and I have account linked working and the skill enabled. When I try looking at it via the Alexa app on phone or web (with debug enabled) it always says the device isn't responding, or it's "Failed to Retrieve State". I can definitely see the messages in Cloud Watch as follows.

Any idea why I'd be chronically getting such a response??

Request:

    "directive": {
        "endpoint": {
            "cookie": {},
            "endpointId": "endpoint-003",
            "scope": {
                "token": "<<<SUPRESSING>>",
                "type": "BearerToken"
            }
        },
        "header": {
            "correlationToken": "<<SHORTENED>>",
            "messageId": "50397414-bb9d-412f-8a2c-15669978ab64",
            "name": "ReportState",
            "namespace": "Alexa",
            "payloadVersion": "3"
        },
        "payload": {}
    }
}

Response:

{
    "context": {
        "properties": [
            {
                "name": "connectivity",
                "namespace": "Alexa.EndpointHealth",
                "timeOfSample": "2020-06-29T16:49:59.00Z",
                "uncertaintyInMilliseconds": 0,
                "value": "OK"
            },
            {
                "name": "powerState",
                "namespace": "Alexa.PowerController",
                "timeOfSample": "2020-06-29T16:49:59.00Z",
                "uncertaintyInMilliseconds": 0,
                "value": "ON"
            }
        ]
    },
    "event": {
        "endpoint": {
            "endpointId": "endpoint-003",
            "scope": {
                "token": "Alexa-access-token",
                "type": "BearerToken"
            }
        },
        "header": {
            "correlationToken": "<<SHORTENED>>",
            "messageId": "7a8b9a71-adda-41b8-acba-4d3855374845",
            "name": "Response",
            "namespace": "Alexa",
            "payloadVersion": "3"
        },
        "payload": {}
    }
}

Solution

  • Problem was: The "name" in my header response should have been "ReportState". "Response" is only used for things that set/change values.

    My general advice is to always verify that THREE things are good:

    1. Initial "Discovery"
    2. "Response" messages
    3. General "ReportState" queries.

    By this - I mean that:

    1. Anything you advertised as should be reported in "discovery" better be reported in other ("ReportState") messages. If you advertise a "PowerController" - if your ReportStates don't contain status for that, you'll either not see the status, or it'll keep retrying forever (continuing to look for it) - or you might get some sort of an error.
    2. If you CHANGED your discovery stuff - make sure that you really removed, re-discovered, and that the states (above) for the new additions/removals are okay
    3. Always make sure that "EndpointHealth" is being reported.