Just to contribute with something quite easy, but useful (at least for me).
It’s a single use code. Meaning it gets cleared after a single use.
Considering you installed the custom Lovelace text input row* mentioned by @jkuntz805:
Create an input text for your single use code
Input Text - Single Use Code
In your configuration.yaml, add this input_text.
input_text:
##Input do código temporário da porta
singleusecode:
name: Single Use Code
initial: 0000
Create a script that sets the user code and notifies you
Script - Set new lock code and notify
Important: I’m using codeslot 100, since I probably won’t create 100 codes in this lifetime. Which also means in this workflow, only 1 single use code is possible. Please check your lock max number of codes to see if 100 is usable.
alias: Add Single Use Code
sequence:
- service: zha.set_lock_user_code
target:
#Easiest way to locate your device ID is through the Call Service on Developer Tools, selecting zha.set_lock_user_code, selecting your device and checking the YAML editor
device_id: yourDeviceID
data:
code_slot: '100'
user_code: '{{ states(''input_text.singleusecode'') | int }}'
- service: notify.your_phone_goes_here
data:
message: Um código de uso único foi criado.
title: Novo código - Porta da Frente
data:
#This part is only valid for Android devices. For some reason, I need this or the notification won't show unless I unlock my phone. This sets the notification priority as urgent. In case you need it, check documentation for iOS settings on priority.
ttl: 0
priority: high
mode: single
icon: mdi:key-plus
Create a card to input your single use code and run the script
Lovelace Card
You can place this in a lovelace card, editing it in YAML mode.
type: vertical-stack
cards:
- type: entities
header:
image: https://www.ryadel.com/wp-content/uploads/2017/11/IT-Security.jpg
type: picture
show_header_toggle: false
entities:
- type: custom:text-input-row
entity: input_text.singleusecode
- entity: script.add_single_use_code
icon: mdi:key-plus
Create an automation that deletes the code when used and notifies you
Automation to delete used code and send notification
This was created for a Yale YRD256 lock with Zigbee. It’s probably the same for a few other Yale Locks with Zigbee. For your lock, you might want to check which args you should use to detect Unlocking on the trigger and the code slot args to use on the condition. You can check this by listening to zha_event on Developer Tools and unlocking your door through the keypad to check for the event info.
alias: Fechadura - Deleta Single Use Code
trigger:
- platform: event
event_type: zha_event
event_data:
#You can find the device_ieee on your Zigbee integration.
device_ieee: 00:00:00:00:00:00:00:00
args:
operation: Unlock
condition:
- condition: template
value_template: '{{ trigger.event.data.args.code_slot == 100 }}'
action:
- service: zha.clear_lock_user_code
target:
device_id: yourDeviceID
data:
code_slot: '100'
- service: notify.your_phone_goes_here
data:
title: Porta da Frente
message: Código de Uso Único foi utilizado e apagado.
data:
ttl: 0
priority: high
mode: single
That’s it. I made a few comments along the way to help people that - like me - are noobs.
Hope someone finds it helpful.
** btw if you didn’t install the custom elements, easiest way is through HACS. It’s available there.