[solved] PN532 NFC: 1 tag = OK, how to add 2nd?

I’m trying to add a 2nd mifare key to my config but cannot get it right.
This is what I have:

pn532_i2c:
  update_interval: 0.3s
  on_tag:
    then:
      - text_sensor.template.publish:
          id: badge_recognized
          state: !lambda 'return x;'
      - if:
          condition:
            text_sensor.state:
              id: badge_recognized
              state: 'XX-XX-XX-XX'
          then:
            - script.execute: person_1_detected
      - if:
          condition:
            text_sensor.state:
              id: badge2_recognized
              state: 'YY-YY-YY-YY'
          then:
            - script.execute: person_2_detected
script:
  - id: person_1_detected
    mode: single
    then:
      - text_sensor.template.publish:
          id: person_detected
          state: !lambda 'return "Nick";'
      - delay: 400ms
      - text_sensor.template.publish:
          id: person_detected
          state: !lambda 'return "Clear";'
  - id: person_2_detected
    mode: single
    then:
      - text_sensor.template.publish:
          id: person2_detected
          state: !lambda 'return "Badge2";'
      - delay: 400ms
      - text_sensor.template.publish:
          id: person2_detected
          state: !lambda 'return "Clear";'  

Thanks for any help!

I realize this is not the same reader but that does not matter.

If you set up binary sensors as the code block below in this link them you can trigger on them being on.

Edit

I see now the pn532 had the same code block in that page

Hi, thanks for dropping by!

I did see those pages you are linking to (and many others)
It’s just that my first block of code doesn’t seem to correct and I have no clue what it has to be.

This works fine for 1 key

pn532_i2c:
  update_interval: 0.3s
  on_tag:
    then:
      - text_sensor.template.publish:
          id: badge_recognized
          state: !lambda 'return x;'
      - if:
          condition:
            text_sensor.state:
              id: badge_recognized
              state: 'XX-XX-XX-XX'
          then:
            - script.execute: person_1_detected

I added this part:

      - if:
          condition:
            text_sensor.state:
              id: badge2_recognized
              state: 'YY-YY-YY-YY'
          then:
            - script.execute: person_2_detected

But apparently it doesn’t work that way so I’m looking how to add the ability to scan/recognize another tag.

As I said use the binary sensors.

binary_sensor:
  - platform: pn532
    uid: 74-10-37-94
    name: "PN532 NFC Tag"
    on_state:
      then:
.....

If you want to use the on_tag then set up the binary sensors and add a condition in on_tag if the binary sensor is true

1 Like

At first, I had no clue how to use it…
This ESPHome stuff & programming is new to me + English is not my native language which makes it’s harder to really understand that info.
Just gave it a try, somehow ‘guessed’ what had to be added and succeeded! :sparkler:

Thanks for pointing me in that direction! :+1:

1 Like

Great!

I didn’t know you were that new to ESP-Home, if I had known then I would have started up the computer to give you a more proper answer.
But great that you got it working

1 Like

No problem, don’t sweat it!

You helped me to make it work: that’s the most important.
Of course when you (I in this case) don’t know how to use the info that is available, it’s a little frustrating and it’s not a big deal to go through this, keep calm, and persist.

What is very typical: when it works, I often have this ‘that wasn’t so hard, right’…