This is awesome! I see now how you extracted the event data. It’s implemented and doing everything I’m looking for it to do thanks to you and @pnbruckner!
Here’s another automation you might find useful for your lock. It changes the lock’s internal alarm mode with the house alarm mode.
Disarmed -> No chips (no alarm)
Armed Home -> Chirps when door opened
Armed Night/Away - Changes to forced entry mode.
Lock Alarm Mode Automation
- id: lock_side_door_alarm_mode
alias: "[Lock] Side Door Alarm Mode"
description: Set side door lock alarm mode.
initial_state: true
mode: queued
trigger:
- platform: state
entity_id: alarm_control_panel.alarmo
to:
- armed_home
- armed_night
- armed_away
- disarmed
condition:
- condition: or
alias: Make sure door lock entity is connected (zwave).
conditions:
- condition: state
entity_id: lock.side_door_lock
state: locked
- condition: state
entity_id: lock.side_door_lock
state: unlocked
action:
- choose:
- conditions:
- condition: state
entity_id: alarm_control_panel.alarmo
state: disarmed
sequence:
- service: zwave_js.set_config_parameter
data:
parameter: Alarm Mode
value: Alarm Off
target:
entity_id: lock.side_door_lock
- conditions:
- condition: state
entity_id: alarm_control_panel.alarmo
state: armed_home
sequence:
- service: zwave_js.set_config_parameter
data:
parameter: Alarm Mode
value: Alert
target:
entity_id: lock.side_door_lock
- conditions:
- condition: or
conditions:
- condition: state
entity_id: alarm_control_panel.alarmo
state: armed_night
- condition: state
entity_id: alarm_control_panel.alarmo
state: armed_away
sequence:
- service: zwave_js.set_config_parameter
data:
parameter: Alarm Mode
value: Forced Entry
target:
entity_id: lock.side_door_lock
I made one correction as it looks like a small typo in the even data for the “Locked (Manual)” The event data was duplicated from the “Unlocked (Manual)” Changed ‘unlock’ to ‘lock’
action:
- service: input_text.set_value
data:
entity_id: input_text.side_door_lock_status
value: >
{% set users = ['Jason','Sheri','Dawn'] %}
{% set userID = trigger.event.data.parameters['userId'] %}
{% set user = 'Keypad' if userID == null else users[userID|int -1] %}
{% if trigger.event.data.label == 'Manual unlock operation' %} Unlocked (Manual)
{% elif trigger.event.data.label == 'Manual lock operation' %} Locked (Manual)
{% elif trigger.event.data.label == 'RF unlock operation' %} Unlocked (Hassio)
{% elif trigger.event.data.label == 'RF lock operation' %} Locked (Hassio)
{% elif trigger.event.data.label == 'Keypad unlock operation' %} Unlocked ({{ user }})
{% elif trigger.event.data.label == 'Keypad lock operation' %} Locked ({{ user }})
{% else %} Unknown
{% endif %}
You are absolutely correct, I had to make the same correction in my config and forgot to make the change here. I’ve updated it now. Good catch!
I found this automation useful, it also works for a Kwikset 888 and it may work for a 910 too (need to test this). I wanted to share some updates here for others, on the latest HA update two things changed, the event_type and event_label. I also changed the “else” line to be a catch all.
- alias: Alarm - Front Door Lock Sensor Updater
id: 'alarm_-_front_door_lock_sensor_updater'
initial_state: true
trigger:
- platform: event
event_type: zwave_js_notification
condition:
- condition: template
value_template: '{{ trigger.event.data.node_id == 66 and trigger.event.data.command_class_name == ''Notification'' }}'
action:
- service: input_text.set_value
data:
entity_id: input_text.front_door_lock_status
value: >
{% set users = ['Chris','Violet','Pat or Bob','Melanie','Amelia'] %}
{% set userID = trigger.event.data.parameters['userId'] %}
{% set user = 'Keypad' if userID == null else users[userID|int -1] %}
{% if trigger.event.data.event_label == 'Manual unlock operation' %} Manual Unlock
{% elif trigger.event.data.event_label == 'Manual lock operation' %} Manual Lock
{% elif trigger.event.data.event_label == 'RF unlock operation' %} RF Unlock
{% elif trigger.event.data.event_label == 'RF lock operation' %} RF Lock
{% elif trigger.event.data.event_label == 'Keypad unlock operation' %} Keypad Unlock ({{ user }})
{% elif trigger.event.data.event_label == 'Keypad lock operation' %} Keypad Lock ({{ user }})
{% else %} {{trigger.event.data.event_label}}
{% endif %}
Thank you! I meant to post an update last week when I saw these changes with the core update. You caught them all.
To summarize for those just catching up, because of the “Breaking ZwaveJS changes” on core-2021.04.00, Zwave_JS_event changed to Zwave_JS_notification and the “label” tag changed to “event_label”
Cheers!
For some reason when I lock/unlock through Home Assistant, there is no event created. Events are only generated when I manually interact with the lock. Is this expected? If not, does anyone know why that would be? I basically never see the “RF (un)lock operation” event_label. I was able to see that with the sensor before moving to zwavejs2mqtt.
What event topic are you listening to?
I subscribed to zwave_js_notification and when I manually lock the door I see an event with event_label ‘Manual lock operation’. But, if I unlock or lock in Home Assistant, no zwave_js_notification event is fired at all.
Interesting. On my end, I see “RF lock operation” or “RF unlock operation” under event_label like you stated. Are you viewing the event data from the Developer Tools ->Events tab when you subscribe to zwave_js_notification?
What events are fired if you lock/unlock via the keypad?
Also, when you moved to zwaveJS2mqtt, did you update the ZwaveJS integration with the proper server address? It should look something like this when you go to Integrations->ZwaveJS->configure.
Yep, I am subscribing to the events from Developer Tools > Events. The ZwaveJS integration is showing connected and I can lock and unlock without issue.
When I use the keypad, I see the correct event showing: “event_label”: “Keypad lock operation”. For whatever reason, only remote commands do not trigger any events even though the lock locks/unlocks as expected.
What about the server address in the ZwaveJS integration? Look at the second part of my previous reply for details. This has caused strange integration issues for me in the past when setup wrong. Especially since you mentioned a recent switch to ZwaveJS2mqtt, a confirmation that this is setup correctly would eliminate a multitude of t/s-ing steps.
Also, what lockset are you using?
I’m using BE469. The ZwaveJS configuration looks good to me.
Are you running a supervised add-on version of ZwaveJSmqtt?
No, I am running Home Assistant core and the zwavejs2mqtt dockers on Unraid.
hi Chris, I’m new to HA - I copied the code snippet and put it in automations.yaml, created the input_text variable and just changed out the node_id to one of my lock nodes. for some reason, when I do a ‘run actions’ on the automations page, I get ‘Error: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘event’’
Am I not supposed to try to test it from there?
alias: Alarm - Front Door Lock Sensor Updater
initial_state: true
trigger:
- platform: event
event_type: zwave_js_notification
condition:
- condition: template
value_template: >-
{{ trigger.event.data.node_id == 22 and
trigger.event.data.command_class_name == 'Notification' }}
action:
- service: input_text.set_value
data:
entity_id: input_text.front_door_lock_status
value: >
{% set users = ['Chris','Violet','Pat or Bob','Melanie','Amelia'] %} {%
set userID = trigger.event.data.parameters['userId'] %} {% set user =
'Keypad' if userID == null else users[userID|int -1] %} {% if
trigger.event.data.event_label == 'Manual unlock operation' %} Manual
Unlock {% elif trigger.event.data.event_label == 'Manual lock operation'
%} Manual Lock {% elif trigger.event.data.event_label == 'RF unlock
operation' %} RF Unlock {% elif trigger.event.data.event_label == 'RF
lock operation' %} RF Lock {% elif trigger.event.data.event_label ==
'Keypad unlock operation' %} Keypad Unlock ({{ user }}) {% elif
trigger.event.data.event_label == 'Keypad lock operation' %} Keypad Lock
({{ user }}) {% else %} {{trigger.event.data.event_label}} {% endif %}
mode: single
thanks,
Is/was there ever a plan by the developers to actually extract this information and make it an attribute or entity? I just switched over to zwave js and for me it luckily only broke just one automation, but I was planning on eventually making a number of automations based on the user codes. It looks like a pain to get that information in a usable form now.
Thanks for this! Got it up and running. I’d like to pass a notification when a user unlocks the door via code how would I accomplish this?
Hi All,
I’m looking to accomplish the same - reading in unlock / user pin data from a Schlage lock.
Basically following everything in this tutorial - Z-Wave JS Locks in Home Assistant - Now See Who Opened The Door - YouTube
I’m running a raspberry pi externally to Home Assistant, running Zwave JS (latest) and websockets to a Home Assistant VM I have on my virtual infrastructure.
I can’t seem to view any zwave_js_notification event data.
I have not configured MQTT or Gateway on the Zwave JS on the rpi, is that something I need to do?
If so could you provide an exmaple of the configs?
I’ve been googling for hours!
Much Appreciated!
Write-Up: How to Capture Lock Events and Associate Them with User IDs in Home Assistant
If you’re looking to track lock events from a Z-Wave lock and want to know which user unlocked or locked the door, this guide will walk you through setting up an automation in Home Assistant that captures this information and displays it in a text entity. This is particularly useful for getting insights into who is operating the lock, especially when multiple users have their own unique codes.
Step 1: Set Up Input Text Entities
First, you’ll need to create an input text entity in Home Assistant to store the lock status updates. You can do this through the Home Assistant UI by navigating to Configuration > Helpers > + Add Helper > Text.
- Name:
Front Door Lock Status
(or any name you prefer) - Entity ID:
input_text.front_door_lock_status
Step 2: Create the Automation
Add the following automation to your automations.yaml
file. This code listens for Z-Wave lock events and updates the input_text.front_door_lock_status
entity with the operation type and the associated user (if applicable).
- alias: Front Door Lock Status Updater
id: 'front_door_lock_status_updater'
initial_state: true
trigger:
- platform: event
event_type: zwave_js_notification
condition:
- condition: template
# Replace 'your_node_id' with the actual node_id of your lock
value_template: '{{ trigger.event.data.node_id == your_node_id and trigger.event.data.command_class_name == "Notification" }}'
action:
- service: input_text.set_value
data:
# Replace 'input_text.front_door_lock_status' with the actual input_text entity ID you created
entity_id: input_text.front_door_lock_status
value: >
{% set users = ['User 1', 'User 2', 'User 3', 'User 4', 'User 5', 'User 6', 'User 7', 'User 8', 'User 9'] %}
{% set userID = trigger.event.data.parameters['userId'] %}
{% set user = 'Keypad' if userID == null else users[userID|int - 1] %}
{% if trigger.event.data.event_label == 'Manual unlock operation' %} Manual Unlock
{% elif trigger.event.data.event_label == 'Manual lock operation' %} Manual Lock
{% elif trigger.event.data.event_label == 'RF unlock operation' %} RF Unlock
{% elif trigger.event.data.event_label == 'RF lock operation' %} RF Lock
{% elif trigger.event.data.event_label == 'Keypad unlock operation' %} Keypad Unlock ({{ user }})
{% elif trigger.event.data.event_label == 'Keypad lock operation' %} Keypad Lock ({{ user }})
{% else %} {{ trigger.event.data.event_label }}
{% endif %}
Code Breakdown:
- Alias: A descriptive name for the automation.
- ID: A unique identifier for this automation.
- Trigger: The automation listens for
zwave_js_notification
events from your lock. - Condition: Ensures the event is a notification from the specific lock. Replace
'your_node_id'
with the actualnode_id
of your lock (found in Developer Tools > States). - Action: Updates the
input_text
entity with the operation type and user name based on the event data. Theusers
list corresponds to User IDs assigned in your lock.
Step 3: Testing
- Reload Automations: After saving the automation, reload your automations from the Home Assistant UI or restart Home Assistant.
- Operate the Lock: Test the lock by performing different operations (manual, RF, and keypad).
- Check the Status: The
input_text.front_door_lock_status
should update with the correct operation and user name.
Notes:
- Customization: Adjust the
users
array in the code to match the actual users and their corresponding User IDs on your lock. - Troubleshooting: If the status doesn’t update correctly, ensure that the
node_id
matches the one in your Z-Wave configuration and that the automation is active.
By following these steps, you’ll be able to capture detailed lock events in Home Assistant, allowing you to know exactly who locked or unlocked your door, whether manually or via keypad.