IoT & AutomationHome Assistant
Card and PIN: an access automation in Home Assistant
Step by step: one automation that checks the card, waits for the PIN and gives the reader a green or red signal.
2 min read

The bridge reports every card and every PIN result over MQTT. One automation checks the card, waits up to 15 seconds for the correct PIN, opens the lock and gives the reader a green or red signal.
A card alone can be lost or passed on. A PIN alone can be watched over someone’s shoulder. Together they are a second factor: the door opens only for someone who has the card and knows the code. This guide builds exactly that.
What you need
- a KLOKL Bridge with an OSDP reader that has a keypad
- Home Assistant with an MQTT broker, for example the Mosquitto add-on
- a lock or relay that Home Assistant can switch
The topics involved
Every topic starts with the device ID of your bridge. You find it in the web interface of the bridge and in Home Assistant under the device. In this example it is osdp-reader-3f9a12.
…/card_data: number of the card that was read…/pin_status: “Code akzeptiert” or “Code nicht akzeptiert” after the user presses #…/cmd/feedback_ok: green LED and beeper on the reader…/cmd/feedback_denied: red signal on the reader
Step 1: set the code
The bridge compares the PIN itself, so the code never travels over the network when someone types it. Set the code once: in Home Assistant the bridge appears with a text field “Access Code”; enter the code there. Alternatively publish it to …/cmd/access_code.
Step 2: the automation
Create a new automation, switch to YAML mode and paste the following. Replace the device ID, the card numbers and the lock entity with your own.
1alias: Front door: card and PIN2mode: single3triggers:4 - trigger: mqtt5 topic: osdp-reader-3f9a12/card_data6conditions:7 - condition: template8 value_template: "{{ trigger.payload in ['0004958372', '0004958373'] }}"9actions:10 - wait_for_trigger:11 - trigger: mqtt12 topic: osdp-reader-3f9a12/pin_status13 payload: "Code akzeptiert"14 timeout: "00:00:15"15 continue_on_timeout: true16 - if:17 - condition: template18 value_template: "{{ wait.trigger is not none }}"19 then:20 - action: lock.unlock21 target:22 entity_id: lock.front_door23 - action: mqtt.publish24 data:25 topic: osdp-reader-3f9a12/cmd/feedback_ok26 payload: ""27 else:28 - action: mqtt.publish29 data:30 topic: osdp-reader-3f9a12/cmd/feedback_denied31 payload: ""
What happens
- A card is held to the reader. If its number is not on the list, nothing happens.
- For a known card the automation waits up to 15 seconds for “Code akzeptiert”.
- Correct PIN in time: the lock opens and the reader shows green.
- Wrong PIN or too late: the reader shows red and the door stays closed.
Tips for everyday use
- Find card numbers by holding each card to the reader once and reading the sensor “Card Data” in Home Assistant.
- Keep the list of allowed cards in one place, for example in a template sensor or a helper, if several automations use it.
- For a card-only entrance, leave out the waiting step and unlock directly.
- Add a notification on “Code nicht akzeptiert” if you want to know about failed attempts.
Wiring and first start are described in the documentation. Why the bridge uses OSDP at all: OSDP instead of Wiegand.

Local first: why a door should not depend on the internet
Cloud services come and go, the door stays. Why the KLOKL Bridge works entirely in your own network, and what you still need to plan for.
2 min read

Why the bridge speaks OSDP, not Wiegand
Many card readers still use Wiegand, an interface from the 1980s. For the KLOKL Bridge we chose OSDP: supervised, bidirectional and able to encrypt.
2 min read

IoT & AutomationHome Assistant
Encrypting MQTT: TLS for the Mosquitto broker in Home Assistant
Step by step: enable TLS in the Mosquitto add-on and connect the KLOKL Bridge over MQTTS on port 8883. With an honest look at what it protects against.
2 min read
News about the KLOKL Bridge
New posts, firmware updates and the launch date, straight to your inbox.