Help? Complex Automations with ESP Home NFC Reader

Hey! Looking for some help, tips, or just to get pointed in the right direction.

TL:DR: How can I map the random character “device_id’” of an EPSHome NFC reader in order to target individual entities that are part of one of three NFC readers?

More Info…
I am building 3 (have two built so far) of the ESP8266 and PN532 standalone NFT Tag readers @adonno made. One by the front door, one by the back door, and one in my office.

I need help figuring out a way that I can separate the automations I build from the process of identifying which tag reader was used in order to have the tone and light feedback only happen on that device. Right now I need to duplicate all of the reader’s rtttl tone and led light actions for each reader. I’m thinking I need to handle some of the automation work in scripts, templates, custom sensors, or some other things I don’t know about.

I’ll use this example to frame my questions…
I want to put NFC tags on my dog’s leashes. When we leave to take him on a walk we scan that tag at either the front door or the back door. The scan will check a toggle helper to see if he has already been on a walk today, so his second walk can be shorter. Based on that toggle, the output will be a different tone and led color which should only happen on the NFC reader I used. I also want to check which leash is being used based on which tag is scanned. The regular leash has waste bags attached to the leash, but you can’t really attach bags to the loop harness leash, so when the loop leash is being used I want to play a reminder to grab bags.

So far I have a text input helper that gets populated with the “device_id” found in the event data from scanning a tag. The problem is that it is just a random string of characters, not a friendly name matching anything in HA. Also, while the “device_id” can tell me which reader was used, I don’t know how I would map those random device_ids for each reader to the individual entities I need to target in the automations. Ultimately I want to inject the correct entities for the light on and play rtttlt services in the action.

I don’t want this post to get too long, so let me know if you have any questions I can answer to clarify what I’m trying to do. Thanks!

I think your issue is going to be that entity ids aren’t templatable. There has bee discussions around how to do it and I haven’t really seen anyone successful.

Your best bet would be to pass the reader id to a script and use multiple conditions to turn on matching light etc.

I put most of my logic/coding on ESPHOME instead of Home Assistant.
Maybe this could be useful.

esphome:
  name: espname
  friendly_name: board-m5stack

esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "jpktO*****************8"

ota:
  password: "f570779023*****************8"

wifi:
  networks:
  - ssid: "Youknow"
    password: "ineedcoffee"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Fallback Hotspot"
    password: "Onik2501***"

captive_portal:
    
# 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