Home Assistant Tags

Hi everybody,

I’m trying to build a jukebox system with RFID cards and card reader (thanks to @adonno amazing job).

I’ve follow this post : Home Assistant Tags - Home Assistant

It’s working as expected : after card is scanned, an album from my Plex server is played on my Sonos Speakers. You can see bellow my automation :frowning:

alias: Handle Tag Scan
mode: single
max_exceeded: silent
variables:
  media_players:
    3c4e54495a710c03a5bcbb9b74c3e98c: media_player.chambre
  tags:
    cca80f72-2604-960d-2014-099818b363dd:
      media_content_id: >-
        plex://{ "library_name": "Reggae JA / Albums", "artist_name":
        "Capleton", "album_name": "Reign of fire" }
      media_content_type: music
trigger:
  - platform: event
    event_type: tag_scanned
condition:
  - condition: template
    value_template: '{{ trigger.event.data.tag_id in tags }}'
  - condition: template
    value_template: '{{ trigger.event.data.device_id in media_players }}'
action:
  - 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 }}'
  - service: 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

This method works, but maintain a matching table between tag’s id & plex album details seems really annoying and I have the feeling this can be optimized :wink:

Here is an exemple of a Plex album mapping :
plex://{ "library_name": "Reggae JA / Albums", "artist_name": "Capleton", "album_name": "Reign of fire" }

I’ve found out that it was possible to flash this data directly inside the tags as tag_id, and these tags are still recognized when they are scanned, so my idea is to find how to skip the matching table steps between tag’s id & plex album.

My idea:

  • When any tag is scanned an automation is fired
  • A condition in this automation check if the tag id start with plex:// to continue
  • The automation play the media referenced in my tag on my sonos speakers.

The downside :
I can’t find how to use the tag_id inside the automation action.
I totaly don’t know how to do a logical test on the first caracters of a string.

Any idea how to achieve this ? :sweat_smile:
Any help would be welcomed!!

1 Like