question

Shahzeb Ihsan avatar image
Shahzeb Ihsan asked

Alexa can't discover device if interface is changed from Alexa.PowerController to Alexa.DoorbellEventSource

Hi all,


I followed the following example to get a working SmartHome skill for a Switch:

https://github.com/alexa-samples/skill-sample-python-smarthome-switch

I am now trying to create a SmartHome skill for a Doorbell, so I changed the lambda function's endpoint capability specification from the example to this:

    if namespace == 'Alexa.Discovery':
        if name == 'Discover':
            adr = AlexaResponse(namespace='Alexa.Discovery', name='Discover.Response')
            capability_alexa = adr.create_payload_endpoint_capability()
            capability_alexa_doorbelleventsource = adr.create_payload_endpoint_capability(
                interface='Alexa.DoorbellEventSource',
                proactivelyReported=True)
            adr.add_payload_endpoint(
                friendly_name='Sample DoorbellEventSource',
                endpoint_id='sample-doorbell-01',
                displayCategories=["DOORBELL"],
                capabilities=[capability_alexa, capability_alexa_doorbelleventsource])
            return send_response(adr.get())


This is the JSON response from the lambda function:

{
  "event": {
    "header": {
      "namespace": "Alexa.Discovery",
      "name": "Discover.Response",
      "messageId": "d7afa78e-6d7a-4681-a836-3da796e0e3e0",
      "payloadVersion": "3"
    },
    "payload": {
      "endpoints": [
        {
          "capabilities": [
            {
              "type": "AlexaInterface",
              "interface": "Alexa",
              "version": "3",
              "properties": {
                "proactivelyReported": true
              }
            },
            {
              "type": "AlexaInterface",
              "interface": "Alexa.DoorbellEventSource",
              "version": "3",
              "properties": {
                "proactivelyReported": true
              }
            }
          ],
          "description": "Sample Endpoint Description",
          "displayCategories": [
            "DOORBELL"
          ],
          "endpointId": "sample-doorbell-01",
          "friendlyName": "Sample DoorbellEventSource",
          "manufacturerName": "Sample Manufacturer"
        }
      ]
    }
  }
}


But Alexa can't discover any devices from this skill. I don't think this is not a problem with the region because if I change the interface type back to Alexa.PowerController (with other related changes), device discovery works fine, but in any case, if it is relevant, I am using "Ireland" since I am located in Germany.

alexa smart homesmart homealexa skillsdevice 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

Shahzeb Ihsan avatar image
Shahzeb Ihsan answered

I figured out that the "proactivelyReported" capability was being returned incorrectly i.e. nested inside "properties". There is a bug in the following file in the Alexa SmartHome example which only allows "proactivelyReported" to be nested inside "properties":

https://github.com/alexa-samples/skill-sample-python-smarthome-switch/blob/master/lambda/smarthome/alexa/skills/smarthome/alexa_response.py


Changing the function to the following, fixed the problem with the discovery:

def create_payload_endpoint_capability(self, **kwargs):
    capability = {
        'type': kwargs.get('type', 'AlexaInterface'),
        'interface': kwargs.get('interface', 'Alexa'),
        'version': kwargs.get('version', '3'),
        'proactivelyReported': kwargs.get('proactively_reported', False)
    }
    supported = kwargs.get('supported', None)
    if supported:
        capability['properties'] = {}
        capability['properties']['supported'] = supported
        capability['properties']['proactivelyReported'] = kwargs.get('proactively_reported', False)
        capability['properties']['retrievable'] = kwargs.get('retrievable', False)
    return capability

This then sends the following "correct" (expected) response:

{
  "event": {
    "header": {
      "namespace": "Alexa.Discovery",
      "name": "Discover.Response",
      "messageId": "0729bfb7-291d-48db-99ce-67a9f92256cf",
      "payloadVersion": "3"
    },
    "payload": {
      "endpoints": [
        {
          "capabilities": [
            {
              "type": "AlexaInterface",
              "interface": "Alexa",
              "version": "3",
              "proactivelyReported": false
            },
            {
              "type": "AlexaInterface",
              "interface": "Alexa.DoorbellEventSource",
              "version": "3",
              "proactivelyReported": true
            }
          ],
          "description": "Sample Endpoint Description",
          "displayCategories": [
            "DOORBELL"
          ],
          "endpointId": "sample-doorbell-01",
          "friendlyName": "Sample DoorbellEventSource",
          "manufacturerName": "Sample Manufacturer"
        }
      ]
    }
  }
}


10 |5000

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