This one frontdoor_lock_manager_common.yaml?
## WARNING ##
# This file is auotmaticly generated, any changes
# will be overwritten.
##################################################
################ COMMON ENTITIES ###############
##################################################
############### input_boolean: #################
input_boolean:
frontdoor_lock_notifications:
name: "Lock Notifications"
frontdoor_dooraccess_notifications:
name: "Door Notifications"
frontdoor_garageacess_notifications:
name: "Garage Notifications"
frontdoor_reset_lock:
name: "frontdoor reset lock"
################### sensor: ####################
sensor:
- platform: time_date
display_options:
- 'time'
- 'date'
- 'date_time'
- 'date_time_iso'
- 'time_date'
- 'time_utc'
- 'beat'
- platform: template
sensors:
frontdoor_statusreport:
friendly_name: 'frontdoor Status Report'
value_template: >
{% set UC = 'sensor.schlage_allegion_be469_touchscreen_deadbolt_alarm_level_frontdoor' %}
{% set AC = 'sensor.schlage_allegion_be469_touchscreen_deadbolt_access_control_frontdoor' %}
{% if (((as_timestamp(now()) - as_timestamp(states.UC.last_changed)) < 15) and ((as_timestamp(now()) - as_timestamp(states.AC.last_changed)) < 15)) %}
{% set usercode_value = states(UC) %}
{% set alarm_type_value = states(AC) %}
{% if 'alarm_type' in AC %}
{% 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' } %}
{% elif 'access_control' in AC %}
{% set alarm_type_general_actions = {
'1':'Manual Lock',
'2':'Manual Unlock',
'3':'RF Lock',
'4':'RF Unlock',
'7':'Manual not fully locked',
'8':'RF not fully locked',
'9':'Auto Lock locked',
'10':'Auto Lock not fully locked',
'11':'Lock Jammed',
'16':'Keypad temporary disabled',
'17':'Keypad busy' } %}
{% set alarm_type_lock_actions = {
'5':'Keypad Lock',
'6':'Keypad Unlock' } %}
{% set alarm_type_code_actions = {
'12':'All User Codes Deleted',
'13':'Single Code Deleted',
'14':'New User Code Added',
'15':'Duplicate Code' } %}
{% endif %}
{% if alarm_type_value in alarm_type_code_actions %}
{{alarm_type_value}};{{ alarm_type_code_actions[alarm_type_value] }};{{usercode_value}}
{% elif alarm_type_value in alarm_type_lock_actions %}
{{alarm_type_value}};{{ alarm_type_lock_actions[alarm_type_value] }};{{usercode_value}}
{% elif alarm_type_value in alarm_type_general_actions %}
{{alarm_type_value}};{{ alarm_type_general_actions[alarm_type_value] }}
{% else %}
{{-1}};Unknown Alarm Type Value {{ states(AC) }}
{% endif %}
{% else %}
{% endif %}
################### script : ####################
script:
frontdoor_reset_lock:
sequence:
- service: script.frontdoor_manual_notify
data_template:
title: "reset"
message: "frontdoor"
frontdoor_conditional_notify:
sequence:
- condition: template
value_template: >-
{% set inputbool = boolean %}
{% if states(inputbool) == 'on'%}
true
{% else %}
false
{% endif %}
- service: script.frontdoor_manual_notify
data_template:
title: "{{title}}"
message: "{{message}}"
################### automation: ####################
automation:
- alias: frontdoor Notifications
trigger:
platform: state
entity_id: sensor.frontdoor_statusreport
condition:
- condition: state
entity_id: 'binary_sensor.allow_automation'
state: 'on'
- condition: template
value_template: >-
{% set report = states.sensor.frontdoor_statusreport.state %}
{% set a = report.split(';') %}
{% if (a|length) != 3 or (a[2] == "0") %}
{{ true }}
{% else %}
{{ true }}
{% endif %}
action:
- service: script.frontdoor_conditional_notify
data_template:
boolean: input_boolean.frontdoor_lock_notifications
title: "Sensor Status Report"
message: >-
{% set report = states.sensor.frontdoor_statusreport.state %}
{% set a = report.split(';') %}
{% set msg = "ID:" + a[0] + " MSG:" + a[1] %}
{% if (a|length) == 3 %}
{% set msg = msg + " SLOT:" + a[2] %}
{% endif %}
{{ a[1] }}
- alias: frontdoor User Notifications
trigger:
platform: state
entity_id: sensor.frontdoor_statusreport
condition:
- condition: state
entity_id: 'binary_sensor.allow_automation'
state: 'on'
- condition: template
value_template: >-
{% set report = states.sensor.frontdoor_statusreport.state %}
{% set a = report.split(';') %}
{% if (a|length) == 3 and (a[2] | int > 0) %}
{{ true }}
{% else %}
{{ false }}
{% endif %}
- condition: template
value_template: >-
{% set report = states.sensor.frontdoor_statusreport.state %}
{% set a = report.split(';') %}
{% set entity_id = 'notify_frontdoor_' + a[2] %}
{% set notify = states['input_boolean'][entity_id].state %}
{{ notify == "on" }}
action:
- service: script.frontdoor_manual_notify
data_template:
title: >-
{% set report = states.sensor.frontdoor_statusreport.state %}
{% set a = report.split(';') %}
{{ a[1] }}
message: >-
{% set report = states.sensor.frontdoor_statusreport.state %}
{% set a = report.split(';') %}
{% set entity_id = 'input_text.frontdoor_name_' + a[2] %}
{% set user = states(entity_id) %}
{{ user }}
###############################
- alias: frontdoor Sensor Close
condition:
- condition: state
entity_id: 'binary_sensor.allow_automation'
state: 'on'
trigger:
entity_id: binary_sensor.frontdoor
platform: state
to: 'off'
action:
- service: script.frontdoor_conditional_notify
data_template:
boolean: input_boolean.frontdoor_dooraccess_notifications
title: "frontdoor"
message: "Closed"
- alias: frontdoor Sensor Opened
condition:
- condition: state
entity_id: 'binary_sensor.allow_automation'
state: 'on'
trigger:
entity_id: binary_sensor.frontdoor
platform: state
to: 'on'
action:
- service: script.frontdoor_conditional_notify
data_template:
boolean: input_boolean.frontdoor_dooraccess_notifications
title: "frontdoor"
message: "Opened"
- alias: frontdoor Add Code
condition:
- condition: state
entity_id: 'binary_sensor.allow_automation'
state: 'on'
trigger:
entity_id: binary_sensor.active_frontdoor_1,binary_sensor.active_frontdoor_2,binary_sensor.active_frontdoor_3,binary_sensor.active_frontdoor_4,binary_sensor.active_frontdoor_5
platform: state
to: 'on'
action:
- service: lock.set_usercode
data_template:
node_id: >-
{{states.lock.lock.schlage_frontdoor.attributes.node_id}}
code_slot: >-
{% set object_id = trigger.to_state.object_id %}
{% set index = object_id.rfind('_') + 1 %}
{% set code_slot = object_id[index:] %}
{{ code_slot }}
usercode: >-
{% set object_id = trigger.to_state.object_id %}
{% set index = object_id.rfind('_') + 1 %}
{% set code_slot = object_id[index:] %}
{% set codetext = 'frontdoor_pin_' + code_slot | string %}
{% set code = states['input_text'][codetext].state %}
{{ code | string }}
- alias: frontdoor Update Code
trigger:
entity_id: input_text.frontdoor_pin_1,input_text.frontdoor_pin_2,input_text.frontdoor_pin_3,input_text.frontdoor_pin_4,input_text.frontdoor_pin_5
platform: state
condition:
- condition: state
entity_id: 'binary_sensor.allow_automation'
state: 'on'
- condition: template
value_template: >-
{% set object_id = trigger.to_state.object_id %}
{% set index = object_id.rfind('_') + 1 %}
{% set code_slot = object_id[index:] %}
{% set b = 'input_boolean.enabled_frontdoor_' + code_slot | string %}
{{ is_state(b, 'on') and (trigger.from_state.state != trigger.to_state.state)}}
action:
- service: persistent_notification.create
data_template:
title: "frontdoor LOCK MANAGER"
message: >-
{% set object_id = trigger.to_state.object_id %}
{% set index = object_id.rfind('_') + 1 %}
{% set code_slot = object_id[index:] %}
{{ 'You changed the PIN for code ' + code_slot | string + '. Please enable it in order to make it active.'}}
- service: input_boolean.turn_off
data_template:
entity_id: >-
{% set object_id = trigger.to_state.object_id %}
{% set index = object_id.rfind('_') + 1 %}
{% set code_slot = object_id[index:] %}
{{ 'input_boolean.enabled_frontdoor_' + code_slot | string }}
- alias: Reset frontdoor
condition:
- condition: state
entity_id: 'binary_sensor.allow_automation'
state: 'on'
trigger:
entity_id: input_boolean.frontdoor_reset_lock
platform: state
from: 'off'
to: 'on'
action:
- service: script.frontdoor_reset_lock
- service: input_boolean.turn_off
entity_id: input_boolean.frontdoor_reset_lock
- alias: frontdoor Clear Code
condition:
- condition: state
entity_id: 'binary_sensor.allow_automation'
state: 'on'
trigger:
entity_id: binary_sensor.active_frontdoor_1,binary_sensor.active_frontdoor_2,binary_sensor.active_frontdoor_3,binary_sensor.active_frontdoor_4,binary_sensor.active_frontdoor_5
platform: state
to: 'off'
action:
- service: lock.set_usercode
data_template:
node_id: >-
{{states.lock.lock.schlage_frontdoor.attributes.node_id}}
code_slot: >-
{% set object_id = trigger.to_state.object_id %}
{% set index = object_id.rfind('_') + 1 %}
{% set code_slot = object_id[index:] %}
{{ code_slot }}
usercode: >-
{{ range(1000, 9999) | random | int }}
- alias: frontdoor Decrement Access Count
trigger:
platform: state
entity_id: sensor.frontdoor_statusreport
condition:
- condition: state
entity_id: 'binary_sensor.allow_automation'
state: 'on'
- condition: template
# Check for Keypad Unlock code
value_template: >-
{% set report = states.sensor.frontdoor_statusreport.state %}
{% set a = report.split(';') %}
{% if (a|length) == 3 and (a[2] | int > 0) %}
{{ (a[0] | int == 19) or (a[0] | int == 6) }}
{% else %}
{{ false }}
{% endif %}
action:
- service: input_number.decrement
data_template:
entity_id: >-
{% set report = states.sensor.frontdoor_statusreport.state %}
{% set a = report.split(';') %}
{{ 'input_number.accesscount_frontdoor_' + a[2] }}