KeyMaster Z-Wave lock manager and scheduler

Look back to middle - late August in this thread. There was discussion about using the events emitted by Keymaster instead of the built in notify script handler.

1 Like

Thank you Andrew to taking the time to assist me with my concern. I did search and I am not sure if the following is what you meant:

alias: 0 - Lock Logging
description: ""
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 -%}
condition: []
action:
  - service: logbook.log
    data:
      name: "{{ trigger.event.data.lockname }}"
      entity_id: "{{ trigger.event.data.entity_id }}"
      message: "{{ sn }} {{ verb }} the {{ trigger.event.data.lockname }}"
  - choose:
      - conditions:
          - "{{ sn != 'Manual' }}"
        sequence:
          - service: input_text.set_value
            data:
              value: "{{ sn }}"
            target:
              entity_id: input_text.yale_user
          - service: input_datetime.set_datetime
            data:
              datetime: "{{ now() }}"
            target:
              entity_id: input_datetime.last_user
mode: single

Could you please confirm. Sorry for being a newbie to HA and to the coding. I was thinking I only have to replace Keypad unlock operation with my phrase. Thank you again for your time and assistance.

Thatā€™s the final code snippet that I had written previously, yes. The final intent was to help the requester of it with the following:

  1. log to the system log the lock and method / person that opened it
  2. save the date and time of the last named slot usage to a datetime helper
  3. save the last named slot usage name to a text helper

Modifying the actions section is effectively what you need to be doing as if it was your manual_notify script.

Alternatively, you could do some debugging and actually figure out what all is passed to the manual_notify script and do the work there :wink:

2 Likes

Thank you again Andrew and I do appreciate your help. I will try to play with it and get it to work the way I want it to be. Thank you again.

Thanks to all who make our locks work with HA. Itā€™s my hope that one day all of this will be in the UI.

1 Like

Hello @firstof9,

Thank you! Iā€™m glad youā€™re looking into it :slight_smile:

I do (two ā€ŽSchlage BE468GBAK), at a remote location.
Installed and configured GitHub - firstof9/keymaster at zig2mqtt-support

Iā€™m stuck at starting the Zigbee2MQTT add-on: startup fails as Iā€™m already running ZHA and (think that I) cannot run both at the same time with the same controller.
Good time to switch though. Iā€™ll do the migration this WE and report back.

Iā€™m also trying to get what code was used to open the lock into the Logbook, but I feel like Iā€™m missing something. Iā€™ve looked through Home Assistantā€™s docs on Automation and Scripts Yaml and have tried adding code snippets from this thread to my automation.yaml. However, I canā€™t seem to get anything to appear in the logbook, and it seems to break my keymaster_frontdoor_manual_notify script. Iā€™m guessing this is because configuration.yaml includes automation, scripts, and scenes and Iā€™ve got some sort of formatting issue in automation.yaml.

Looking at:

It seems to format entries like:

- id: foo
  alias: bar

While in this thread I see snippets like:

- alias: bar
  id: foo

I guess first I should just ask, am I on the right track? Are you guys adding these entries to automation.yaml?

Are you editing automation.yaml directly? You really should be only editing it via the UI unless you really know what youā€™re doingā€¦

As to the order in your two examples. As far as yaml is concerned, they are the exact same.

Hah, yep, formatting issue. I was editing automation.yaml directly. I find yaml easier to read than the UI in this instance, but Iā€™m just not quite as familiar with it as I need to be to write it apparently. Or I overlooked an indentation error.

Either way, you gave me the idea to create as much of the automation as I could with the UI, then edit yaml for the rest.

Itā€™s working now, and in case it helps anyone else, here is the entirety of my automation.yaml:

- id: '1667935594434'
  alias: 01 - Lock Logging
  description: ''
  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 -%}
  condition: []
  action:
  - service: logbook.log
    data:
      name: "{{ trigger.event.data.lockname }}"
      entity_id: "{{ trigger.event.data.entity_id }}"
      message: "{{ sn }} {{ verb }} the {{ trigger.event.data.lockname }}"
  mode: single

Learnt the hard way last week that Zigbee2MQTT changes the network key of the Zigbee dongle upon first start: it scrapped my existing Zigbee networkā€¦ (had to re-pair everything once I got on site). I have a lot of devices requiring ZHA and will have to keep it running.

@firstof9 :

  • do you have a zigbee lock / have you been able to use your code with it ( Iā€™m considering purchasing a second zigbee stick to run Zigbee2MQTT on it and test it)
  • also found GitHub - firstof9/keymaster at zha-support
    Could you tell me whatā€™s its status?

Thanks!

I do not have a zigbee lock to test with at this time.
I do however have a zigbee network setup now.

Not yet.

As of August.:

FutureTense, I got this working last year with your help, so that I can use my Keypad to disarm my Alarm. Is there a way to do the opposite, i.e. use the Keypad to ARM my alarm system? Currently, when my wife or I leave the house and we want the alarm on, we arm it with our phones through the HA app. I donā€™t have any wall panels currently (maybe next project). That works fine for us, but if we have someone come to the house (say for example the Cleaners), they can disarm the Alarm, but then when they leave - it either stays disarmed or we have to ā€œnoticeā€ when the leave and manually re-arm the system. It would seem that if I can use Keymaster to ā€œdisarmā€ the alarm, I SHOULD be able to have an event that ā€œre-Armsā€ the Alarm if someone uses the keypad to lock it. Obviously, I canā€™t just re-arm the alarm every time the door locks - as there are many times when the door is locked that we DONā€™T want the Alarm on?

So I am thinking that in the automation, condition value_template, I just need to change the values in trigger.event.data.action_code, but I am not sure what they need to be changed to? Any help is greatly appreciated and thank you for a great project!

Thanks so much for your work! I got your branch set up and tested it out with my Kwikset 914 Zigbee locks and it doesnā€™t seem to be working, unless Iā€™m doing something wrong. It added the integration with no problem (didnā€™t seem any different than before) but the Lovelace view wonā€™t add codes and shows entity not available for sensor.connected_******** and binary_sensor.active_******** (asterisks are lock names omitted). I believe these are supposed to show the code adding status. Much appreciated!

Edit: Iā€™m an idiot, forgot to restart after adding the integration. After doing so, the behavior now seems no different than the main branch- just sticks on adding or deleting and does nothing.

Yup itā€™s slow going.

Thanks for this integration. Just set it up. Had a question. Is it ok to change the number of codes once the service has been setup? I see the option when i hit configure on a service. Or should I delete and re add? I am trying to determine if I should start with a small number like 5 and add more as needed? I started with 25 and would like to reduce it.

You can reduce the code slots, the files will be re-generated.

1 Like

@amoney I agree with @firstof9 on that. Iā€™ve got several locks and I usually just add the number of slots that I need to manage, and when I outgrow that (or no longer need that many on a regular basis) then I change the number and get the files all regenerated.

I would strongly recommend that you make sure that any codes that are assigned to higher number slots are cleared before you reduce though :wink:

1 Like

After I setup the integration i see a couple of errors in the logs

2022-12-09 07:30:28.954 ERROR (MainThread) [frontend.js.latest.202212080] https://**********.duckdns.org/lovelace/default_view:0:0 Uncaught TypeError: Failed to resolve module specifier "@rollup/plugin-node-resolve". Relative references must start with either "/", "./", or "../".
2022-12-09 07:30:28.985 ERROR (MainThread) [frontend.js.latest.202212080] https://*****************.duckdns.org/local/community/lovelace-card-tools/webpack.config.js:1:14 Uncaught ReferenceError: require is not defined

I added the webpack.config.js as a module under ressources. Any ideaā€™s on what I need to do to clean these errorrs up?

I am having difficulty with notification for a second door. History shows that manual notify automation is firing for the new lock. It just is not passing ā€œtitle:ā€ and ā€œmessage:ā€ If i replace ā€˜{{ title }}ā€™ and ā€˜{{ message }}ā€™ with text the notification is sent.
Notifications for the old lock work as expected.

notification script looks like this:

keymaster_frontdoor_manual_notify:
  mode: parallel
  sequence:
  - service: notify.telegram_all
    data:
      title: '{{ title }}'
      message: '{{ message }}'

keymaster_back_door_manual_notify:
  mode: parallel
  sequence:
  - service: notify.telegram_all
    data:
      title: '{{ title }}'
      message: '{{ message }}'

back_door_manual_notify throws the following error:

2022-12-09 08:33:36.132 ERROR (SyncWorker_15) [homeassistant.components.telegram_bot] Error sending message: Can't parse entities: can't find end of the entity starting at byte offset 4. Args: (2115185726, 'back_door\nManual unlock operation'), kwargs: {'parse_mode': 'Markdown', 'disable_web_page_preview': None, 'disable_notification': False, 'reply_to_message_id': None, 'reply_markup': None, 'timeout': None}

Any thoughts on how to fix?

From my poor coding eye, Iā€™m thinking that the nManual in ā€œback_door\nManual unlock operationā€ is a typo. I just cant find where I can find it to correct.

Any help would be appreciated.