I was trying to come up with some useful abstracted views to how my z-wave lock works, and am currently giving this a spin. I’m using a Schlage BE469NXCEN Touchscreen DeadBolt lock and have been very pleased with it so far.
The battery level thing is something that’s been floating around a bit… Since a recent change to HASS about events not firing upon attribute change (vs. state change), I’m not sure how “reliable” this might be. It probably will only get updated when the lock changes state from locked to unlocked or similar. This might be close enough…
sensor frontdoorlock:
- platform: template
sensors:
frontdoorbattery:
# entity_id: zwave.front_door_lock_2
entity_id: zwave.front_door_lock
value_template: "{{ states.zwave.front_door_lock.attributes.battery_level }}"
friendly_name: 'Front Door Lock Battery'
unit_of_measurement: '%'
This bit is intended to capture the last user code used to operate the lock. While my lock is configured to only use an entered code to unlock (19), it also covers the case of a code that was used secure the lock (18).
# this sensor is intended to capture the user number that was used during
# the last operation that required a code to be entered. it will persist
# after subsequent other events (manual locking, etc.) that didn't involve
# a user code
front_door_code:
friendly_name: Front Door Last Code
entity_id:
- sensor.front_door_lock_alarm_type
- sensor.front_door_lock_alarm_level
value_template: >-
{% if is_state('sensor.front_door_lock_alarm_type', '18') or
is_state('sensor.front_door_lock_alarm_type', '19') %}
{% if not is_state('sensor.front_door_lock_alarm_level', '0') %}
{{states('sensor.front_door_lock_alarm_level')}}
{% else %}
{# just provide previous value if no user code entered #}
{{states('sensor.front_door_code')}}
{% endif %}
{% else %}
{# just provide previous value if no user code entered #}
{{states('sensor.front_door_code')}}
{% endif %}
This is intended to capture a generic view on what state the lock is in, depending on what operations have been done to it.
front_last_action:
friendly_name: 'Front Door Last Action'
entity_id:
- sensor.front_door_lock_alarm_type
- sensor.front_door_lock_alarm_level
value_template: >-
{% if is_state('sensor.front_door_lock_alarm_type', '18') %}
{% if is_state('sensor.front_door_lock_alarm_level', '0') %}
Locked: Outside Keypad
{% else %}
Locked: User {{states('sensor.front_door_lock_alarm_level')}}
{% endif %}
{% elif is_state('sensor.front_door_lock_alarm_type', '19') %}
Unlocked: User Code {{states('sensor.front_door_lock_alarm_level')}}
{% elif is_state('sensor.front_door_lock_alarm_type', '21') %}
Locked: {{[ 'Outside Lock', 'Inside Deadbolt', 'Outside Keypad' ][states('sensor.front_door_lock_alarm_level')|int]}}
{% elif is_state('sensor.front_door_lock_alarm_type', '22') %}
Unlocked: Inside Deadbolt
{% else %}
Unknown: {{states('sensor.front_door_lock_alarm_type')}}/{{states('sensor.front_door_lock_alarm_level')}}
{% endif %}
I wonder at times if this shouldn’t be tweaked to reflect the current state of the lock vs. what operation was performed. My lock doesn’t report back a reason for when it was locked or unlocked via z-wave command (as compared to operating the local locally.) So you can have this funky situation where the last action was “Locked: Inside Deadbolt”, but the door might actually be unlocked due to a z-wave initiated action…
Maybe this might be a useful example for someone…