Providing triggering tag as input

Hello,
I’m new to blueprints and I’m writing one that should execute some actions when a tag is scanned in my house. Since I have multiple tags, I’d like the tag to also be part of the blueprint input.

I’m trying to avoid manually typing the tag_id, rather providing a tag selector in the UI. Therefore, my input portion is:

blueprint:
  input:
    tag:
      name: "Target tag"
      selector:
        entity:
          filter:
            domain: tag

This provides the list of tags in the UI, and if I select one, the value passed to the automation is the “friendly name”, e.g. tag.over_coffee_machine. I’m having a hard time writing the trigger portion of this blueprint.

I’ve tried a couple of variations, such as directly passing this:

trigger_variables:
  tag: !input tag

trigger:
  - platform: event
    event_type: tag_scanned
    event_data:
      tag_id: "{{ tag }}"

Also tried getting the tag_id from the states attributes:

trigger_variables:
  tag: !input tag

trigger:
  - platform: event
    event_type: tag_scanned
    event_data:
      tag_id: "{{ state_attr(tag, 'tag_id') }}"

And even tried this approach:

trigger_variables:
  _tag: !input tag
  trigger_tag: "{{ state_attr(_tag, 'tag_id') }}"

trigger:
  - platform: event
    event_type: tag_scanned
    event_data:
      tag_id: "{{ trigger_tag }}"

None of these are triggering the automation when I scan the tag.
I don’t know what else to try. Any suggestions?
Thank you!

Hi tyron,

I do not believe trigger.id accepts templates. It is looking for a string because the value has to be a constant for the rest of the code to work.

If the id were variable, how would you refer to it later (not knowing what it is?)

So, as I understand, the !input tag is replaced with the actual string during the blueprint->automation conversion.

The problem is that I can’t just use that string (friendly name), so I’d also need to translate the string-to-id at the same time, during the conversion of blueprint to automation. That’s what I thought the trigger_variables would do.

That is one of the things you can do in trigger_variables, yes. However the id: key (not tag_id:) field will not accept templates because it has to be a known constant. Should be no reason to put it there in that field.
You can have a trigger_variable: statement and those variables will be available in your conditions or actions below. If not using it in the trigger, a variables: statement will also do this.

Oh crap. You are using rfid tags…

Forget what I said, I misread. I have never used those so I have no clue actually.

Sorry for the confusion.