There are several packages out there for lock and code management, including one from me. What I have noticed is some people are really looking for just a simple way to set a code and clear a code. No need to one use, or calendars, etc. I also feel like I see many, many post from people looking for help because they are new to HA and don’t yet really understand what is really happening with these packages. I was one of those people. So since I’m sitting home like so many others. I took my lock package and stripped out anything fancy. This is basically, set a code ,clear a code. Get a notification if you want, and that about it. I have not tested it on my install, but it should work. I’m not posting on github, and don’t plan on keeping this updated. It’s for one lock only, and if you don’t want to edit the yaml, you’ll have to name your entities accordingly. Copy the code below, into a yaml file, put it in your packages folder. If you don’t know how to change the name of an entity, or what a package folder is, I recommend doing a bit more reading before continuing.
#################################################################
# For this to work Name your lock entities as follows #
# lock.front_door #
# sensor.front_door_deadbolt_alarm_type, #
# sensor.front_door_deadbolt_alarm_level #
# use the recorder component in your configuration.yaml #
# For notifications I use pushbullet, but replace with #
# notifyier of your choice if you wish. #
#################################################################
automation:
- alias: Keypad switch turned on (Front Door)
initial_state: true
trigger:
- platform: state
to: 'on'
entity_id:
- input_boolean.door_keypad_1_front_switch
- input_boolean.door_keypad_2_front_switch
- input_boolean.door_keypad_3_front_switch
- input_boolean.door_keypad_4_front_switch
- input_boolean.door_keypad_5_front_switch
- input_boolean.door_keypad_6_front_switch
- input_boolean.door_keypad_7_front_switch
- input_boolean.door_keypad_8_front_switch
- input_boolean.door_keypad_9_front_switch
- input_boolean.door_keypad_10_front_switch
- input_boolean.door_keypad_11_front_switch
- input_boolean.door_keypad_12_front_switch
- input_boolean.door_keypad_13_front_switch
- input_boolean.door_keypad_14_front_switch
- input_boolean.door_keypad_15_front_switch
condition:
- condition: template
value_template: >-
{% set object_id = trigger.to_state.object_id %}
{% set code_slot = "_".join(object_id.split("_")[2:-2]) %}
{% set select_id = 'door_keypad_' ~ code_slot ~ '_code' %}
{{ (states['input_text'][select_id].state != 'Code Here') }}
action:
- service: lock.set_usercode
data_template:
node_id: >-
{{ states.lock.front_door.attributes.node_id }}
code_slot: >-
{% set object_id = trigger.to_state.object_id %}
{% set code_slot = "_".join(object_id.split("_")[2:-2]) %}
{{ code_slot }}
usercode: >-
{% set object_id = trigger.to_state.object_id %}
{% set code_slot = "_".join(object_id.split("_")[2:-2]) %}
{% set user_code_id = 'door_keypad_' ~ code_slot ~ '_code' %}
{{ states['input_text'][user_code_id].state }}
- alias: Keypad switch turned off (Front Door)
initial_state: true
trigger:
- platform: state
to: 'off'
entity_id:
- input_boolean.door_keypad_1_front_switch
- input_boolean.door_keypad_2_front_switch
- input_boolean.door_keypad_3_front_switch
- input_boolean.door_keypad_4_front_switch
- input_boolean.door_keypad_5_front_switch
- input_boolean.door_keypad_6_front_switch
- input_boolean.door_keypad_7_front_switch
- input_boolean.door_keypad_8_front_switch
- input_boolean.door_keypad_9_front_switch
- input_boolean.door_keypad_10_front_switch
- input_boolean.door_keypad_11_front_switch
- input_boolean.door_keypad_12_front_switch
- input_boolean.door_keypad_13_front_switch
- input_boolean.door_keypad_14_front_switch
- input_boolean.door_keypad_15_front_switch
condition:
- condition: template
value_template: >-
{% set object_id = trigger.to_state.object_id %}
{% set code_slot = "_".join(object_id.split("_")[2:-2]) %}
{% set select_id = 'door_keypad_' ~ code_slot ~ '_code' %}
{{ (states['input_text'][select_id].state != 'Code Here') }}
action:
# this is where usercodes get deleted, for the many locks there is a known issue with clear usercode
# so this sets a random code, of course that means there is an unknown code in the cleared
# slots. If you dont like that set a specific code that only you know using - usercode: number_here
- service: lock.set_usercode
data_template:
usercode: >-
{{ range(1000, 9999) | random }}
node_id: >-
{{ states.lock.front_door.attributes.node_id }}
code_slot: >-
{% set object_id = trigger.to_state.object_id %}
{% set code_slot = "_".join(object_id.split("_")[2:-2]) %}
{{ code_slot }}
- alias: Keypad switch turned on or off with no code set
initial_state: true
trigger:
- platform: state
to: 'on'
entity_id:
- input_boolean.door_keypad_1_front_switch
- input_boolean.door_keypad_2_front_switch
- input_boolean.door_keypad_3_front_switch
- input_boolean.door_keypad_4_front_switch
- input_boolean.door_keypad_5_front_switch
- input_boolean.door_keypad_6_front_switch
- input_boolean.door_keypad_7_front_switch
- input_boolean.door_keypad_8_front_switch
- input_boolean.door_keypad_9_front_switch
- input_boolean.door_keypad_10_front_switch
- input_boolean.door_keypad_11_front_switch
- input_boolean.door_keypad_12_front_switch
- input_boolean.door_keypad_13_front_switch
- input_boolean.door_keypad_14_front_switch
- input_boolean.door_keypad_15_front_switch
condition:
- condition: template
value_template: >-
{% set object_id = trigger.to_state.object_id %}
{% set code_slot = "_".join(object_id.split("_")[2:-2]) %}
{% set select_id = 'door_keypad_' ~ code_slot ~ '_code' %}
{{ (states['input_text'][select_id].state == 'Code Here') }}
action:
- service: input_boolean.turn_off
data_template:
entity_id: >
{{ trigger.to_state.object_id }}
- service: notify.pushover
data_template:
title: "No Code Entered"
message: >-
Please enter a name and a code before turning on the switch.
target:
- YOUR NAME HERE
- alias: Notify on Unlock (Front Door)
initial_state: true
trigger:
- platform: template
value_template: "{{ states.sensor.front_door_report.state.lower().startswith('keypad unlock') }}"
action:
- delay:
seconds: 1
# This will set a a friendly name of whoever unlocked the door to input_text.front_door_code, use in other automations if you wish
- service: input_text.set_value
data_template:
entity_id: input_text.front_door_code
value: >
{% set number = states('sensor.front_door_deadbolt_alarm_level') %}
{% set entity_id = 'input_text.door_keypad_' + number + '_name' %}
{% set user = 'Master' if number == '0' else states(entity_id) %}
{{ user }}
- condition: template
value_template: >-
{% set code_used = states('sensor.front_door_deadbolt_alarm_level') %}
{% set notify_input_object_id = 'code_' ~ code_used ~ '_notify' %}
{{ states['input_boolean'][notify_input_object_id].state == 'on' }}
- service: notify.pushover
data_template:
title: "Front Door Unlocked"
message: >-
by {{ states.input_text.front_door_code.state }} at {{ as_timestamp (now()) | timestamp_custom('%I:%M %p') }}
target:
- YOUR NAME HERE
input_text:
front_door_code:
name: Last Person to Unlock Front Door with Keypad
door_keypad_1_name:
name: Name
door_keypad_1_code:
name: Code
pattern: '[0-9]*'
door_keypad_2_name:
name: Name
door_keypad_2_code:
name: Code
pattern: '[0-9]*'
door_keypad_3_name:
name: Name
door_keypad_3_code:
name: Code
pattern: '[0-9]*'
door_keypad_4_name:
name: Name
door_keypad_4_code:
name: Code
pattern: '[0-9]*'
door_keypad_5_name:
name: Name
door_keypad_5_code:
name: Code
pattern: '[0-9]*'
door_keypad_6_name:
name: Name
door_keypad_6_code:
name: Code
pattern: '[0-9]*'
door_keypad_7_name:
name: Name
door_keypad_7_code:
name: Code
pattern: '[0-9]*'
door_keypad_8_name:
name: Name
door_keypad_8_code:
name: Code
pattern: '[0-9]*'
door_keypad_9_name:
name: Name
door_keypad_9_code:
name: Code
pattern: '[0-9]*'
door_keypad_10_name:
name: Name
door_keypad_10_code:
name: Code
pattern: '[0-9]*'
door_keypad_11_name:
name: Name
door_keypad_11_code:
name: Code
pattern: '[0-9]*'
door_keypad_12_name:
name: Name
door_keypad_12_code:
name: Code
pattern: '[0-9]*'
door_keypad_13_name:
name: Name
door_keypad_13_code:
name: Code
pattern: '[0-9]*'
door_keypad_14_name:
name: Name
door_keypad_14_code:
name: Code
pattern: '[0-9]*'
door_keypad_15_name:
name: Name
door_keypad_15_code:
name: Code
pattern: '[0-9]*'
input_boolean:
door_keypad_1_front_switch:
door_keypad_2_front_switch:
door_keypad_3_front_switch:
door_keypad_4_front_switch:
door_keypad_5_front_switch:
door_keypad_6_front_switch:
door_keypad_7_front_switch:
door_keypad_8_front_switch:
door_keypad_9_front_switch:
door_keypad_10_front_switch:
door_keypad_11_front_switch:
door_keypad_12_front_switch:
door_keypad_13_front_switch:
door_keypad_14_front_switch:
door_keypad_15_front_switch:
code_1_notify:
name: Notify when Used
code_2_notify:
name: Notify when Used
code_3_notify:
name: Notify when Used
code_4_notify:
name: Notify when Used
code_5_notify:
name: Notify when Used
code_6_notify:
name: Notify when Used
code_7_notify:
name: Notify when Used
code_8_notify:
name: Notify when Used
code_9_notify:
name: Notify when Used
code_10_notify:
name: Notify when Used
code_11_notify:
name: Notify when Used
code_12_notify:
name: Notify when Used
code_13_notify:
name: Notify when Used
code_14_notify:
name: Notify when Used
code_15_notify:
name: Notify when Used
sensor:
- platform: template
sensors:
front_door_report:
friendly_name: 'Front Door'
value_template: >
{% set number = states('sensor.front_door_deadbolt_alarm_level') %}
{% set alarm_type_value = states('sensor.front_door_deadbolt_alarm_type') %}
{% set entity_id = 'input_text.door_keypad_' + number + '_name' %}
{% set user = 'Master' if number == '0' else states(entity_id) %}
{% set alarm_type_value = '24' if (as_timestamp(now())-as_timestamp(states.lock.front_door.last_changed)) < 15 and (as_timestamp(now())-as_timestamp(states.sensor.front_door_deadbolt_alarm_type.last_changed)) > 15 and (states.lock.front_door.state) == 'locked' else alarm_type_value %}
{% set alarm_type_value = '25' if (as_timestamp(now())-as_timestamp(states.lock.front_door.last_changed)) < 15 and (as_timestamp(now())-as_timestamp(states.sensor.front_door_deadbolt_alarm_type.last_changed)) > 15 and (states.lock.front_door.state) == 'unlocked' else alarm_type_value %}
{% set alarm_type_general_actions = {
'0':'No Status Reported',
'9':'Lock Jammed',
'17':'Keypad Lock Jammed',
'21':'Manual Lock',
'22':'Manual Unlock',
'23':'HA Lock Jammed',
'24':'HA Lock',
'25':'HA Unlock',
'26':'Auto Lock Jammed',
'27':'Auto Lock',
'32':'All Codes Deleted',
'161':'Bad Code Entered',
'167':'Battery Low',
'168':'Battery Critical',
'169':'Battery Too Low To Operate Lock' } %}
{% set alarm_type_lock_actions = {
'18':'Keypad Lock',
'19':'Keypad Unlock',
'162':'Lock Code Attempt Outside of Schedule' } %}
{% set alarm_type_code_actions = {
'33':'Code Deleted',
'112':'Code Changed',
'113':'Duplicate Code' } %}
{% if alarm_type_value in alarm_type_code_actions %}
{{ alarm_type_code_actions[alarm_type_value] }} (Code {{ number}})
{% elif alarm_type_value in alarm_type_lock_actions and number == '0' %}
{{ alarm_type_lock_actions[alarm_type_value] }} with Schlage Button
{% elif alarm_type_value in alarm_type_lock_actions %}
{{ alarm_type_lock_actions[alarm_type_value] }} with Code {{ number }} ({{ user }})
{% elif alarm_type_value in alarm_type_general_actions %}
{{ alarm_type_general_actions[alarm_type_value] }}
{% else %}
Unknown Alarm Type Value {{ states('sensor.front_door_deadbolt_alarm_type') }}
{% endif %}
script:
door_keypad_1_delete:
alias: Delete Door Code 1
sequence:
- service: input_text.set_value
data:
value: 'Name Here'
entity_id: input_text.door_keypad_1_name
- service: input_text.set_value
data:
value: 'Code Here'
entity_id: input_text.door_keypad_1_code
- service: input_select.select_option
data:
option: 'Disabled'
entity_id: input_select.door_keypad_1_slot_state
- service: input_boolean.turn_off
entity_id:
- input_boolean.door_keypad_1_front_switch
- input_boolean.code_1_notify
door_keypad_2_delete:
alias: Delete Door Code 2
sequence:
- service: input_text.set_value
data:
value: 'Name Here'
entity_id: input_text.door_keypad_2_name
- service: input_text.set_value
data:
value: 'Code Here'
entity_id: input_text.door_keypad_2_code
- service: input_select.select_option
data:
option: 'Disabled'
entity_id: input_select.door_keypad_2_slot_state
- service: input_boolean.turn_off
entity_id:
- input_boolean.door_keypad_2_front_switch
- input_boolean.code_2_notify
door_keypad_3_delete:
alias: Delete Door Code 3
sequence:
- service: input_text.set_value
data:
value: 'Name Here'
entity_id: input_text.door_keypad_3_name
- service: input_text.set_value
data:
value: 'Code Here'
entity_id: input_text.door_keypad_3_code
- service: input_select.select_option
data:
option: 'Disabled'
entity_id: input_select.door_keypad_3_slot_state
- service: input_boolean.turn_off
entity_id:
- input_boolean.door_keypad_3_front_switch
- input_boolean.code_3_notify
door_keypad_4_delete:
alias: Delete Door Code 4
sequence:
- service: input_text.set_value
data:
value: 'Name Here'
entity_id: input_text.door_keypad_4_name
- service: input_text.set_value
data:
value: 'Code Here'
entity_id: input_text.door_keypad_4_code
- service: input_select.select_option
data:
option: 'Disabled'
entity_id: input_select.door_keypad_4_slot_state
- service: input_boolean.turn_off
entity_id:
- input_boolean.door_keypad_4_front_switch
- input_boolean.code_4_notify
door_keypad_5_delete:
alias: Delete Door Code 5
sequence:
- service: input_text.set_value
data:
value: 'Name Here'
entity_id: input_text.door_keypad_5_name
- service: input_text.set_value
data:
value: 'Code Here'
entity_id: input_text.door_keypad_5_code
- service: input_select.select_option
data:
option: 'Disabled'
entity_id: input_select.door_keypad_5_slot_state
- service: input_boolean.turn_off
entity_id:
- input_boolean.door_keypad_5_front_switch
- input_boolean.code_5_notify
door_keypad_6_delete:
alias: Delete Door Code 6
sequence:
- service: input_text.set_value
data:
value: 'Name Here'
entity_id: input_text.door_keypad_6_name
- service: input_text.set_value
data:
value: 'Code Here'
entity_id: input_text.door_keypad_6_code
- service: input_select.select_option
data:
option: 'Disabled'
entity_id: input_select.door_keypad_6_slot_state
- service: input_boolean.turn_off
entity_id:
- input_boolean.door_keypad_6_front_switch
- input_boolean.code_6_notify
door_keypad_7_delete:
alias: Delete Door Code 7
sequence:
- service: input_text.set_value
data:
value: 'Name Here'
entity_id: input_text.door_keypad_7_name
- service: input_text.set_value
data:
value: 'Code Here'
entity_id: input_text.door_keypad_7_code
- service: input_select.select_option
data:
option: 'Disabled'
entity_id: input_select.door_keypad_7_slot_state
- service: input_boolean.turn_off
entity_id:
- input_boolean.door_keypad_7_front_switch
- input_boolean.code_7_notify
door_keypad_8_delete:
alias: Delete Door Code 8
sequence:
- service: input_text.set_value
data:
value: 'Name Here'
entity_id: input_text.door_keypad_8_name
- service: input_text.set_value
data:
value: 'Code Here'
entity_id: input_text.door_keypad_8_code
- service: input_select.select_option
data:
option: 'Disabled'
entity_id: input_select.door_keypad_8_slot_state
- service: input_boolean.turn_off
entity_id:
- input_boolean.door_keypad_8_front_switch
- input_boolean.code_8_notify
door_keypad_9_delete:
alias: Delete Door Code 9
sequence:
- service: input_text.set_value
data:
value: 'Name Here'
entity_id: input_text.door_keypad_9_name
- service: input_text.set_value
data:
value: 'Code Here'
entity_id: input_text.door_keypad_9_code
- service: input_select.select_option
data:
option: 'Disabled'
entity_id: input_select.door_keypad_9_slot_state
- service: input_boolean.turn_off
entity_id:
- input_boolean.door_keypad_9_front_switch
- input_boolean.code_9_notify
door_keypad_10_delete:
alias: Delete Door Code 10
sequence:
- service: input_text.set_value
data:
value: 'Name Here'
entity_id: input_text.door_keypad_10_name
- service: input_text.set_value
data:
value: 'Code Here'
entity_id: input_text.door_keypad_10_code
- service: input_select.select_option
data:
option: 'Disabled'
entity_id: input_select.door_keypad_10_slot_state
- service: input_boolean.turn_off
entity_id:
- input_boolean.door_keypad_10_front_switch
- input_boolean.code_10_notify
door_keypad_11_delete:
alias: Delete Door Code 11
sequence:
- service: input_text.set_value
data:
value: 'Name Here'
entity_id: input_text.door_keypad_11_name
- service: input_text.set_value
data:
value: 'Code Here'
entity_id: input_text.door_keypad_11_code
- service: input_select.select_option
data:
option: 'Disabled'
entity_id: input_select.door_keypad_11_slot_state
- service: input_boolean.turn_off
entity_id:
- input_boolean.door_keypad_11_front_switch
- input_boolean.code_11_notify
door_keypad_12_delete:
alias: Delete Door Code 12
sequence:
- service: input_text.set_value
data:
value: 'Name Here'
entity_id: input_text.door_keypad_12_name
- service: input_text.set_value
data:
value: 'Code Here'
entity_id: input_text.door_keypad_12_code
- service: input_select.select_option
data:
option: 'Disabled'
entity_id: input_select.door_keypad_12_slot_state
- service: input_boolean.turn_off
entity_id:
- input_boolean.door_keypad_12_front_switch
- input_boolean.code_12_notify
door_keypad_13_delete:
alias: Delete Door Code 13
sequence:
- service: input_text.set_value
data:
value: 'Name Here'
entity_id: input_text.door_keypad_13_name
- service: input_text.set_value
data:
value: 'Code Here'
entity_id: input_text.door_keypad_13_code
- service: input_select.select_option
data:
option: 'Disabled'
entity_id: input_select.door_keypad_13_slot_state
- service: input_boolean.turn_off
entity_id:
- input_boolean.door_keypad_13_front_switch
- input_boolean.code_13_notify
door_keypad_14_delete:
alias: Delete Door Code 14
sequence:
- service: input_text.set_value
data:
value: 'Name Here'
entity_id: input_text.door_keypad_14_name
- service: input_text.set_value
data:
value: 'Code Here'
entity_id: input_text.door_keypad_14_code
- service: input_select.select_option
data:
option: 'Disabled'
entity_id: input_select.door_keypad_14_slot_state
- service: input_boolean.turn_off
entity_id:
- input_boolean.door_keypad_14_front_switch
- input_boolean.code_14_notify
door_keypad_15_delete:
alias: Delete Door Code 15
sequence:
- service: input_text.set_value
data:
value: 'Name Here'
entity_id: input_text.door_keypad_15_name
- service: input_text.set_value
data:
value: 'Code Here'
entity_id: input_text.door_keypad_15_code
- service: input_select.select_option
data:
option: 'Disabled'
entity_id: input_select.door_keypad_15_slot_state
- service: input_boolean.turn_off
entity_id:
- input_boolean.door_keypad_15_front_switch
- input_boolean.code_15_notify
I’m also not building out a lovelace for everyone. I think getting to know lovelace and customize it how you want is a bit part of HA. Here is a single, super simple lovelace for a single slot.
type: entities
title: Code Slot One
entities:
- entity: input_text.door_keypad_1_name
- entity: input_text.door_keypad_1_code
- entity: input_boolean.code_1_notify
- entity: input_boolean.door_keypad_1_front_switch
- entity: script.door_keypad_1_delete
repeat for all 15 slots if you wish, or create your own how you want.