Created
December 30, 2025 14:10
-
-
Save Ruben-Schadron/f9ded18e105fb38d7d9f0b7e38a34f9f to your computer and use it in GitHub Desktop.
Read a badge from the wiegand scanner that came in using esphome
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| blueprint: | |
| name: "Badge reader" | |
| description: "Triggers when the specified Wiegand device UID sensors detect their corresponding UIDs within the specified date range." | |
| domain: automation | |
| input: | |
| sensor_wiegand_uids: | |
| name: Wiegand Device UID Sensors | |
| description: "List of Wiegand device UID sensors that trigger the automation." | |
| selector: | |
| entity: | |
| multiple: true | |
| filter: | |
| domain: sensor | |
| required_uids: | |
| name: Required UIDs | |
| description: "List of specific UIDs that must be detected by the sensors to trigger the automation (comma-separated)." | |
| selector: | |
| text: {} | |
| user_names: | |
| name: User Names | |
| description: "List of user names corresponding to the UIDs (comma-separated)." | |
| selector: | |
| text: {} | |
| start_date: | |
| name: Start Date | |
| description: "The beginning date of the valid range for triggering." | |
| selector: | |
| date: {} | |
| end_date: | |
| name: End Date | |
| description: "The ending date of the valid range for triggering." | |
| selector: | |
| date: {} | |
| trigger: | |
| - trigger: state | |
| entity_id: !input sensor_wiegand_uids | |
| variables: | |
| start_date: !input start_date | |
| end_date: !input end_date | |
| required_uids: !input required_uids | |
| user_names: !input user_names | |
| sensor_name: "{{ trigger.entity_id.split('.')[1] }}" | |
| led_entity: "switch.{{ sensor_name.replace('_uid', '_led') }}" | |
| buzzer: "switch.{{ sensor_name.replace('_uid', '_buzzer') }}" | |
| lock: "switch.{{ sensor_name.replace('_uid', '_slot') }}" | |
| conditions: | |
| - condition: template | |
| value_template: > | |
| {% set start = strptime(start_date, '%Y-%m-%d').date() %} | |
| {% set end = strptime(end_date, '%Y-%m-%d').date() %} | |
| {{ start <= now().date() <= end }} | |
| actions: | |
| # debug | |
| # - action: persistent_notification.create | |
| # data: | |
| # message: "test1: {{ trigger.to_state.state in required_uids }}, test2: {{ trigger.to_state.state not in required_uids }}\n ids: {{required_uids}}\n state (from and to): {{ trigger.from_state.state }}, {{ trigger.to_state.state }} ;-)" | |
| - choose: | |
| - conditions: | |
| - condition: template | |
| value_template: "{{ trigger.to_state.state in required_uids }}" | |
| sequence: | |
| - action: persistent_notification.create | |
| data: | |
| title: "Authorized Badge Detected" | |
| message: > | |
| The badge for user {{ user_names }} has been detected with UID {{ trigger.to_state.state }} on reader {{ sensor_name }} within the date range. | |
| - action: switch.turn_on | |
| target: | |
| entity_id: | |
| - "{{ led_entity }}" | |
| - "{{ buzzer }}" | |
| - "{{ lock }}" | |
| - delay: "00:00:00.5" | |
| - action: switch.turn_off | |
| target: | |
| entity_id: "{{ buzzer }}" | |
| - delay: "00:00:02" | |
| - action: switch.turn_off | |
| target: | |
| entity_id: | |
| - "{{ led_entity }}" | |
| - "{{ lock }}" | |
| - conditions: | |
| - condition: template | |
| value_template: "{{ trigger.to_state.state not in required_uids }}" | |
| sequence: | |
| - action: persistent_notification.create | |
| data: | |
| title: "Unrecognized Badge Detected" | |
| message: "An unrecognized UID {{ trigger.to_state.state }} was detected on reader {{ sensor_name }}." | |
| - action: switch.turn_on | |
| target: | |
| entity_id: "{{ buzzer }}" | |
| - delay: "00:00:03" | |
| - action: switch.turn_off | |
| target: | |
| entity_id: "{{ buzzer }}" | |
| default: | |
| - action: persistent_notification.create | |
| data: | |
| title: "badge error" | |
| message: "Something went wrong when reading from reader {{ sensor_name }}." | |
| mode: single |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment