感谢您的访问。此页面目前仅提供英语版本。我们正在开发中文版本。谢谢您的理解。

Alexa.PowerLevelController Interface

The Alexa.PowerLevelController interface describes the messages used to control the power level of a device. Use this interface for devices that support power-level control, such as a dimmer switch. For more general properties that can be expressed as a percentage, implement the [Alexa.PercentageController][alexa-percentagecontroller] interface instead.

For the list of locales that are supported for the PowerLevelController interface, see List of Capability Interfaces and Supported Locales.

Utterances

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

Alexa, set the power to 40 percent on the fan.
Alexa, increase the power level by 12 on the light switch.

After the customer says an utterance, Alexa sends a corresponding directive to your skill.

Properties

The powerLevel property

The Alexa.PowerLevelController interface uses the powerLevel property as the primary property. The property represents the power level of a device expressed as an integer percentage between 0 and 100 inclusive. If the powerLevel property is used to represent a change, then valid values are from -100 to 100 inclusive.

Discovery

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

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

For the full list of display categories, see display categories.

Discover response example

The following example shows a Discover.Response message for an endpoint that supports the Alexa.PowerLevelController and Alexa.ColorController interfaces.

{
  "event": {
    "header": {
      "namespace": "Alexa.Discovery",
      "name": "Discover.Response",
      "payloadVersion": "3",
      "messageId": "<message id>"
    },
    "payload": {
      "endpoints":[
        {
          "endpointId": "<unique ID of the endpoint>",
          "manufacturerName": "<the manufacturer name of the endpoint>",
          "modelName": "<the model name of the endpoint>",
          "description": "<a description that is shown in the Alexa app>",
          "friendlyName": "<device name, displayed in the Alexa app>",
          "displayCategories": ["LIGHT"],
          "cookie": {},
          "capabilities": [
            {
              "type": "AlexaInterface",
              "interface": "Alexa.PowerLevelController",
              "version": "3",
              "properties": {
                "supported": [
                  {
                    "name": "powerLevel"
                  }
                ],
                "proactivelyReported": true,
                "retrievable": true
              }
            },
            {
              "type": "AlexaInterface",
              "interface": "Alexa.ColorController",
              "version": "3",
              "properties": {
                "supported": [
                  {
                    "name": "color"
                  }
                ],
                "proactivelyReported": true,
                "retrievable": true
              }
            }
          ]
        }
      ]
    }
  }
}

Directives

SetPowerLevel directive

Support the SetPowerLevel directive so that customers can set the power level on devices.

The following example shows a customer utterance:

Alexa, set the power to 40 percent on the fan.

SetPowerLevel directive payload details

Field Description Type
powerLevel The power level to set the device to. Integer

SetPowerLevel directive example

{
  "directive": {
    "header": {
      "namespace": "Alexa.PowerLevelController",
      "name": "SetPowerLevel",
      "messageId": "<message id>",
      "correlationToken": "<an opaque correlation token>",
      "payloadVersion": "3"
    },
    "endpoint": {
      "scope": {
        "type": "BearerToken",
        "token": "<an OAuth2 bearer token>"
      },
      "endpointId": "<endpoint id>",
      "cookie": {}
    },
    "payload": {
      "powerLevel": 40
    }
  }
}

SetPowerLevel response event

If you handle a SetPowerLevel directive successfully, respond with an Alexa.Response event. In the context object, include the values of all properties that changed. You can respond synchronously or asynchronously. If you respond asynchronously, include a correlation token and a scope with an authorization token.

SetPowerLevel response event example

{
  "event": {
    "header": {
      "namespace": "Alexa",
      "name": "Response",
      "messageId": "<message id>",
      "correlationToken": "<an opaque correlation token>",
      "payloadVersion": "3"
    },
    "endpoint": {
      "scope": {
        "type": "BearerToken",
        "token": "<an OAuth2 bearer token>"
      },
      "endpointId": "<endpoint id>"
    },
    "payload": {}
  },
  "context": {
    "properties": [
      {
        "namespace": "Alexa.PowerLevelController",
        "name": "powerLevel",
        "value": 40,
        "timeOfSample": "2017-02-03T16:20:50.52Z",
        "uncertaintyInMilliseconds": 500
      }
    ]
  }
}

SetPowerLevel directive error handling

If you can't handle a SetPowerLevel directive successfully, respond with an Alexa.ErrorResponse event.

AdjustPowerLevel directive

Support the AdjustPowerLevel directive so that customers can adjust the power level on devices.

The following example shows a customer utterance:

Alexa, increase the power level by 12 on the light switch.

AdjustPowerLevel directive payload details

Field Description Type
powerLevelDelta The amount by which to change the power level. Integer

AdjustPowerLevel directive example

{
  "directive": {
    "header": {
      "namespace": "Alexa.PowerLevelController",
      "name": "AdjustPowerLevel",
      "messageId": "<message id>",
      "correlationToken": "<an opaque correlation token>",
      "payloadVersion": "3"
    },
    "endpoint": {
      "scope": {
        "type": "BearerToken",
        "token": "<an OAuth2 bearer token>"
      },
      "endpointId": "<endpoint id>",
      "cookie": {}
    },
    "payload": {
      "powerLevelDelta": 12
    }
  }
}

AdjustPowerLevel response event

If you handle an AdjustPowerLevel directive successfully, respond with an Alexa.Response event. In the context object, include the values of all properties that changed. You can respond synchronously or asynchronously. If you respond asynchronously, include a correlation token and a scope with an authorization token.

AdjustPowerLevel response event example

{
  "event": {
    "header": {
      "namespace": "Alexa",
      "name": "Response",
      "messageId": "<message id>",
      "correlationToken": "<an opaque correlation token>",
      "payloadVersion": "3"
    },
    "endpoint": {
      "scope": {
        "type": "BearerToken",
        "token": "<an OAuth2 bearer token>"
      },
      "endpointId": "<endpoint id>"
    },
    "payload": {}
  },
  "context": {
    "properties": [
      {
        "namespace": "Alexa.PowerLevelController",
        "name": "powerLevel",
        "value": 52,
        "timeOfSample": "2017-02-03T16:20:50.52Z",
        "uncertaintyInMilliseconds": 500
      }
    ]
  }
}

AdjustPowerLevel directive error handling

If you can't handle an AdjustPowerLevel directive successfully, respond with an Alexa.ErrorResponse event.

State reporting

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 of the retrievable properties in the context object. You identify your retrievable properties in your discovery response. For more information about state reports, see Understand State Reporting.

StateReport response event example

{
  "event": {
    "header": {
      "namespace": "Alexa",
      "name": "StateReport",
      "messageId": "<message id>",
      "correlationToken": "<an opaque correlation token>",
      "payloadVersion": "3"
    },
    "endpoint": {
      "scope": {
        "type": "BearerToken",
        "token": "<an OAuth2 bearer token>"
      },
      "endpointId": "<endpoint id>"
    },
    "payload": {}
  },
  "context": {
    "properties": [
      {
        "namespace": "Alexa.PowerLevelController",
        "name": "powerLevel",
        "value": 52,
        "timeOfSample": "2017-02-03T16:20:50.52Z",
        "uncertaintyInMilliseconds": 0
      }
    ]
  }
}

Change reporting

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

ChangeReport event example

{  
  "event": {
    "header": {
      "namespace": "Alexa",
      "name": "ChangeReport",
      "messageId": "<message id>",
      "payloadVersion": "3"
    },
    "endpoint": {
      "scope": {
        "type": "BearerToken",
        "token": "<an OAuth2 bearer token>"
      },
      "endpointId": "<endpoint id>"
    },
    "payload": {
      "change": {
        "cause": {
          "type": "PHYSICAL_INTERACTION"
        },
        "properties": [
          {
            "namespace": "Alexa.PowerLevelController",
            "name": "powerLevel",
            "value": 75,
            "timeOfSample": "2017-02-03T16:20:50.52Z",
            "uncertaintyInMilliseconds": 0
          }
        ]
      }
    }
  },
  "context": {}
}