Skip to main content

Lock entity

A lock entity is able to be locked and unlocked. Locking and unlocking can optionally be secured with a user code. Some locks also allow for opening of latches, this may also be secured with a user code. Derive a platform entity from homeassistant.components.lock.LockEntity.

Properties

tip

Properties should always only return information from memory and not do I/O (like network requests). Implement update() or async_update() to fetch data.

NameTypeDefaultDescription
changed_bystringNoneDescribes what the last change was triggered by.
code_formatstringNoneRegex used to validate the code supplied to the lock, unlock, and open actions, or None if no code is required.
is_lockedboolNoneWhether the lock is locked. Used to determine state.
is_lockingboolNoneWhether the lock is in the process of being locked. Used to determine state.
is_unlockingboolNoneWhether the lock is in the process of being unlocked. Used to determine state.
is_openboolNoneWhether the lock is unlocked and has released its latch. Only relevant for locks that support LockEntityFeature.OPEN. Used to determine state.
is_openingboolNoneWhether the lock is in the process of releasing its latch. Used to determine state.
is_jammedboolNoneWhether the lock tried to move but got stuck before it finished. Used to determine state.

States

The state is derived from the properties above and is one of the following LockState enum members:

ValueDescription
LOCKEDThe lock is locked.
LOCKINGThe lock is in the process of being locked.
UNLOCKEDThe lock is not locked.
UNLOCKINGThe lock is in the process of being unlocked.
OPENThe lock is not secured and has released its latch.
OPENINGThe lock is in the process of releasing its latch.
JAMMEDThe lock tried to move but got stuck before it finished.
note

The OPEN state and the is_open property require the lock to be not secured and have its latch released. A released latch while the lock is still secured is not the open state.

When more than one of the state properties is set, they are evaluated in a fixed priority order and the first match determines the state:

  1. is_jammedJAMMED
  2. is_openingOPENING
  3. is_lockingLOCKING
  4. is_openOPEN
  5. is_unlockingUNLOCKING
  6. is_lockedLOCKED when True, UNLOCKED when False

If is_locked is None and none of the other state properties evaluate truthy, the state is unknown.

Supported features

Supported features are defined by using values in the LockEntityFeature enum and are combined using the bitwise or (|) operator.

ValueDescription
OPENThis lock supports opening the door latch.

Methods

Lock

class MyLock(LockEntity):

def lock(self, **kwargs: Any) -> None:
"""Lock all or specified locks. A code to lock the lock with may optionally be specified."""

async def async_lock(self, **kwargs: Any) -> None:
"""Lock all or specified locks. A code to lock the lock with may optionally be specified."""

Unlock

class MyLock(LockEntity):

def unlock(self, **kwargs: Any) -> None:
"""Unlock all or specified locks. A code to unlock the lock with may optionally be specified."""

async def async_unlock(self, **kwargs: Any) -> None:
"""Unlock all or specified locks. A code to unlock the lock with may optionally be specified."""

Open

Only implement this method if the flag LockEntityFeature.OPEN is set.

class MyLock(LockEntity):

def open(self, **kwargs: Any) -> None:
"""Open (unlatch) all or specified locks. A code to open the lock with may optionally be specified."""

async def async_open(self, **kwargs: Any) -> None:
"""Open (unlatch) all or specified locks. A code to open the lock with may optionally be specified."""