Get started with SmartThings Hubs + Smart Locks

SmartThings Hub + Smart Lock

SmartThings Hub is connected to your local network using either Wifi or ethernet. The Smart Lock is paired to SmartThings via Zigbee or Z-Wave. These locks can then be remotely locked, unlocked, and have access codes programmed to allow keyless entry.

Overview

To pair a SmartThings Hub and smart lock with our API, we'll need to sign into a SmartThings account. We can do this by creating a Seam Webview.

Make sure to install the relevant Seam package for your language...

from seamapi import Seam

seam = Seam()

webview = seam.connect_webviews.create(accepted_providers=["smartthings"])

assert webview.login_successful is False

# Send the webview URL to your user
print(webview.url)

We should now send the Connect Webview URL to the user, when the user signs in, we'll see a "completed" status on the webview or login_successful set to true.

updated_webview = seam.connect_webviews.get(webview.connect_webview_id)

assert updated_webview.login_successful

We can now find all the devices that are associated with the connected account that was signed into. From the returned payload, see whether the door lock is locked or unlocked.

from pprint import pprint

all_devices = seam.devices.list()

some_device = all_devices[0]

assert device.properties["online"] is True
assert device.properties["locked"] is True

pprint(device)
# Device(device_id='a8669e4c-76e3-4db6-a827-11a65eb360ba',
#       device_type='smartthings_lock',
#       location=None,
#       properties={'smartthings_metadata': {...}},
#                   'locked': True,
#                   'online': True})

Locking a Door

Lock a door

POST https://connect.getseam.com/locks/lock_door

Headers

Name
Type
Description

Authorization*

String

Bearer <API_KEY>

Request Body

Name
Type
Description

device_id*

String

ID of the Device to be locked

{
    "action_attempt": {
        "action_attempt_id": "8f17e75c-dd1f-42c6-8c5c-35fbfa3e6809",
        "status": "pending",
        "action_type": "LOCK_DOOR"
    },
    "ok": true
}
seam.locks.lock_door(some_device)

updated_device = seam.devices.get(some_device.device_id)

assert updated_device.properties["locked"] is True

Unlocking a Door

Unlock a door

POST https://connect.getseam.com/locks/unlock_door

Headers

Name
Type
Description

Authorization*

String

Bearer <API_KEY>

Request Body

Name
Type
Description

device_id*

String

ID of the Device to be unlocked

{
    "action_attempt": {
        "action_attempt_id": "8f17e75c-dd1f-42c6-8c5c-35fbfa3e6809",
        "status": "pending",
        "action_type": "UNLOCK_DOOR"
    },
    "ok": true
}
seam.locks.unlock_door(some_device)

updated_device = seam.devices.get(some_device.device_id)

assert updated_device.properties["locked"] is False

Create an Access Code

Create an Access Code

POST https://connect.getseam.com/access_codes/create

Headers

Name
Type
Description

Authorization*

String

Bearer <API_KEY>

Request Body

Name
Type
Description

device_id*

String

ID of the Device to be programmed

code

String

digits to set on the device

starts_at

String

iso8601 timestamp for desired start time of code. null implies that the code will be immediately active.

ends_at

String

iso8601 timestamp for desired end time of code. null implies that the code will be permanent.

name*

String

Name of Access Code

{
    "action_attempt": {
         "action_attempt_id": "123e4567-e89b-12d3-a456-426614174000",
         "action_type": "CREATE_ACCESS_CODE",
         "status": "pending",
         "result": {}
    },
    "ok": true
}

For Scheduled Access Codes, both starts_at and ends_at are required. For Ongoing Access Codes, don't set starts_at or ends_at.

access_code = seam.access_codes.create(
    device=some_device,
    name="new code",
    code="876543",
    starts_at="2022-01-13T21:17:56.138Z",
    ends_at="2022-01-13T21:17:58.138Z"
)

pprint(access_code)
# AccessCode(
#       access_code_id='a8669e4c-76e3-4db6-a827-11a65eb360ba',
#       type='ongoing',
#       name='new code',
#       code='876543',
#       starts_at='2022-01-13T21:17:56.138Z'
#       ends_at='2022-01-13T21:17:58.138Z',
#       location=None,
# )

Delete an Access Code

Remove an Access Code

DELETE https://connect.getseam.com/access_codes/remove

Headers

Name
Type
Description

Authorizaion*

String

Bearer <API_KEY>

Request Body

Name
Type
Description

access_code_id*

String

{
    "action_attempt": {
         "action_attempt_id": "123e4567-e89b-12d3-a456-426614174000",
         "action_type": "DELETE_ACCESS_CODE",
         "status": "pending",
         "result": {}
    },
    "ok": true
}
attempt = seam.access_codes.delete(access_code=access_code)

pprint(attempt)
# ActionAttempt(
#   action_attempt_id='af0155aa-51fe-4e63-9acb-2fbd33675cac',
#   action_type='DELETE_ACCESS_CODE',
#   status='success',
#   result={},
#   error=None
# )

List Access Codes

List Access Codes

GET https://connect.getseam.com/access_codes

Query Parameters

Name
Type
Description

device

String

Filter by Device

device_id

String

Filter by Device

Headers

Name
Type
Description

Authorizaion*

String

Bearer <API_KEY>

{
    "access_codes": [
        {
            "access_code_id": "123e4567-e89b-12d3-a456-426614174000",
            "code": "876543",
            "name": "ongoing code",
            "type": "ongoing",
            "status": "setting",
            "created_at": "2022-02-11T22:53:40.988Z"
        },
        {
	    "access_code_id": "123e4568-e89b-12d3-a456-426614174000",
	    "code": "141498",
	    "name": "scheduled code",
	    "type": "time_bound",
	    "status": "set",
	    "ends_at": "2022-02-11T22:55:00.000Z",
	    "starts_at": "2022-02-11T22:54:00.000Z",
            "created_at": "2022-02-11T22:53:40.988Z"
	}
    ]
}
# you can use a device or a device_id as the "device" parameter
seam.access_codes.list(device=some_device)
# [
#   AccessCode(
#     access_code_id='af5272b1-2a49-4eb5-9388-2447fc7b5bd1',
#     type='ongoing',
#     code='123459',
#     starts_at=None,
#     ends_at=None,
#     name='ongoing 1'
#   ),
#   AccessCode(
#     access_code_id='57f8216a-ebc4-46e7-8f89-9c9448f70733',
#     type='ongoing',
#     code='189644',
#     starts_at=None,
#     ends_at=None,
#     name='ongoing 2'
#   )
# ]

Last updated

Was this helpful?