Need help with change NFC tags and reader Pn532

So, I made a simple alarm. I used examples from the help. And also fragments from this forum.
The system receives the tag value and if it is correct then the security is disabled.
The task is to be able to change the tag to a new one if necessary. And disable the old one in case of its loss or theft.
How to do this without reflashing?
Here is a basic example of code-

# Example configuration entry
spi:
  clk_pin: GPIO1
  miso_pin: GPIO0
  mosi_pin: GPIO4

pn532_spi:
  cs_pin: GPIO5
  on_tag:
    then:
      - homeassistant.tag_scanned: !lambda 'return x;'
      - if:
          condition:
            or:
            - binary_sensor.is_on: tag1
            - binary_sensor.is_on: tag2
          then: #this is where you would code your actions
            - logger.log: "Valid NFC tag detected" 
            - rtttl.play: 'long:d=1,o=4,b=60:e4'
            - switch.turn_on: door 
          else:
            - logger.log: "Invalid NFC tag detected" 
            - rtttl.play: 'long:d=4,o=5,b=200:a,32p,a,32p,a'

switch:
  - platform: gpio
    pin: GPIO7
    name: "door" 
    id: door
    icon: "mdi:gate"
    on_turn_on:
        - delay: 5s
        - switch.turn_off: door

# PIEZO buzzer
output:
  - platform: ledc
    pin: GPIO10
    id: rtttl_out

rtttl:
  output: rtttl_out

binary_sensor:
  - platform: pn532
    uid: 7A-4F-27-15
    id: tag1
  - platform: pn532
    uid: 7B-36-DE-19
    id: tag2

Here in the binary sensor block specific IDs are specified.
I need to be able to change or add a label from HA.
I tried to use the number component, the text sensor, and finally the lambda call. But without success.
When trying to use lambda in the binary sensor component, the PN532 platform writes that this component does not support lambda calls.
Is it really impossible to solve such an important task using esphome?

if HA can be involved you have at lest 2 options:

  1. Send tag UID to HA and turn_on door with HA automation
  2. use text component to expose a text field to HA and set UID there in HA. During tag_scanned automation compare UID with the one read from HA

Without HA? Maybe with mqtt? Write the UID on mqtt topic that you can read from esphome doruing startup? Save it to some text field and same as 2.

Thank you for your recommendations. The thing is that this is a simple block of the security system. And here autonomy is important to increase reliability. HA provides additional functionality, but it should not be a mandatory component. There may be an update, configuration adjustment, reboot, etc. at an inopportune moment.

Therefore, let’s move on to point 2.
Yes, it is possible to use a text sensor.
But how to use the received value in the UID field?
Lambda does not work there, the compiler reports that the sensor platform does not support lambda.

Here’s what the automation fragment looks like.
You can set actions when the sensor is triggered, but I haven’t found a single way to replace the sensor itself without reflashing.

binary_sensor:
  - platform: pn532
    uid: 04-DE-02-4A-28-67-84
    name: "PN532 UID Detected"
    on_press:
      then:
        - lambda: |-
            if (id(security_mode) == 2) {
              id(security_mode) = 0;
              id(siren).turn_off();

the thing is, this UID tag can be easily copied so this is not a secure setup. If you want to make it secure, put dumb passive tag on the wall so anybody can scan it to get the UID. And only your phone after scanning this particular UID will run HAss action to open the door. This can be done with Shortcuts on iOS and probably some other way on Android.

But if you insist, set the text template sensor in esphome. Fill it in HA. Move the automation to on_tag lambda. Use condition to check if scanned tag equals UID set in HA.
That would be something like

- if:
    condition:
      lambda: 'return id(text_sensor_id).state == x ;'
    then: #this is where you would code your actions
      - logger.log: "Valid NFC tag detected" 
      - rtttl.play: 'long:d=1,o=4,b=60:e4'
      - switch.turn_on: door 
    else:
      - logger.log: "Invalid NFC tag detected" 
      - rtttl.play: 'long:d=4,o=5,b=200:a,32p,a,32p,a'