Add PIN code
Use this action to add a new PIN code to a Schlage lock, for example to give a guest or family member their own code. You can create a permanent PIN or a temporary PIN that is only active during a specific time window.
Using this action from the user interface
If you prefer building automations and scripts visually, Home Assistant walks you through this action step by step. You pick what to target, tweak a few options, and save. No YAML knowledge required.
To add a PIN code from an automation or a script:
- Go to Settings > Automations & scenes.
- Open an existing automation or script, or select Create automation > Create new automation.
- If you’re setting up a new automation, add a trigger in the When section. Scripts don’t need a trigger. They run when something else calls them.
- In the Then do section, select Add action.
- Select what you want to control. Under By target (see Targets), select the Schlage lock.
- From the actions shown for that target, under Schlage, select Add PIN code.
- Enter the PIN name and the PIN code.
- To create a temporary PIN, enter a Start time and End time. Leave both empty for a permanent PIN.
- Select Save.
Options in the UI
Whether the native Schlage notification should be sent when this PIN is used. On by default.
When this PIN becomes active. Providing a start time makes the PIN temporary; both a start and an end time are required.
Temporary vs. permanent PINs
When you add a PIN without a start or end time, it becomes a permanent PIN that works until you delete it. If you provide both a start time and an end time, the PIN becomes a temporary PIN that is only active during that window.
You must provide both times together or leave both empty. If you provide only one, you get an error: Start and end times are required together. Provide both to create a temporary PIN, or neither for a permanent one.
The start time must be before the end time. If the start time is the same as or after the end time, you get an error: Start time must be before end time.
Using this action in YAML
If you work directly in YAML, or you want to know exactly what Home Assistant does under the hood, this section has the technical reference. It lists the field names you use in YAML, their types, and which ones are required. For how an automation or a script is built in YAML, refer to Automations in YAML and Scripts.
In YAML, refer to this action as schlage.add_code. A basic example looks like this:
action: schlage.add_code
target:
entity_id: lock.front_door
data:
name: Example Person
code: "3333"
To add a temporary PIN in YAML:
action: schlage.add_code
target:
entity_id: lock.front_door
data:
name: Guest
code: "1234"
start_datetime: "2026-09-01T15:00:00"
end_datetime: "2026-09-01T16:00:00"
Options in YAML
The name of the PIN code. Must be unique to the lock, regardless of capitalization.
The PIN code to add. Must be unique to the lock and be between 4 and 8 digits long.
Whether the native Schlage notification should be sent when this PIN is used.
When this PIN becomes active. Providing a start time makes the PIN temporary; both a start and an end time are required.
Targets of the action
This action requires a target. The target is the object of the action. You can point the action at a single entityAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more], a device, an area, a floor, or a label, and Home Assistant will run the action on every matching lock entity behind that target.
-
Entity: one specific lock entity, such as
lock.living_room. - Device: every lock entity that belongs to a device.
- Area: every lock entity in a room or area.
- Floor: every lock entity on a floor.
- Label: every lock entity that shares a label.
You can also select different target types in one action. For example, you can add a specific entity and an area as targets in the same action to run the action on both of them at once.
To learn which entities Home Assistant includes for a device, area, floor, or label, and how it handles several entities, refer to Automation targets.
To leave out some of these entities, refer to Excluding targets. For example, you can leave out one lock entity in an area.
Try it yourself
Ready to test this? Open Settings > Tools > Actions, search for this action, fill in the fields, and select Perform action. You see what happens on your actual entitiesAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more] without writing a line of YAML.
Still stuck?
To test the action on its own, run it in the automation editor with Run action, and check the message that it shows. To see what the action did when the automation ran, open the trace of that run. For details, refer to Testing automations. For common problems and their solutions, refer to Troubleshooting automations.
If that doesn’t help, the Home Assistant community is quick to help: join Discord for real-time chat, post on the community forum with the action you’re calling and what you expected to happen, or share on our subreddit /r/homeassistant.
AI assistants like ChatGPT or Claude can also explain actions or suggest the right one when you describe what you want in plain language.
Related actions
Explore related actions:
-
Delete PIN code: Deletes a PIN code from a Schlage lock.
-
Get PIN codes: Returns all PIN codes stored on a Schlage lock.