Wiegand RFID scanner notify HA of scanned badge instead of only the last code

Hi all! I finally got my wiegand reader working in ESP Home with this code: GitHub - dancwilliams/esphome-wiegand: Simple ESPHome Wiegand custom component

I can read the scanned code in home assistant.

But I’m now trying to make an automation to open the door if the correct code is scanned. It’s all working fine unless I scan the same badge twice.
For example: i want to enter the house and scan my RFID badge. Then leave and a few minutes later I scan the same badge to re-enter. The scanned code (sensor.card_id) doesn’t change so I can’t detect it to open the door.
If I first scan another badge, and then my own badge again, it gets detected ofcourse.

This is my code:

text_sensor:
- platform: custom
  lambda: |-
    auto wiegand = new WiegandReader(D1, D2);
    App.register_component(wiegand);
    return {wiegand};
  text_sensors:
    name: "Card ID"
    on_value:
      then:
        - homeassistant.tag_scanned: !lambda |-
            return x; 

So in home assistant I can read the scanned code in sensor.card_id.
But I also need something to detect WHEN a badge is scanned…
Does anyone know what to add in the ESPHome code to notify HA that a badge was scanned.

I prefer to have something like this:
I scan the code. I handle it, somehow send feedback to ESPHome that I received the code correctly so ESPHome can set sensor.card_id back to “0000” for example.

Or can I overwrite the sensor value from home assistant somehow?

I’m open for other ideas!

Thanks in advance!

What about adding a delay followed by another tag_scanned event:

text_sensor:
- platform: custom
  lambda: |-
    auto wiegand = new WiegandReader(D1, D2);
    App.register_component(wiegand);
    return {wiegand};
  text_sensors:
    name: "Card ID"
    on_value:
      then:
        - homeassistant.tag_scanned: !lambda |-
            return x;
        - delay: 60s 
        - homeassistant.tag_scanned: '0000'

It didn’t work… The value remains the same…