Locking and Unlocking

Learn how to lock and unlock a smart lock, and confirm the action's success.

Overview

Seam enables you to lock or unlock your door lock remotely. This guide walks you through how to perform these actions using the Seam API.

When you send a command to a smart lock, it might take a while for Seam to confirm the action's success. To handle this, Seam provides an "action attempt" object, which indicates whether the action was successful.

To ensure that the action has been successfully executed, we advise checking the status of the action attempt object by polling the "Get Action Attempt" request. Once Seam has successfully confirmed the action, the action attempt's status will indicate success.

For those who prefer using webhooks to verify the success of an action, we'll soon introduce events that confirm an action's success.


Before You Begin

Be sure to confirm that your device has the capability to lock and unlock. You can inspect this by checking the device's capabilities by looking for lock in the capabilities_supported list in Get Device or List Devices (or Get Lock or List Locks).

Request:

pprint(seam.locks.get(device="6aae9d08-fed6-4ca5-8328-e36849ab48fe"))

Response:

Device(device_id='6aae9d08-fed6-4ca5-8328-e36849ab48fe',
       .
       .
       .
       capabilities_supported=[
              'lock', // Device supports lock and unlock actions.
              .
              .
              .
              ],
       .
       .
       .
       )

Locking a Door

You can lock a door using the Lock endpoint. To confirm the success of the action, see Verifying the success of a lock or unlock action.

Request:

pprint(seam.locks.lock_door(device="6aae9d08-fed6-4ca5-8328-e36849ab48fe"))

Response:

ActionAttempt(action_attempt_id='47f2ba20-a2e5-4f3d-9add-e5ac33a415a3',
              action_type='LOCK_DOOR',
              status='success',
              result={},
              error=None)

Unlocking a Door

You can lock a door using the Unlock endpoint. To confirm the success of the action, see Verifying the success of a lock or unlock action.

Request:

pprint(seam.locks.unlock_door(device="6aae9d08-fed6-4ca5-8328-e36849ab48fe"))

Response:

ActionAttempt(action_attempt_id='a34cf3e7-42ad-481a-9edf-80be46c5b9d4',
              action_type='UNLOCK_DOOR',
              status='success',
              result={},
              error=None)

Verifying the Success of a Lock or Unlock Action

1. Execute a Lock request (or other action)

When initiating a lock or unlock action, the Seam API returns an action attempt, which monitors the success or failure of the action.

Request:

pprint(seam.locks.lock_door(device="6aae9d08-fed6-4ca5-8328-e36849ab48fe"))

Response:

ActionAttempt(action_attempt_id='47f2ba20-a2e5-4f3d-9add-e5ac33a415a3',
              action_type='LOCK_DOOR',
              status='success',
              result={},
              error=None)

2. Poll the Action Attempt to Verify the Success of the Action

Use the action_attempt_id from the prior response to make a Get Action Attempt request. When the action attempt's status changes to success, it indicates the action has been successful.

Request:

pprint(seam.action_attempts.get(action_attempt="47f2ba20-a2e5-4f3d-9add-e5ac33a415a3"))

Response:

ActionAttempt(action_attempt_id='47f2ba20-a2e5-4f3d-9add-e5ac33a415a3',
              action_type='LOCK_DOOR',
              status='success',
              result={},
              error=None)

Checking the Locked Status of a Lock

To retrieve the locked status of a specific door lock, use the "Get Lock" endpoint (or "Get Device" endpoint for C#) by providing the device_id of the lock in question. This will return detailed information, including the current locked status.

Request:

pprint(seam.locks.get(device="6aae9d08-fed6-4ca5-8328-e36849ab48fe"))

Response:

Device(device_id='6aae9d08-fed6-4ca5-8328-e36849ab48fe',
       device_type='august_lock',
       location={'location_name': 'My House',
                 'timezone': 'America/Los_Angeles'},
       properties={
                   .
                   .
                   .
                   'locked': True,
                   .
                   .
                   .
                   },
       .
       .
       .
       )

Lock and Unlock Events

Whenever a lock is locked or unlocked, Seam emits a lock.locked or lock.unlocked event. You can see these events by making a List Events request or by setting up a webhook. For more information on how to set up webhooks, see the Webhooks guide.

A lock or unlock event looks like the following:

{
  "event": {
    "event_id": "fb81969c-cf9f-4566-918d-94f1563af2b7",
    "device_id": "6aae9d08-fed6-4ca5-8328-e36849ab48fe",
    "event_type": "lock.locked",
    "workspace_id": "398d80b7-3f96-47c2-b85a-6f8ba21d07be",
    "created_at": "2023-10-13T15:10:18.443Z",
    "occurred_at": "2023-10-13T15:09:08.531Z",
    "method": "unknown",
    "connected_account_id": "f4140589-ef32-4086-a4c8-256b7b535d5a"
  },
  "ok": true
}

For more information about the lock.locked and lock.unlocked attributes, please refer to the Events guide.

Last updated

Logo

© Seam Labs, Inc. All rights reserved.