# Tutorial | Using Scenes API to Determine Execution Location

**URL:** <https://community.smartthings.com/t/tutorial-using-scenes-api-to-determine-execution-location/244303>\
**Category:** Tutorials\
**Created:** [June 30, 2022, 4:10pm UTC](https://community.smartthings.com/t/tutorial-using-scenes-api-to-determine-execution-location/244303 "2022-06-30T16:10:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nett](https://avatars.discourse-cdn.com/v4/letter/n/8c91f0/32.png) [@nett](https://community.smartthings.com/u/nett)\
**Post date:** [June 30, 2022, 4:10pm UTC](https://community.smartthings.com/t/tutorial-using-scenes-api-to-determine-execution-location/244303/1 "2022-06-30T16:10:21Z")

</div>

# 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

- REST API client (such as [Postman](https://www.postman.com))
- [Personal Access Token](https://account.smartthings.com/tokens) (PAT)

## Generate a SmartThings Personal Access Token

If you don’t have an existing [PAT](https://developer.smartthings.com/docs/advanced/authorization-and-permissions) with the following authorized scopes, visit the [personal access tokens](https://account.smartthings.com/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 | Developer Documentation | SmartThings](https://developer.smartthings.com/docs/api/public/#operation/getDevices) |

| Response |
| --- |

```json
    "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 | Developer Documentation | SmartThings](https://developer.smartthings.com/docs/api/public/#operation/listScenes) |

| Response |
| --- |

```json
{
    "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"
}

```

---

<div class="post-metadata">

**Author:** ![orangebucket](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/orangebucket/32/81590_2.png) [@orangebucket](https://community.smartthings.com/u/orangebucket)\
**Post date:** [June 30, 2022, 7:50pm UTC](https://community.smartthings.com/t/tutorial-using-scenes-api-to-determine-execution-location/244303/2 "2022-06-30T19:50:12Z")

</div>

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.
