Tutorial | Using Scenes API to Determine Execution Location

Tutorial | Using Scenes API to Determine Execution Location

Overview

For this tutorial, we will use the Devices API and Scenes API to determine the current execution location.

NOTE: The local scene execution feature is currently in beta testing for selected customers.

Prerequisites

Generate a SmartThings Personal Access Token

If you don’t have an existing PAT with the following authorized scopes, visit the personal access tokens page to generate a new PAT. You will use your PAT as a bearer token in the Postman app.

  • Scenes
    • See all scenes (r:scenes:*)
  • Devices
    • List all devices (l:devices) or See all devices (r:devices:*)

Obtain Location ID for a Device

You can use the Postman app to get the “locationId” value for a device in a scene from the following response.

Get Devices GET https://api.smartthings.com/devices
Authorization: Bearer <PAT>
Documentation API | SmartThings Developers
Response
    "items": [
        {
            "deviceId": "<sengled device id>",
            "name": "Sengled Light",
            "label": "Sengled Light",
            "manufacturerName": "SmartThings",
            "presentationId": "SmartThings-smartthings-ZigBee_Dimmer",
            "deviceManufacturerCode": "sengled",
            "locationId": "<location id>",
            "roomId": "<room id>",
            "deviceTypeId": "52969956-9ba8-46ba-873e-1bb46cfef033",
            "deviceTypeName": "ZigBee Dimmer",
            "deviceNetworkType": "ZIGBEE",
            "components": [
                {
                    "id": "main",
                    "label": "Sengled Light",
                    "capabilities": [
                        {
                            "id": "switch",
                            "version": 1
                        },
                        {
                            "id": "configuration",
                            "version": 1
                        },
                        {
                            "id": "switchLevel",
                            "version": 1
                        },
                        {
                            "id": "refresh",
                            "version": 1
                        },
                        {
                            "id": "actuator",
                            "version": 1
                        },
                        {
                            "id": "healthCheck",
                            "version": 1
                        },
                        {
                            "id": "light",
                            "version": 1
                        }
                    ],
                    "categories": [
                        {
                            "name": "Light",
                            "categoryType": "manufacturer"
                        },
                        {
                            "name": "Light",
                            "categoryType": "manufacturer"
                        }
                    ]
                }
            ],
            "createTime": "2022-04-12T03:07:39.956Z",
            "parentDeviceId": "<hub device id>",
            "dth": {
                "completedSetup": true,
                "deviceNetworkType": "ZIGBEE",
                "deviceTypeId": "52969956-9ba8-46ba-873e-1bb46cfef033",
                "deviceTypeName": "ZigBee Dimmer",
                "executingLocally": true,
                "hubId": "<hub device id>",
                "networkSecurityLevel": "UNKNOWN"
            },
            "type": "DTH",
            "restrictionTier": 0,
            "allowed": []
        },
        {
            "deviceId": "<hub device id>",
            "name": "SmartThings v3 Hub",
            "label": "Hub",
            "manufacturerName": "SmartThings",
            "presentationId": "SmartThings-smartthings-hub",
            "locationId": "<location id>",
            "roomId": "<room id>",
            "components": [
                {
                    "id": "main",
                    "label": "main",
                    "capabilities": [
                        {
                            "id": "bridge",
                            "version": 1
                        }
                    ],
                    "categories": [
                        {
                            "name": "Hub",
                            "categoryType": "manufacturer"
                        }
                    ]
                }
            ],
            "createTime": "2021-12-29T01:06:39.366Z",
            "childDevices": [
                {
                    "deviceId": "<sengled device id>",
                    "profile": {},
                    "allowed": []
                }
            ],
            "profile": {
                "id": "<profile id>"
            },
            "type": "HUB",
            "restrictionTier": 0,
            "allowed": []
        }
    ],
    "_links": {}
}

Get Scene Execution Location

Use the Postman app to get the following response. The scene execution location in the “executionLocation" element can be “Cloud” or “Local”.

List Scenes GET https://api.smartthings.com/scenes/?locationId=<location id>
Authorization: Bearer <PAT>
Accept: application/vnd.smartthings+json;v=20200501
Documentation API | SmartThings Developers
Response
{
    "name": "Scene Lights On",
    "actions": [
        {
            "command": {
                "devices": [
                    "<device id>"
                ],
                "commands": [
                    {
                        "component": "main",
                        "capability": "switch",
                        "command": "on"
                    }
                ]
            },
            "type": "command"
        }
    ],
    "sequence": {
        "actions": "Parallel"
    },
    "meta": {
        "locationId": "<location id>",
        "userUuid": "<user id>",
        "dateCreated": "2022-03-23T17:30:28Z",
        "dateUpdated": "2022-03-23T17:30:28Z",
        "dateExecuted": "2022-03-23T17:30:29Z",
        "editable": true,
        "apiVersion": "20200501",
        "executingLocally": false
    },
    "id": "<scene id>",
    "executionLocation": "Local",
    "ownerType": "Location",
    "ownerId": "<location id>",
    "creator": "SMARTTHINGS",
    "dateCreated": "2022-03-23T17:30:28Z",
    "dateUpdated": "2022-03-23T17:30:28Z"
}
2 Likes

That version of the scenes endpoint looks like it might have more potential than the current offering. I hope so. Currently Scenes are just toys like Routines. A developer grade version similar to Rules is desperately needed, though I guess if there was an action to execute a rule that would suffice. Scenes have their feet in two camps at the moment.