Having trouble with tag scanning example code

I pretty much lifted this code from the example YAML..

This is what it is in its distilled form:

- alias: Scan Test
  id: scan_test
  mode: single
  max_exceeded: silent
  variables:
    readers:
      1d8b1234c12f3dcbbe1234a123456bf3: 1_north_door
      deadbeaf123456778abadf1322232222: 1_south_door
      987654231beefdeedc0ffee122aaaaaa: 0_lobby_door
    tags:
      1234567:
        name: curly
  trigger:
    platform: event
    event_type: tag_scanned
  condition:
    - "{{ trigger.event.data.tag_id in tags }}"
    - "{{ trigger.event.data.device_id in readers }}"
  action:
    - variables:
        full_name: "{{ tags[trigger.event.data.tag_id].name }}"
        reader_door: "{{ readers[trigger.event.data.device_id] }}"
    - service: notify.pushover
      data: 
        text: "{{ reader_door }} unlocked for 30 seconds by {{ full_name }}"

The event looks like this:

{
    "event_type": "tag_scanned",
    "data": {
        "tag_id": "1234567",
        "device_id": "deadbeaf123456778abadf1322232222"
    },
    "origin": "LOCAL",
    "time_fired": "2021-09-22T20:10:19.465266+00:00",
    "context": {
        "id": "9b3786c6320f7c4991e6df7a8d77f16b",
        "parent_id": null,
        "user_id": null
    }
}

The condition “{{ trigger.event.data.tag_id in tags }}” fails every time. I can comment that condition and it passes, and it will even barf out the proper trigger.event.data.tag_id tags variable if I let it pass. I’ve also tried to convert the decimal tag_id to hexadecimal and dashed hexadecimal as in the example, and the condition doesn’t work, although {{ trigger.event.data.device_id in readers }} passes every time.

Sometimes it just takes a night of thinking to solve a problem. This is fixed by putting the tags variables in quotes. I suppose my esphome wiegand code is sending the tag-id as a string rather than a number.

- alias: Scan Test
  id: scan_test
  mode: single
  max_exceeded: silent
  variables:
    readers:
      1d8b1234c12f3dcbbe1234a123456bf3: 1_north_door
      deadbeaf123456778abadf1322232222: 1_south_door
      987654231beefdeedc0ffee122aaaaaa: 0_lobby_door
    tags:
      "1234567":
        name: curly
  trigger:
    platform: event
    event_type: tag_scanned
  condition:
    - "{{ trigger.event.data.tag_id in tags }}"
    - "{{ trigger.event.data.device_id in readers }}"
  action:
    - variables:
        full_name: "{{ tags[trigger.event.data.tag_id].name }}"
        reader_door: "{{ readers[trigger.event.data.device_id] }}"
    - service: notify.pushover
      data: 
        text: "{{ reader_door }} unlocked for 30 seconds by {{ full_name }}"
1 Like