KeyMaster Z-Wave lock manager and scheduler

Oh sorry, yes of course. Thanks

alias: SS - Lock Logging
description: Custom Keymaster Notification
trigger:
  - platform: event
    event_type: keymaster_lock_state_changed
    event_data:
      state: unlocked
    variables:
      sn: |-
        {%- if trigger.event.data.code_slot_name == "" -%}
          Manual
        {%- else -%}
          {{ trigger.event.data.code_slot_name }}
        {%- endif -%}
      verb: |-
        {%- if trigger.event.data.code_slot_name == "" -%}
          unlock of
        {%- else -%}
          unlocked
        {%- endif -%}
      door: |-
        {%- if trigger.event.data.lockname == "front_door" -%}
          Front Door
        {%- elif trigger.event.data.lockname == "laundry_room" -%}
          Laundry Room Door
        {%- else -%}
          Garage Side Door
        {%- endif -%}
condition: []
action:
  - data:
      name: "{{ trigger.event.data.lockname }}"
      entity_id: "{{ trigger.event.data.entity_id }}"
      message: "{{ sn }} {{ verb }} the {{ door }}"
    action: logbook.log
  - metadata: {}
    data:
      message: "{{ sn }} {{ verb }} the {{ door }}"
      title: "{{ door }}"
      data:
        tag: "{{ door }}"
    action: notify.mobile_app_ss_s24u
mode: single

I’m not 100% certain that the changes here are going to work, but I think they should.

ias: SS - Lock Logging
description: Custom Keymaster Notification
trigger:
  - platform: event
    event_type: keymaster_lock_state_changed
    event_data:
      state: unlocked
    variables:
      sn: |-
        {%- if trigger.event.data.code_slot_name == "" -%}
          Manual
        {%- else -%}
          {{ trigger.event.data.code_slot_name }}
        {%- endif -%}
      verb: |-
        {%- if trigger.event.data.code_slot_name == "" -%}
          unlock of
        {%- else -%}
          unlocked
        {%- endif -%}
      door: |-
        {%- if trigger.event.data.lockname == "front_door" -%}
          Front Door
        {%- elif trigger.event.data.lockname == "laundry_room" -%}
          Laundry Room Door
        {%- else -%}
          Garage Side Door
        {%- endif -%}
      code_slot: trigger.event.data.code_slot
      notify_state: >-
        {% states("input_boolean.notify_" + trigger.event.data.lockname + "_ +
        code_slot | string) %}
condition: []
action:
  - data:
      name: "{{ trigger.event.data.lockname }}"
      entity_id: "{{ trigger.event.data.entity_id }}"
      message: "{{ sn }} {{ verb }} the {{ door }}"
    action: logbook.log
  - if:
      - condition: template
        value_template: "{{ notify_state == \"on\" }}"
    then:
      - metadata: {}
        data:
          message: "{{ sn }} {{ verb }} the {{ door }}"
          title: "{{ door }}"
          data:
            tag: "{{ door }}"
        action: notify.mobile_app_ss_s24u
mode: single

I’ve added two new variables code_slot (which comes from the event data) and the state of the notify boolean.

Then in the notify action itself, I’ve wrapped it in an if statement to say only send a notification if the notify toggle is “on”.

I have not tested this with an actual lock, but the variable setting should work and then it’s just a matter of making sure that the if logic is correct.

Thanks bud!

So I brought that in and got the following. Is this what you were referring to? Thank you so much

Yes, that’s what I was referring to. I only did a minimal amount of testing in the dev tools template tester to figure out some of the syntax there. You may need to fiddle around with it some to figure out how to get that variable to be set correctly. Alternatively, you could try moving the states expression down into to the value_template section of the if condition and replace the variable check.

In any case, this should be the right direction for you to play with.

Thanks. I dont know much of this level of coding in HA but will start working to learn. Can I ask if this also has anything in it regarding the showing of only when a lock has its code entered (vs a manual unlock from inside of the home)? Thanks again for all the help

No, I didn’t include anything to not send a notification if it’s a manual unlock. But that would just be another condition in that if statement making sure that

sn != 'Manual'

Thanks. So I dont really know what Im doing but I messed with the syntax and think the issue was a ’ in the notify_state to make it stop throwing a syntax error. It didnt seem to work (in that I disabled the laundry room lock) but it was still sending me the notification. If Im understanding correctly it should be using the bottom message when the lock is enabled. I temp put a ‘2’ in the wording to see if firing and it still using the first message line (that doesnt have the 2) so I suppose its not recognizing it as off.

Although I believe that is going to the logbook but still seems to be whats going to my phone. Hopefully that makes sense. As for the sn != ‘Manual’, would that go where ‘value_template’ is? My apologies Im just winging this lol

Here was the code currently

alias: SS - Lock Logging2
description: Custom Keymaster Notification
trigger:
  - platform: event
    event_type: keymaster_lock_state_changed
    event_data:
      state: unlocked
    variables:
      sn: |-
        {%- if trigger.event.data.code_slot_name == "" -%}
          Manual
        {%- else -%}
          {{ trigger.event.data.code_slot_name }}
        {%- endif -%}
      verb: |-
        {%- if trigger.event.data.code_slot_name == "" -%}
          unlock of
        {%- else -%}
          unlocked
        {%- endif -%}
      door: |-
        {%- if trigger.event.data.lockname == "front_door" -%}
          Front Door
        {%- elif trigger.event.data.lockname == "laundry_room" -%}
          Laundry Room Door
        {%- else -%}
          Garage Side Door
        {%- endif -%}
      code_slot: trigger.event.data.code_slot
      notify_state: >-
        {{ states('input_boolean.notify_' + trigger.event.data.lockname + '_ +
        code_slot | string') }}
condition: []
action:
  - data:
      name: "{{ trigger.event.data.lockname }}"
      entity_id: "{{ trigger.event.data.entity_id }}"
      message: "{{ sn }} {{ verb }} the {{ door }}"
    action: logbook.log
  - if:
      - condition: template
        value_template: "{{ notify_state == \"on\" }}"
    then:
      - metadata: {}
        data:
          message: "{{ sn }} {{ verb }} the2 {{ door }}"
          title: "{{ door }}"
          data:
            tag: "{{ door }}"
        action: notify.mobile_app_ss_s24u
mode: single

And sorry one more dumb thing, this is linked to the ‘Lock Notifications’ and not the Door or Garage Notifications right? (from the Lock dashboard)

Ok, I’ve re-looked at this and yes, I had a few code errors in it. Here’s an updated version that should do what you’re wanting.

You’ll note that I’ve expanded the if condition with another condition checking on the state of the slot name not being "Manual". By default all of the conditions to an if are done as an AND conditional with HA, so by stating that the Lock Notifications setting needs to be on as well as it not being a Manual operation, should mean that you only get notifications where you want them but everything gets logged no matter what.

Again, I haven’t fully tested the logic on this, but I’m reasonably confident in this version.

alias: SS - Lock Logging
description: Custom Keymaster Notification
trigger:
  - platform: event
    event_type: keymaster_lock_state_changed
    event_data:
      state: unlocked
    variables:
      sn: |-
        {%- if trigger.event.data.code_slot_name == "" -%}
          Manual
        {%- else -%}
          {{ trigger.event.data.code_slot_name }}
        {%- endif -%}
      verb: |-
        {%- if trigger.event.data.code_slot_name == "" -%}
          unlock of
        {%- else -%}
          unlocked
        {%- endif -%}
      door: |-
        {%- if trigger.event.data.lockname == "front_door" -%}
          Front Door
        {%- elif trigger.event.data.lockname == "laundry_room" -%}
          Laundry Room Door
        {%- else -%}
          Garage Side Door
        {%- endif -%}
      code_slot: trigger.event.data.code_slot
      notify_state: >-
        {% states("input_boolean.notify_" + trigger.event.data.lockname + "_" +
        code_slot | string) %}
condition: []
action:
  - data:
      name: "{{ trigger.event.data.lockname }}"
      entity_id: "{{ trigger.event.data.entity_id }}"
      message: "{{ sn }} {{ verb }} the {{ door }}"
    action: logbook.log
  - if:
      - condition: template
        value_template: "{% notify_state == \"on\" %}"
      - condition: template
        value_template: "{% sn != \"Manual\" %}"
    then:
      - metadata: {}
        data:
          message: "{{ sn }} {{ verb }} the {{ door }}"
          title: "{{ door }}"
          data:
            tag: "{{ door }}"
        action: notify.mobile_app_ss_s24u
mode: single

I have notifications setup. There are 3 people in my house. When I use my code to unlock the lock, the notification shows my name. When my wife uses her code, my son’s name shows in the notification and vice versa. So I just switched their names in KeyMaster. After I did that, I disabled my wife’s code, then re-enabled it. Now, the PIN Status shows as Adding and never changes to Connected. Her code still seemed to work for a couple of days but now it doesn’t. Any ideas how I can fix this? I am on the newest version.

Turn “Enabled” to off on your wife’s code or the code where you are stuck at “Adding” then;
Go to “Developer Tools”, then “ACTIONS”, in Actions select “Z-Wave: Clear lock user code”, then in Targets select “Chose Entity” and select your lock, in code slot put in your the code slot number, select “Perform Action”. That what I call a reset, this should work, give it about 20 seconds before switching the code to Enable.

See this if you want it in an automation.

Thank you for the suggestion. Unfortunately, it doesn’t seem to work for me. Something is not being cleared out. I have 3 locks. My front door is the master. I selected my front door lock as the entity and entered 2 for the code slot. Then, clicked the perform Action button. After a couple of seconds, the Perform Action button turned green with a check mark. I waited a couple of minutes and tried to enable the code but it just stayed at adding. I tried adding all three locks but that did not work either. I also tried clicking on Advanced Options and then Reset Code Slot but that, also, did not work. When I disable the code, the PIN Status shows Deleting and then Disconnected. Re-enabling the code just gets stuck at Adding.

I entered my wife’s name with a number 2, code into another slot and it works. If I remove the 2 from her name, it does not work. When I add the 2 back, it works again.

Something is definitely not being cleared out.

I sorry it didn’t work for you. Do you have any AC powered ZWAVE devices within 10 feet of the locks?
Like repeaters, outlets, or light switches? This is an indication that you need a buffering ZWAVE repeater next to the locks, some commands are being dropped.

I have 3 Inovelli wall rocker within 8 feet of the front door lock. The Zwave receiver is within 12 feet.

I looked at the events for that lock Zwave JS and I could see it was receiving the information. I’m not sure what happened but it is working properly now. I must have done something that stopped it from working properly but I’m not exactly sure what.

Thank you for trying to help me. I appreciate it.

So I just tried this by searching for all automations with the word keymaster, using select all and it moved a few hundred of them and not others.

Turns out the hundreds of others have no unique ID or something so it won’t work.

I was curious about this custom notification. I am getting this error:
Message malformed: invalid template (TemplateSyntaxError: Encountered unknown tag 'states'.) for dictionary value @ data['trigger'][0]['variables']['notify_state']

This is the relevant section:

notify_state: >-
        {% states("input_boolean.notify_" + trigger.event.data.lockname + "_" + code_slot | string) %}

When I comment out this section as well as the section below, I get a new error.

Commented out section:

- condition: template
       value_template: "{% notify_state == \"on\" %}"

New error:
Message malformed: invalid template (TemplateSyntaxError: Encountered unknown tag 'sn'.) for dictionary value @ data['action'][1]['if'][0]['value_template']

I am not getting any notifications for Keymaster even though I have the manual script modified the way that I need. In the automations for user and lock notify, it shows that they have never run. They used to before I had to remove and readd my locks. I get a notification when the door opens and closes which uses the Keymaster automation, and it is showing as running. I’m wondering if it’s tied to keymaster_lock_state_changed never firing. How can I test this theory and/or fix the issue.

I have lock and door notifications enabled (and showing enabled) via the lovelace card.

To add more, I looked at the zwave_js events for last night when I unlocked the door with my code and then manually relocked it:

10/14/2024, 7:14:41 PM - notification
Arg 0:
113
Arg 1:
└─type: 6
└─event: 6
└─label: Access Control
└─eventLabel: Keypad unlock operation
└─parameters
└──userId: 1

and then:

10/14/2024, 7:14:59 PM - notification
Arg 0:
113
Arg 1:
└─type: 6
└─event: 1
└─label: Access Control
└─eventLabel: Manual lock operation