Schlage Connect Locks - HA Integration Needs Attention

Have not implemented this yet, but here is an easy way to set up a one time use code. For me I only have 18 codes set up because one of my locks only supports 18 codes. Anyway, I took 16, 17, and 18 and added them to a group called one time use.

Then I’m going to set up an automation like this

- alias: 'One Time Use for Code 16'
  trigger:
  - platform: state
    entity_id: sensor.lock_back_door_deadbolt_alarm_level
    to: '16'
  - platform: state
    entity_id: sensor.lock_front_door_deadbolt_alarm_level
    to: '16'
  - platform: state
    entity_id: sensor.lock_garage_door_lock_alarm_level
    to: '16'
  action:
  - service: script.turn_on
    entity_id: script.door_keypad_16_delete

Seems like it should work. If the code is used on any of the locks, it will be erased from all three. Nice thing is all the rest of the automation, sensors, etc are already there.

Looking at the rest of the code, How could I use this sort of logic in my scenario

	  - service: script.turn_on
        data_template:
          entity_id: >-
            {% set object_id = trigger.to_state.object_id %}
            {% set code_slot = object_id[7:-19] %}
            {{ 'script.door_keypad_' ~ code_slot ~ '_delete' }}

So trigger would be State change of these sensors

sensor.lock_front_door_deadbolt_alarm_level
sensor.lock_back_door_deadbolt_alarm_level
sensor.lock_garage_door_lock_alarm_level

Condition would be state = 16, or 17, or 18

Action would be

  - service: script.turn_on
    data_template:
      entity_id: >-
        {% set code_slot = STATE OF ALARM LEVEL %}  # This i struggle
        {{ 'script.door_keypad_' ~ code_slot ~ '_delete' }}

Seems like it would not be too hard.  I'm going to keep playing, I think this is not hard, I'm still just a a beginer state using templates and setting values like this

Probably a lot of duplication, but… I’m going to test this out tonight

  - alias: 'One Time Use for Code 16 - 18'
    trigger:
      - platform: state
        entity_id: sensor.lock_back_door_deadbolt_alarm_level
        to: '16'
      - platform: state
        entity_id: sensor.lock_front_door_deadbolt_alarm_level
        to: '16'
      - platform: state
        entity_id: sensor.lock_garage_door_lock_alarm_level
        to: '16'
      - platform: state
        entity_id: sensor.lock_back_door_deadbolt_alarm_level
        to: '17'
      - platform: state
        entity_id: sensor.lock_front_door_deadbolt_alarm_level
        to: '17'
      - platform: state
        entity_id: sensor.lock_garage_door_lock_alarm_level
        to: '17'
      - platform: state
        entity_id: sensor.lock_back_door_deadbolt_alarm_level
        to: '18'
      - platform: state
        entity_id: sensor.lock_front_door_deadbolt_alarm_level
        to: '18'
      - platform: state
        entity_id: sensor.lock_garage_door_lock_alarm_level
        to: '18'
    action:
      - service: script.turn_on
        entity_id: >-
          {% if is_state('sensor.lock_front_door_deadbolt_alarm_level', '16') %}
            script.door_keypad_16_delete
          {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '17') %}
            script.door_keypad_17_delete
          {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '18') %}
            script.door_keypad_18_delete
          {% if is_state('sensor.lock_back_door_deadbolt_alarm_level', '16') %}
            script.door_keypad_16_delete
          {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '17') %}
            script.door_keypad_17_delete
          {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '18') %}
            script.door_keypad_18_delete
          {% if is_state('sensor.lock_garage_door_lock_alarm_level', '16') %}
            script.door_keypad_16_delete
          {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '17') %}
            script.door_keypad_17_delete
          {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '18') %}
            script.door_keypad_18_delete
          {% else %}
            n/a
          {% endif %}

I have this in my package as well, btw this works just great

      backdoor_action:
        friendly_name: 'Back Door Action'
        value_template: >
          {% if is_state('sensor.lock_back_door_deadbolt_alarm_type', '22') %}
            Manual Unlock
          {% elif is_state('sensor.lock_back_door_deadbolt_alarm_type', '21') %}
            Manual Lock
          {% elif is_state('sensor.lock_back_door_deadbolt_alarm_type', '19') %}
            Keypad Unlock
          {% elif is_state('sensor.lock_back_door_deadbolt_alarm_type', '18') %}
            Keypad Lock
          {% elif is_state('sensor.lock_back_door_deadbolt_alarm_type', '25') %}
            Wireless Unlock
          {% elif is_state('sensor.lock_back_door_deadbolt_alarm_type', '24') %}
            Wireless Lock
          {% elif is_state('sensor.lock_back_door_deadbolt_alarm_type', '9') %}
            Lock Jammed
          {% elif is_state('sensor.lock_back_door_deadbolt_alarm_type', '161') %}
            Tamper Alarm
          {% else %}
            HA Controlled
          {% endif %}
          
      backdoor_code:
        friendly_name: 'Back Door Code'
        value_template: >
          {% if is_state('sensor.lock_back_door_deadbolt_alarm_type', '19') or is_state('sensor.lock_back_door_deadbolt_alarm_type', '18') %}
            {% if is_state('sensor.lock_back_door_deadbolt_alarm_level', '1') %}
              {{ states.input_text.door_keypad_1_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '2') %}
              {{ states.input_text.door_keypad_2_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '3') %}
              {{ states.input_text.door_keypad_3_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '4') %}
              {{ states.input_text.door_keypad_4_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '5') %}
              {{ states.input_text.door_keypad_5_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '6') %}
              {{ states.input_text.door_keypad_6_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '7') %}
              {{ states.input_text.door_keypad_7_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '8') %}
              {{ states.input_text.door_keypad_8_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '9') %}
              {{ states.input_text.door_keypad_9_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '10') %}
              {{ states.input_text.door_keypad_10_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '11') %}
              {{ states.input_text.door_keypad_11_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '12') %}
              {{ states.input_text.door_keypad_12_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '13') %}
              {{ states.input_text.door_keypad_13_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '14') %}
              {{ states.input_text.door_keypad_14_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '15') %}
              {{ states.input_text.door_keypad_15_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '16') %}
              {{ states.input_text.door_keypad_16_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '17') %}
              {{ states.input_text.door_keypad_17_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '18') %}
              {{ states.input_text.door_keypad_18_name.state }}
            {% else %}
              Unknown
            {% endif %}
          {% else %}
            n/a
          {% endif %}
          
      frontdoor_action:
        friendly_name: 'Front Door Action'
        value_template: >
          {% if is_state('sensor.lock_front_door_deadbolt_alarm_type', '22') %}
            Manual Unlock
          {% elif is_state('sensor.lock_front_door_deadbolt_alarm_type', '21') %}
            Manual Lock
          {% elif is_state('sensor.lock_front_door_deadbolt_alarm_type', '19') %}
            Keypad Unlock
          {% elif is_state('sensor.lock_front_door_deadbolt_alarm_type', '18') %}
            Keypad Lock
          {% elif is_state('sensor.lock_front_door_deadbolt_alarm_type', '25') %}
            Wireless Unlock
          {% elif is_state('sensor.lock_front_door_deadbolt_alarm_type', '24') %}
            Wireless Lock
          {% elif is_state('sensor.lock_front_door_deadbolt_alarm_type', '9') %}
            Lock Jammed
          {% elif is_state('sensor.lock_front_door_deadbolt_alarm_type', '161') %}
            Tamper Alarm
          {% else %}
            HA Controlled
          {% endif %}
          
      frontdoor_code:
        friendly_name: 'Front Door Code'
        value_template: >
          {% if is_state('sensor.lock_front_door_deadbolt_alarm_type', '19') or is_state('sensor.lock_front_door_deadbolt_alarm_type', '18') %}
            {% if is_state('sensor.lock_front_door_deadbolt_alarm_level', '1') %}
              {{ states.input_text.door_keypad_1_name.state }}
            {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '2') %}
              {{ states.input_text.door_keypad_2_name.state }}
            {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '3') %}
              {{ states.input_text.door_keypad_3_name.state }}
            {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '4') %}
              {{ states.input_text.door_keypad_4_name.state }}
            {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '5') %}
              {{ states.input_text.door_keypad_5_name.state }}
            {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '6') %}
              {{ states.input_text.door_keypad_6_name.state }}
            {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '7') %}
              {{ states.input_text.door_keypad_7_name.state }}
            {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '8') %}
              {{ states.input_text.door_keypad_8_name.state }}
            {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '9') %}
              {{ states.input_text.door_keypad_9_name.state }}
            {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '10') %}
              {{ states.input_text.door_keypad_10_name.state }}
            {% elif is_state('sensor.lock_back_door_deadbolt_alarm_level', '11') %}
              {{ states.input_text.door_keypad_11_name.state }}
            {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '12') %}
              {{ states.input_text.door_keypad_12_name.state }}
            {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '13') %}
              {{ states.input_text.door_keypad_13_name.state }}
            {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '14') %}
              {{ states.input_text.door_keypad_14_name.state }}
            {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '15') %}
              {{ states.input_text.door_keypad_15_name.state }}
            {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '16') %}
              {{ states.input_text.door_keypad_16_name.state }}
            {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '17') %}
              {{ states.input_text.door_keypad_17_name.state }}
            {% elif is_state('sensor.lock_front_door_deadbolt_alarm_level', '18') %}
              {{ states.input_text.door_keypad_18_name.state }}
            {% else %}
              Unknown
            {% endif %}
          {% else %}
            n/a
          {% endif %}
          
      garagedoor_action:
        friendly_name: 'Garage Door Action'
        value_template: >
          {% if is_state('sensor.lock_garage_door_lock_alarm_type', '22') %}
            Manual Unlock
          {% elif is_state('sensor.lock_garage_door_lock_alarm_type', '21') %}
            Manual Lock
          {% elif is_state('sensor.lock_garage_door_lock_alarm_type', '19') %}
            Keypad Unlock
          {% elif is_state('sensor.lock_garage_door_lock_alarm_type', '18') %}
            Keypad Lock
          {% elif is_state('sensor.lock_garage_door_lock_alarm_type', '25') %}
            Wireless Unlock
          {% elif is_state('sensor.lock_garage_door_lock_alarm_type', '24') %}
            Wireless Lock
          {% elif is_state('sensor.lock_garage_door_lock_alarm_type', '9') %}
            Lock Jammed
          {% elif is_state('sensor.lock_garage_door_lock_alarm_type', '161') %}
            Tamper Alarm
          {% else %}
            HA Controlled
          {% endif %}
          
      garagedoor_code:
        friendly_name: 'Garage Door Code'
        value_template: >
          {% if is_state('sensor.lock_garage_door_lock_alarm_type', '19') or is_state('sensor.lock_garage_door_lock_alarm_type', '18') %}
            {% if is_state('sensor.lock_garage_door_lock_alarm_level', '1') %}
              {{ states.input_text.door_keypad_1_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '2') %}
              {{ states.input_text.door_keypad_2_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '3') %}
              {{ states.input_text.door_keypad_3_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '4') %}
              {{ states.input_text.door_keypad_4_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '5') %}
              {{ states.input_text.door_keypad_5_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '6') %}
              {{ states.input_text.door_keypad_6_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '7') %}
              {{ states.input_text.door_keypad_7_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '8') %}
              {{ states.input_text.door_keypad_8_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '9') %}
              {{ states.input_text.door_keypad_9_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '10') %}
              {{ states.input_text.door_keypad_10_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '11') %}
              {{ states.input_text.door_keypad_11_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '12') %}
              {{ states.input_text.door_keypad_12_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '13') %}
              {{ states.input_text.door_keypad_13_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '14') %}
              {{ states.input_text.door_keypad_14_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '15') %}
              {{ states.input_text.door_keypad_15_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '16') %}
              {{ states.input_text.door_keypad_16_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '17') %}
              {{ states.input_text.door_keypad_17_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '18') %}
              {{ states.input_text.door_keypad_18_name.state }}
            {% else %}
              Unknown
            {% endif %}
          {% else %}
            n/a
          {% endif %}

Trying to get this to trigger, and not having any luck.

- alias: 'Notify who unlocked backdoor and when it was unlocked'
  trigger:
  - platform: state
    entity_id: sensor.backdoor_action
    to: 'KeyPad Unlock'
  action:
  - service: notify.pushbullet_notifications
    data:
      message: " On {{ states.sensor.date.state }} at {{ states.sensor.time.state }}"
      target:
      - email/[email protected]
      title: "Door unlocked by {{ states.sensor.backdoor_code.state }}"    

This seems to be the state
‘KeyPad Unlock’

Any recommendations on troubleshooting

change data: to data_template:

Data does work, but I changed it., If I manually trigger it runs, so it must be the trigger. I mean here’s the state, it is changing, so what am I missing. :frowning:

2018-06-072018-06-07%20(1)

not 100% sure it might be this (not sure if HA is programmed for case sensitivity or not):

to: 'KeyPad Unlock'
try
to: 'Keypad Unlock'

1 Like

I’ve been doing some additions and modifications to the already awesome package provided by @nalipaz.

I hope to do a bit more testing, but I’ve customized it a bit more for the home user.

I’ve really just borrowed and modified various scripts from these forums and put them all into a single package.

If I get it all working using this as the baseline, I should have

  1. Code management (just the same as already here)
  2. Notifications for when doors are unlocked with codes, using the names already entered in the UI and providing a timestamp.
  3. One time use codes. Via the UI, select enable in UI, random code generated and enabled for all locks. Once code is used on any lock, it will be removed from all locks.

My locks are schlage but I believe it should work for most zwave locks. For the most part I tried to use the foundation that was already there and reuse when possible. More to come soon

2 Likes

this is FASCINATING! Exactly the sort of functionality I’ve been looking for but I’m a little unclear on how to expose certain attributes to HASS like battery level and such and to throw in an extra monkey-wrench into the whole thing my ZWave controller is the ISY994 which can be fickle.

I noticed there is a function in the script that calls for:

sensor.door_lock_batteries_front_door

and I don’t have that attribute available to call, it that platform dependent?
Further investigation reveals that I don’t have a “service: lock.set_usercode” either, however I have used REST commands with high reliability, this syntax is used for ISY controllers for changing lock codes:

http://username:password@ISY994_IP_ADDRESS/rest/zwave/node/ZW006_1/security/user/[4-30]/set/code/####

I’m going to try best to dissect this code to fit my particular situation and any help with that would be incredible as my scripting isn’t the strongest

Nice @ptdalen, I look forward to seeing your changes!

Are you are of any issues with packages getting too large and not acting “right?”

I have an couple of sensors, that I had under sensors.yaml, them I put them into the door_locks.yaml package. They seem to work once or twice and then stop.

Prior to adding them they seemed to work. I’m taking them back out and will see if it works any better?

Not that I am aware. You might want to check your logs. Sometimes I have to comment out a bunch of other stuff to isolate the errors from something in particular like that.

Actually i think it’s just me being impatient. Need to give HA a few minutes after a restart.

@nalipaz

I just realized that I dont think this has been setting any of my codes

I’m sure it’s probably something I’ve done previoully, but it did bring up a quick question

          node_id: >-
            {% set object_id = trigger.to_state.object_id %}
            {% set lock_name = "_".join(object_id.split("_")[3:-1]) %}
            {% set lock_id = 'lock_' ~ lock_name ~ '_door_lock' %}
            {{ states['lock'][lock_id].attributes.node_id }}

would this end up as
{{ states[‘lock’][lock_id].attributes.node_id }}
being
locklock_back_door_lock
or does it add the. between lock and lock because of the []

Just trying to see what might be wrong in my config

I’ve done so many tweaks and changes in a short time, so I’m not sure what has changed, but Not getting codes to update.

I’ll say that I found this worked

  {
  "node_id": 81,
  "code_slot": 3,
  "usercode": "1234"
  }

but this did not

  {
  "node_id": 81,
  "code_slot": 3,
  "usercode": 1234
  }

Again, might just need to be patient, between HA restarts, and zwave “warming” up, I might be trying things too quickly. When I 1st loaded this I was running a dev branch of open zwave, now I’m running the normal branch, gonna have to check that too

Going to try changing this part of your 1st automation

          code_slot: >-
            {% set object_id = trigger.to_state.object_id %}
            {% set code_slot = "_".join(object_id.split("_")[2:-2]) %}
            {{ code_slot }}

I removed the
| int

Might be required for my locks. I cannot remember are you using schlage be469’s?

I think the user code is supposed to be sent as a string not an int.

Yeah, I agree. Weird, part was I had this working perfectly for the past several weeks. Although it’s one of those things that you really dont revisit often. I mean how often do you change door codes. :slight_smile:

Since the 1st time I had it working, I’ve changed zwave versions, added a several sensors to report which code opened the door, renamed a lot of items via entity registry, and of course made a few minor tweaks to the package itself.

It definitely worked in the begining. I reverted to an earier version of the package and it still did not work. Not sure if you remember but I was one of the could people running the owzdev flavor and had “odd” behavior with my schlage be469. I ended up reverting to a master branch and the locks added all the sensors I needed to get my other door lock automatons working, but now I’m wondering if the versions did not handle the loading of codes differently. I’ll play around this weekend and see if I can get this ironed out. :slight_smile:

Remember you can dump the template code you’re using into the template menu in HA to check and make sure it’s returning what you’re expecting :wink: (It’s the one that looks like a paper with <> on it)