ESPHome Tag reader

Hi,
I am quite new to home assistant and I am currently trying to integrate tag readers which are outside and inside of my gate. I can trigger the gate to open.
I would like to also have a status of which “tag” is at home and which is away, but the state changes to away immediately after the tag is removed from the reader. Is there a way to use the tag reader more like a switch? If you tag at the reader outside the gate it will give me the status “home” until I tag the inside reader (to open the gate to leave the property) and then it shows away again.

that’s what I have so far in the ESPhome Editor:

on_tag:
    then:
      - homeassistant.tag_scanned: !lambda 'return x;' 
      

binary_sensor:
  - platform: rc522
    uid: XXX
    name: "Blue RFID Tag"
    
  - platform: rc522
    uid: YYY
    name: "White RFID Card"

Thank You
Dan

Is the other tag reader on a separate device? If so maybe rename the sensors:

binary_sensor:
  - platform: rc522
    uid: XXX
    name: "Blue RFID Tag In"
    id: blue_rfid_in

On the other device:

binary_sensor:
  - platform: rc522
    uid: XXX
    name: "Blue RFID Tag Out"
    id: blue_rfid_out

In HA create a template binary sensor or an automation that triggers to then control the gate. An automation is probably easier to write - I haven’t had any experience with trigger based template sensors so I’m only guessing how that will work.