Alexa.ContactSensor Interface 3


Implement the Alexa.ContactSensor interface in your Alexa skill for devices that detect contact between two surfaces. For example, a contact sensor can report whether a door or window is open or closed. For more details about security skills, see Smart Home Security Overview.

If your contact sensors are components of a larger security system, your skill can also implement the Alexa.MotionSensor and Alexa.SecurityPanelController interfaces for a unified customer experience.

For the list of languages that the ContactSensor interface supports, see List of Alexa Interfaces and Supported Languages. For the definitions of the message properties, see Alexa Interface Message and Property Reference.

Contact sensor overview

A contact sensor typically has two components; a main component and a magnet component. When the components are in contact with each other, the sensor is closed. When they lose contact, the sensor is open.

The following image shows the open and closed states of a contact sensor on a window.

Utterances

When you use the Alexa.ContactSensor interface, the voice interaction model is already built for you. The following examples show some customer utterances:

Alexa, is the bedroom window open?

After the customer says one of these utterances, Alexa sends a corresponding state report request to your skill.

Reportable properties

The Alexa.ContactSensor interface uses detectionState as the primary property. You can use the following values for detectionState.

Value Description
DETECTED The sensor is open and the two pieces of the sensor aren't in contact with each other. For example, after a window is opened.
NOT_DETECTED The sensor is closed and the two pieces of the sensor are in contact with each other.

Discovery

You describe endpoints that support Alexa.ContactSensor using the standard discovery mechanism described in Alexa.Discovery.

Set retrievable to true for the properties that you report when Alexa sends your skill a state report request. Set proactivelyReported to true for the properties that you proactively report to Alexa in a change report.

Use CONTACT_SENSOR for the display category. For the full list of display categories, see display categories.

Sensor devices must also implement Alexa.EndpointHealth.

Discover response example

The following example shows a Discover.Response message for a contact sensor device that supports the Alexa.ContactSensor interface.

Copied to clipboard.

{
  "event": {
    "header": {
      "namespace": "Alexa.Discovery",
      "name": "Discover.Response",
      "payloadVersion": "3",
      "messageId": "Unique identifier, preferably a version 4 UUID"
    },
    "payload": {
      "endpoints": [
        {
          "endpointId": "Unique ID of the endpoint",
          "manufacturerName": "Manufacturer of the endpoint",
          "description": "Smart Sensor by Sensor Maker",
          "friendlyName": "Bedroom window",
          "displayCategories": ["CONTACT_SENSOR"],
          "cookie": {},
          "capabilities": [
            {
              "type": "AlexaInterface",
              "interface": "Alexa.ContactSensor",
              "version": "3",
              "properties": {
                "supported": [
                  {
                    "name": "detectionState"
                  }
                ],
                "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"
            }
          ]
        }
      ]
    }
  }
}

Directives

The Alexa.ContactSensor interface doesn't define any directives.

State reporting

Support the ReportState directive so that customers can ask about the state of their contact sensors.

The following examples show user utterances:

Alexa, is the bedroom window open?

Alexa sends a ReportState directive to request information about the state of an endpoint. When Alexa sends a ReportState directive, you send a StateReport event in response. The response contains the current state of all retrievable properties in the context object. You identify your retrievable properties in your discovery response. For details about state reports, see Understand State and Change Reporting.

StateReport response example

Copied to clipboard.

{
  "event": {
    "header": {
      "namespace": "Alexa",
      "name": "StateReport",
      "messageId": "Unique identifier, preferably a version 4 UUID",
      "correlationToken": "Opaque correlation token that matches the request",
      "payloadVersion": "3"
    },
    "endpoint": {
      "scope": {
        "type": "BearerToken",
        "token": "OAuth2.0 bearer token"
      },
      "endpointId": "Endpoint ID"
    },
    "payload": {}
  },
  "context": {
    "properties": [
      {
        "namespace": "Alexa.ContactSensor",
        "name": "detectionState",
        "value": "NOT_DETECTED",
        "timeOfSample": "2017-02-03T16:20:50.52Z",
        "uncertaintyInMilliseconds": 0
      },
      {
        "namespace": "Alexa.EndpointHealth",
        "name": "connectivity",
        "value": {
          "value": "OK"
        },
        "timeOfSample": "2017-02-03T16:08:15.02Z",
        "uncertaintyInMilliseconds": 0
      }
    ]
  }
}

Change reporting

You send a ChangeReport event to report changes proactively in the state of an endpoint. You identify the properties that you proactively report in your discovery response. For details about change reports, see Understand State and Change Reporting.

ChangeReport event example

Copied to clipboard.

{  
  "event": {
    "header": {
      "namespace": "Alexa",
      "name": "ChangeReport",
      "messageId": "Unique identifier, preferably a version 4 UUID",
      "payloadVersion": "3"
    },
    "endpoint": {
      "scope": {
        "type": "BearerToken",
        "token": "OAuth2.0 bearer token"
      },
      "endpointId": "Endpoint ID"
    },
    "payload": {
      "change": {
        "cause": {
          "type": "PHYSICAL_INTERACTION"
        },
        "properties": [
          {
            "namespace": "Alexa.ContactSensor",
            "name": "detectionState",
            "value": "DETECTED",
            "timeOfSample": "2018-02-03T16:20:50.52Z",
            "uncertaintyInMilliseconds": 0
          }
        ]
      }
    }
  },
  "context": {
    "properties": [
      {
        "namespace": "Alexa.EndpointHealth",
        "name": "connectivity",
        "value": {
          "value": "OK"
        },
        "timeOfSample": "2017-02-03T16:08:15.02Z",
        "uncertaintyInMilliseconds": 0
      }
    ]
  }
}

Was this page helpful?

Last updated: Aug 23, 2024