ZWave JS User Lock Codes

I’ve built a little script and frontend that helps me maintain my 3 Yale YRD256 locks with updating and deleting codes. The codes are stored in entities and passed along to the locks through the ZWAVE_JS.SET_LOCK_USERCODE service and removing the codes with ZWAVE_JS.CLEAR_LOCK_USERCODE

…and nearly all of the time it works flawlessly, expect when it doesn’t. Every once in awhile the codes just don’t register or aren’t deleted. What I would like to do is add a verification script after the set/delete routine after the script is executed and compare the store code entity to the actual code stored in the lock…but I can’t find any way to view what the current lock code is set for? Is there any entity or attribute in ZWave JS that exposes the lock codes? What am I missing? Surely someone far more intelligent than me has an answer to this! lol.

1 Like

On my Schlage locks, in the ZwaveJS2MQTT control panel, set lock codes show up as a bunch of asterisks (********) and codes not set are blank. You might be able to use this to do some checks in yoru script, but I dont know for sure if you can read this data.

An alternative is Keymaster

Keymaster does work, but it is a little clunky and rough around the edges. Install creates a ton of entities. I had issues with it and got rid of it, but others have been using it in their AirBnBs and homes for awhile. Might be worth a look.

Thanks Greg…I can see the codes in the Zwave2MQTT control panel as well. Would just be convenient to be able to verify it through an automation…Afterall that’s the whole purpose of HA…to make our lives easier?! lol

I also looked at Keymaster and while it’s a great integration, it’s a lot more than I need and like you, I wasn’t a fan of the ‘bloat’ it added to my setup.

@mboarman Would you happen to still have the scripts you made for updating codes? I find keymaster waaaaay to heavy and it doesn’t seem to work well. I end up setting codes in ZWave JS UI instead. Would much rather a simple update script or two.

Weird…I know I had a thread on here somewhere with the entire script and frontend yaml laid out, but I can’t find it anywhere…I’ll do my best to re-create it here:

This does require creating some helpers (amount depends on how many users and locks you have). Below is the script I put in a package (note: I have three locks but paired it down to two for this example)

script:

## Front Door 

  set_lock_frontdoor_code:
    alias: Set Front Door Lock Code
    sequence:
    - service: zwave_js.set_lock_usercode
      target:
        entity_id: lock.lock_front_door
      data:
        usercode: >
          {{ "%04d" % states('input_text.front_door_code_' ~ states('input_select.code_slot')) | int(0) }} 
        code_slot: '{{ states("input_select.code_slot") | int }}'
    mode: single
    icon: mdi:arrow-right-bold-circle
    
  delete_lock_frontdoor_code:
    alias: Delete Front Lock Code
    sequence:
    - service: zwave_js.clear_lock_usercode
      target:
        entity_id: lock.lock_front_door
      data:
        code_slot: '{{ states("input_select.code_slot") | int }}'
        
    - service: input_text.set_value
      data:
        entity_id: >
          {% if is_state('input_select.code_slot','01') %}
            input_text.front_door_code_01
          {% elif is_state('input_select.code_slot','02') %}
            input_text.front_door_code_02
          {% elif is_state('input_select.code_slot','03') %}
            input_text.front_door_code_03
          {% elif is_state('input_select.code_slot','04') %}
            input_text.front_door_code_04
          {% elif is_state('input_select.code_slot','05') %}
            input_text.front_door_code_05
          {% elif is_state('input_select.code_slot','06') %}
            input_text.front_door_code_06
          {% endif %}
        value: ""
    - service: input_text.set_value
      data:
        entity_id: >
          {% if is_state('input_select.code_slot','01') %}
            input_text.code_slot_front_user_01
          {% elif is_state('input_select.code_slot','02') %}
            input_text.code_slot_front_user_02
          {% elif is_state('input_select.code_slot','03') %}
            input_text.code_slot_front_user_03
          {% elif is_state('input_select.code_slot','04') %}
            input_text.code_slot_front_user_04
          {% elif is_state('input_select.code_slot','05') %}
            input_text.code_slot_front_user_05
          {% elif is_state('input_select.code_slot','06') %}
            input_text.code_slot_front_user_06
          {% endif %}
        value: ""
    mode: single
    icon: mdi:delete-circle

##Back Door
    
  set_lock_bckdoor_code:
    alias: Set Back Door Lock Code
    sequence:
    - service: zwave_js.set_lock_usercode
      target:
        entity_id: lock.lock_back_door
      data:
        usercode: >
          {{ "%04d" % states('input_text.bck_lock_code_' ~ states('input_select.code_slot')) | int(0) }}        
        code_slot: '{{ states("input_select.code_slot") | int }}'
    mode: single
    icon: mdi:arrow-right-bold-circle
    
  delete_lock_bckdoor_code:
    alias: Delete Back Lock Code
    sequence:
    - service: zwave_js.clear_lock_usercode
      target:
        entity_id: lock.lock_back_door
      data:
        code_slot: '{{ states("input_select.code_slot") | int }}'   
                    
        
    - service: input_text.set_value
      data: #user name
        entity_id: >              
         {% if is_state('input_select.code_slot','01') %}
           input_text.code_slot_bck_user_01
         {% elif is_state('input_select.code_slot','02') %}
           input_text.code_slot_bck_user_02
         {% elif is_state('input_select.code_slot','03') %}
           input_text.code_slot_bck_user_03
         {% elif is_state('input_select.code_slot','04') %}
           input_text.code_slot_bck_user_04
         {% elif is_state('input_select.code_slot','05') %}
           input_text.code_slot_bck_user_05
         {% elif is_state('input_select.code_slot','06') %}
           input_text.code_slot_bck_user_06
         {% endif %}
        value: ""
    - service: input_text.set_value
      data: #user code
        entity_id: >       
         {% if is_state('input_select.code_slot','01') %}
           input_text.bck_lock_code_01
         {% elif is_state('input_select.code_slot','02') %}
           input_text.bck_lock_code_02
         {% elif is_state('input_select.code_slot','03') %}
           input_text.bck_lock_code_03
         {% elif is_state('input_select.code_slot','04') %}
           input_text.bck_lock_code_04
         {% elif is_state('input_select.code_slot','05') %}
           input_text.bck_lock_code_05
         {% elif is_state('input_select.code_slot','06') %}
           input_text.bck_lock_code_06
         {% endif %}
        value: ""
    mode: single
    icon: mdi:delete-circle

Helpers needed for each door and lock:

input_text.yourlock_lock_code_01 (one for each code 01 - ??)
input_text.code_slot_yourlock_user_01 (one for each user (01 - ??)

For example…If you want to have up to six slots, then you would need a total of 12 helpers (6 of each) for EACH lock.

input_select.code_slot (this help just tells the script how many codes you want for each lock in the drop down.

here is an example:

The yaml for the frontend is pretty straight forward:

  - theme: Google Dark Theme Mod
    title: LOCKS
    path: locks
    type: custom:grid-layout
    badges: []
    cards:
      - type: horizontal-stack
        cards:
          - cards:
              - type: entities
                title: Front Door Lock Codes
                entities:
                  - input_select.code_slot
              - type: custom:state-switch
                entity: input_select.code_slot
                states:
                  '01':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_front_user_01
                      - entity: input_text.front_door_code_01
                      - entity: script.set_lock_frontdoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_frontdoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_frontdoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_frontdoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
                  '02':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_front_user_02
                      - entity: input_text.front_door_code_02
                      - entity: script.set_lock_frontdoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_frontdoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_frontdoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_frontdoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
                  '03':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_front_user_03
                      - entity: input_text.front_door_code_03
                      - entity: script.set_lock_frontdoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_frontdoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_frontdoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_frontdoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
                  '04':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_front_user_04
                      - entity: input_text.front_door_code_04
                      - entity: script.set_lock_frontdoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_frontdoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_frontdoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_frontdoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
                  '05':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_front_user_05
                      - entity: input_text.front_door_code_05
                      - entity: script.set_lock_frontdoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_frontdoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_frontdoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_frontdoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
                  '06':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_front_user_06
                      - entity: input_text.front_door_code_06
                      - entity: script.set_lock_frontdoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_frontdoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_frontdoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_frontdoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
            type: vertical-stack
          - cards:
              - type: entities
                title: Back Door Lock Codes
                entities:
                  - input_select.code_slot
              - type: custom:state-switch
                entity: input_select.code_slot
                states:
                  '01':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_bck_user_01
                      - entity: input_text.bck_lock_code_01
                      - entity: script.set_lock_bckdoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_bckdoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_bckdoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_bckdoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
                  '02':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_bck_user_02
                      - entity: input_text.bck_lock_code_02
                      - entity: script.set_lock_bckdoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_bckdoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_bckdoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_bckdoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
                  '03':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_bck_user_03
                      - entity: input_text.bck_lock_code_03
                      - entity: script.set_lock_bckdoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_bckdoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_bckdoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_bckdoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
                  '04':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_bck_user_04
                      - entity: input_text.bck_lock_code_04
                      - entity: script.set_lock_bckdoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_bckdoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_bckdoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_bckdoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
                  '05':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_bck_user_05
                      - entity: input_text.bck_lock_code_05
                      - entity: script.set_lock_bckdoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_bckdoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_bckdoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_bckdoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
                  '06':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_bck_user_06
                      - entity: input_text.bck_lock_code_06
                      - entity: script.set_lock_bckdoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_bckdoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_bckdoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_bckdoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
            type: vertical-stack
          - cards:
              - type: entities
                title: Garage Door Lock Codes
                entities:
                  - input_select.code_slot
              - type: custom:state-switch
                entity: input_select.code_slot
                states:
                  '01':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_garage_user_01
                      - entity: input_text.garage_door_code_01
                      - entity: script.set_lock_garagedoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_garagedoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_garagedoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_garagedoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
                  '02':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_garage_user_02
                      - entity: input_text.garage_door_code_02
                      - entity: script.set_lock_garagedoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_garagedoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_garagedoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_garagedoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
                  '03':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_garage_user_03
                      - entity: input_text.garage_door_code_03
                      - entity: script.set_lock_garagedoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_garagedoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_garagedoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_garagedoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
                  '04':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_garage_user_04
                      - entity: input_text.garage_door_code_04
                      - entity: script.set_lock_garagedoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_garagedoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_garagedoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_garagedoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
                  '05':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_garage_user_05
                      - entity: input_text.garage_door_code_05
                      - entity: script.set_lock_garagedoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_garagedoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_garagedoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_garagedoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
                  '06':
                    cards: null
                    type: entities
                    entities:
                      - entity: input_text.code_slot_garage_user_06
                      - entity: input_text.garage_door_code_06
                      - entity: script.set_lock_garagedoor_code
                        action_name: Set
                        type: button
                        name: Set Lock Code
                        tap_action:
                          action: call-service
                          service: script.set_lock_garagedoor_code
                          confirmation:
                            text: Change the lock code for this slot?
                      - entity: script.delete_lock_garagedoor_code
                        action_name: Delete
                        type: button
                        name: Delete Lock Code
                        tap_action:
                          action: call-service
                          service: script.delete_lock_garagedoor_code
                          confirmation:
                            text: Delete the lock code for this slot?
            type: vertical-stack

It looks cumbersome, but once put together runs pretty smoothly…It also isn’t as bloat-y as Keymaster. Keymaster is a great script, just way more than I needed. Hope this helps!

3 Likes

I am sorry but I am new to home assistant, and I just was able to add an old kwikset 910 to the z-wave controller, and now I am struggling with adding the user codes to the lock via Z-Wave JS.

Where I can set this yaml for the front end ?

Hi @gerootech -

  1. Go to the Developer Tools → Services and look for the service “Z-Wave: Set a usercode on a lock”.
  2. Select the lock entity as target
  3. Type a Code Slot (There is code slot 1-20 for that model)
  4. Enter a code, make a note of what code slot is which code in a spreadsheet, password manager or elsewhere.

2 Likes

Thanks, That is very helpful.

Thanks for this info, I would have taken ages to find it otherwise.

Is there a way to interrogate the memory registers first to understand if they have been filled already? I used to use OpenHAB and I think I it had a way of doing it via the UI.