Best way to manage tags

I was looking at the Tags doc page and noticed the code example changed:

Tag Scan Automation Example
automation:
- alias: "Handle Tag Scan"
  # Hide warnings when triggered while in delay.
  max_exceeded: silent
  variables:
    # Map scanner device ID to media player entity ID
    media_players:
      0e19cd3cf2b311ea88f469a7512c307d: media_player.spotify_balloob
    # Map tag ID to content
    tags:
      A7-6B-90-5F:
        media_content_id: spotify:album:0h2knr6qpiAq0tV5ri5JMF
        media_content_type: album
      04-B1-C6-62-2F-64-80:
        media_content_id: spotify:playlist:0OtWh3u6fZrBJTQtVBQWge
        media_content_type: playlist
  triggers:
    - trigger: event
      event_type: tag_scanned
  conditions:
    # Test that we support this device and tag
    - "{{ trigger.event.data.tag_id in tags }}"
    - "{{ trigger.event.data.device_id in media_players }}"
  actions:
    - variables:
        media_player_entity_id: "{{ media_players[trigger.event.data.device_id] }}"
        media_content_id: "{{ tags[trigger.event.data.tag_id].media_content_id }}"
        media_content_type: "{{ tags[trigger.event.data.tag_id].media_content_type }}"
    - action: media_player.play_media
      target:
        entity_id: "{{ media_player_entity_id }}"
      data:
        media_content_id: "{{ media_content_id }}"
        media_content_type: "{{ media_content_type }}"
    - delay: 2 # timeout before we allow processing next scan

This is somewhat different from what I’m doing, and I wanted to see which method is better. There are pros and cons either way.

Methods of Automating Tag Scans

Neither method requires programming and writing to the tags. While you can, I don’t know why you would since doing it all in software gives you a lot more flexibility!

Old method from docs

in the past, the Home Asisstant Tags docs had you creating an automation per tag. That simply doesn’t scale.

New method from docs

The new version fixes has a very Python-like solution which is closer to how I’d code it by hand, but it also means I lose a lot of the Home Assistant GUI:

    # Map scanner device ID to media player entity ID
    media_players:
      0e19cd3cf2b311ea88f469a7512c307d: media_player.spotify_balloob
    # Map tag ID to content
    tags:
      A7-6B-90-5F:
        media_content_id: spotify:album:0h2knr6qpiAq0tV5ri5JMF
        media_content_type: album
      04-B1-C6-62-2F-64-80:
        media_content_id: spotify:playlist:0OtWh3u6fZrBJTQtVBQWge
        media_content_type: playlist

My method

I name each tag with a string action and parse it in my automations:


The important piece is I use the Tag’s “Name” field rather than doing it all in software.

I have one automation for games and one for music, and they both use the device ID to determine which device to target.

Differences (Pros & Cons)

1. Log Visibility

Using the “Name” gives you more visibility, especially in the Activity Log:


I can still name the Tag to make logging better, but that requires duplication.

2. Dual-use cards

Using variables in an Automation means you can use the same card for multiple tasks.

For instance, the same card could play Super Mario Bros on a MiSTer and play the Super Mario Bros music album via Music Assistant when scanned on a different NFC reader.

With parsing the Tag Name, that’s a lot harder to do today. I’d need to bake more than one task into the Tag Name.

3. Simplifying Automations

With either the variables method and the Tag Name, I can still keep to one automation file per task (one for music, one for games), and it knows what that card does for any given task.

Nothing changes either way.

4. No string parsing

Putting tag commands in the Automation directly also means I don’t need to do any string parsing; simple dictionary lookups are enough.

The only quirk is I have cards that do other tasks such as closing the game and transfer the playlist to a different speaker with Music Assistant.

Conclusion

Which method makes more sense?

After writing all this, I’m currently leading toward putting the tags in the Automation, but I also wanna have some sort of semantic name on the Tag itself. Thing is, I really don’t like the idea of having to update that info in 2-3 places every time.