So, you’ve made the switch from Keymaster to the Lock Manager integration in Home Assistant. You can now sync your various door locks and their pin codes, without all the bloat of the Keymaster integration!
The next step? You probably want to receive a notification whenever a specific person unlocks the door. For example, get a notification when your kids unlock a door, when guests arrive, when the maid service enters, or when your girlfriend comes over unannounced.
In this guide, I’ll show you exactly how to do that – in a single automation. To do this, we will be “listening” to the integration-provided event called lock_code_manager_lock_state_changed
. Whenever a code is used, it will publish the info we need in the Developer Tools, which we will then put into an automation using Trigger ID’s.
Let’s get started!
Prerequisites
The first step is to obviously pair your locks to Home Assistant. I’m using 2 Kwikset 620 locks (which are fantastic by the way).
Then, you’ll need to follow my Install Lock Manager Integration in Home Assistant guide.
Listen to Event in Developer Tools
Launch Home Assistant.
In your sidebar, click Developer Tools > Events tab.
Paste this into the “Listen To Events” field: lock_code_manager_lock_state_changed
and then click Start Listening.
Enter Pin Code at a Door
Now that Home Assistant is listening for that event, go ahead and open your door and enter in one of the PIN codes you created. You should see it populate some info like the screenshot below.
Note: I highly recommend entering 1 PIN code at EACH door, if you plan on syncing multiple doors. This will get you the entity_id
and device_id
for each door, which we’ll need to include in the automation for the next step.
Highlight everything in the green box and copy to clipboard (CTRL+C).
At this stage, you can either enter EVERY door pin code, at every door, so they all show up in Developer Tools, or, plan on updating the teal highlighted area in your automation in the next step. The only thing that changes is the code_slot
and code_slot_name
. And possibly the entity_id
and device_id
if using multiple doors.
Create Your Automation
Now that we have the info we need, it’s time to create the automation to notify your phone whenever a specific PIN code is used.
Open a SECOND tab of Home Assistant. We will need to access the Developer Tools in one tab, and Automations tab in another.
Settings > Automations & Scenes > Create Automation > Create Automation from scratch.
I’ll show you how to create it via the UI, but I’m also providing my YAML if you’d rather go that route.
Lock Manager UI Automation
- Under the When section, click Add Trigger.
- Search for “Event”.
- Choose “Manual Event”
- For event type, enter
lock_code_manager_lock_state_changed
- For the Event data section, paste the text you copied above.
- When you paste it in – it isn’t going to be formatted correctly.
- Highlight everything you pasted (CTRL+A), then press SHIFT+TAB. This will move everything a few spaces to the left.
Then, click the 3 dots in the top right of that “When” event.
- Click Edit ID.
- In the Trigger ID space, enter a name. For example, “Danny Patio Door”
Repeat the “Add Trigger” step for each PIN code, and at EACH door!
I have 3 PIN codes synced to 2 doors, so I had to do this 6 times (3×2). This means I now have 6 “trigger ID’s” I can choose between.
Your “When” section should look like this:
(I.e. – Front Door Danny, Patio Door Danny, Front Door GF, Patio Door GF, Front Door son, Patio Door Son)
Under the “Then Do” section:
- Click Add Action and search for “Choose”.
- Expand Option 1.
- Under Conditions, click add Condition “triggered by” and check the box next to whichever trigger ID you want it to notify on.
- Click Add Action, click + Add Action and Search for “notifications”, then click Notifications: Send a notification via mobile_app_XXXXXXXXX
Check the “Title” box.
- Enter the name of the person who unlocked the door
- In the Message field, add “Unlocked the Front Door” or “Unlocked Whatever Door”
Like I mentioned, I have 6 “if-then” statements. So I repeated this 6 times.
Lock Manager YAML Automation
For this, you’ll just need to update the following values:
- entity_id
- device_id
- lock_code_manager_config_entry_id
- code_slot
- code_slot_name
Here’s the full YAML if you’d rather replace the values above. Just copy and and paste this into a new automation and then replace the above values.
alias: "Door: Triggers"
description: ""
trigger:
- platform: event
event_type: lock_code_manager_lock_state_changed
event_data:
notification_source: event
entity_id: lock.front_door
device_id: 32620abba3922b3b52215f88bef24fa9
lock_code_manager_config_entry_id: c4e89703f57e4fce7cc515b6f45834eb
state: unlocked
action_text: Keypad unlock operation
code_slot: 2
code_slot_name: Ceason
from: locked
to: unlocked
id: Front Door Ceason
- platform: event
event_type: lock_code_manager_lock_state_changed
event_data:
notification_source: event
entity_id: lock.patio_door
device_id: 2352452a58a8074d53a76d14d66f84fd
lock_code_manager_config_entry_id: c4e89703f57e4fce7cc515b6f45834eb
state: unlocked
action_text: Keypad unlock operation
code_slot: 2
code_slot_name: Ceason
from: locked
to: unlocked
id: Patio Door Ceason
- platform: event
event_type: lock_code_manager_lock_state_changed
event_data:
notification_source: event
entity_id: lock.front_door
device_id: 32620abba3922b3b52215f88bef24fa9
lock_code_manager_config_entry_id: c4e89703f57e4fce7cc515b6f45834eb
state: unlocked
action_text: Keypad unlock operation
code_slot: 1
code_slot_name: Danny
from: locked
to: unlocked
id: Front Door Danny
- platform: event
event_type: lock_code_manager_lock_state_changed
event_data:
notification_source: event
entity_id: lock.patio_door
device_id: 2352452a58a8074d53a76d14d66f84fd
lock_code_manager_config_entry_id: c4e89703f57e4fce7cc515b6f45834eb
state: unlocked
action_text: Keypad unlock operation
code_slot: 1
code_slot_name: Danny
from: locked
to: unlocked
id: Patio Door Danny
- platform: event
event_type: lock_code_manager_lock_state_changed
event_data:
notification_source: event
entity_id: lock.front_door
device_id: 32620abba3922b3b52215f88bef24fa9
lock_code_manager_config_entry_id: c4e89703f57e4fce7cc515b6f45834eb
state: unlocked
action_text: Keypad unlock operation
code_slot: 3
code_slot_name: Jax
from: locked
to: unlocked
id: Front Door Jax
- platform: event
event_type: lock_code_manager_lock_state_changed
event_data:
notification_source: event
entity_id: lock.patio_door
device_id: 2352452a58a8074d53a76d14d66f84fd
lock_code_manager_config_entry_id: c4e89703f57e4fce7cc515b6f45834eb
state: unlocked
action_text: Keypad unlock operation
code_slot: 3
code_slot_name: Jax
from: locked
to: unlocked
id: Patio Door Jax
condition: []
action:
- choose:
- conditions:
- condition: trigger
id:
- Front Door Ceason
sequence:
- service: notify.mobile_app_pixel_7
metadata: {}
data:
title: Ceason
message: unlocked the Front Door.
- conditions:
- condition: trigger
id:
- Patio Door Ceason
sequence:
- service: notify.mobile_app_pixel_7
metadata: {}
data:
title: Ceason
message: unlocked the Patio Door.
- conditions:
- condition: trigger
id:
- Front Door Danny
sequence:
- service: notify.mobile_app_pixel_7
metadata: {}
data:
title: Danny
message: unlocked the Front Door.
- conditions:
- condition: trigger
id:
- Patio Door Danny
sequence:
- service: notify.mobile_app_pixel_7
metadata: {}
data:
title: Danny
message: unlocked the Patio Door.
- conditions:
- condition: trigger
id:
- Front Door Jax
sequence:
- service: notify.mobile_app_pixel_7
metadata: {}
data:
title: Jax
message: unlocked the Front Door.
- conditions:
- condition: trigger
id:
- Patio Door Jax
sequence:
- service: notify.mobile_app_pixel_7
metadata: {}
data:
title: Jax
message: unlocked the Patio Door.
mode: single
Wrapping Up
When all is said and done, you should receive notifications like this whenever a pin code is used, and at which door is was used from. This Lock Manager integration vis HACS is awesome, and is a very welcome improvement to the Keymaster ingregration.
Please comment below if this tutorial/guide/walk-through helped you out!