Home Assistant Tags

Hey all,

check out that (starting 2:00Min)
ESP32 playing music on Amazon Echo

This guy is simply writing the URI of spotify to the tag and plays the music on Amazon Echo.
Of course this is bypassing HA to validate the NFC, but actually, we don’t need HA neccessarily to just play some music from spotify.

Combined with the project of @schmurtz RFID Magic Box this would be the greatest portable “ESP-toni” you could build.

What’s your opinion on that?

makeratplay / esp32SpotifyEchoDot

Instead Amazon Echo you could also use an ESP32 with the squeezelite-esp32 firmware : it transforms an ESP32 into a squeezebox player able to read mp3, webradio ,spotify connect, airplay and many more. Not easier but it’s fun and the sound of the ESP32 with this firmware is awesome. cspot is an alternative : it is a spotify connect firmware for ESP32 that you could drive with HA.

And by the way if you need just web radio and tts notification you can use ESP8266 (very cheap!) or ESP32 thanks to the project I’m working on (initially created by MrDIY) : MrDiy-Audio-Notifier

Yeah you are completely right.

It depends on what is required, while I don’t have my requirements finally set yet.

Regardless what will be the hardware to output audio:

1.) Reading the card as you do, so detecting black and white constellations, will leverage 4 possibilities by one card. Which is totally cool.

Pro:
integrated in Esphome and HA which is cool to see what is playing and pressed and read by the nfc reader

Can be used for any scenario, not only as player.

Con:

  • ha down–》 no music will be played
  • it is only me able to write the automation to play the music

2.) Makeratplay has also some pro and cons

Pro:

  • Independently working:
    It does read the uri written to the tag and directly passes it to spotify api to play it on Amazon echo

  • my wife could write the tags as well, so I am not the only one able to create tags

  • Optional: not yet validated, but maybe this is possible to be integrated into esphome --》 this would leverage the integration into ha.
    Anyhow, if played on Amazon echo, it is integrated in HA by adding spotify component… so we would see what is playing currently.

Cons:

  • not yet possible to integrate into ha
  • dedicated to read only uri’s for spotify, so it cannot do anything else.
  • each uri must have an own card / sticker
  • buttons for switching track are missing currently

Output audio:
Squeezelite is absolutely the all-rounder…
CSPOT would be the alternative to Amazon echo, especially because audio controll is not needed

The audio notifier you are working on is awsome, but something I would not use here.

So, yeah… probably I will build two devices…
One, really close to your magic rfid box, for my personal fun

One for my kids being independent from ha, playing on any device connected to spotify.

So for info, I’ve received the tags I mentioned previously, and they work perfectly with Home Assistant :wink:

What is the max range of these tags/readers? I would like to put one on my dog’s collar to open his door, but he’s not going to hold it up to a reader.

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

Just wanted to say a massive thank you for this - your blog post and instructions were pretty easy to follow so I could modify the bits for a sonos playlist, etc.

I had probably wasted about 2 days of my life trying to sort this out before coming across this… now my kids can easily play their favourite music without pinging me all of the time. If only Audible could be ties to a card!

Could do what I’ve done with YouTube set the tag id to the audible book specifically wanted and when you scan a tag the event contains the I’d and you construct the url using that. Saves you needing to create records in code.

There seems to be a minor oversight in the implementation of this feature. In Settings>Tags you can name your tags quite easily, for instance “Artist - Album” for media tags, “Apples” for “grocery list tags”, etc.

But those names mean nothing in the context of automations or working with the tags. So, for instance for every tag I want to trigger a play_media-automation, I would have to manually hand-code the automation to that specific album/artist - or adding that specific item to the grocery list, etc.

Instead, if the event tag_scanned contained the name of the tag you could maintain the “message of the card” in the Settings>Tags location, and write more general automations in terms of “if card scanned, translate name to ‘play media’ function”.

As it is now it’s basically if "04-21-D9-08-19-6C-80 scanned play “Artist - Album”, if “d1aea5a3-e725-4039-acd6-a2c419dd839e add Apples to grocery list”, etc.

I see others have the same need:

2 Likes

Hello, i’m new here. I read this blog beacuse i have a tag reader from @adonno which works very good. I also managed to make automation with a card that plays album from plex server on a sonos device.
Because of two kids i thought about making a simple jukebox with tagreaders and wifi speakers playing the favourite audio book for every kid.
Is it possible to scan nfc card 1 on tagreader 1 and play album on device 1 and then scan nfc card 1 on tagreader 2 and play album on device 2?
I dont know how to make the automation! Templates?
I appreciate every help you can give.

Hi @kannbert,

…exactly that i have also realized for my children. i use node-red for this as in many other cases. if you are interested i can explain it to you. unfortunately i have not had the time to deal with direct HA automations. for me it was easier to click it together in node-red years ago. but in the meantime the automations directly under homeassistant have also become simpler and more powerful.

the key to automation here is that each reader sends its own id through which the tag was scanned. this allows you to create a simple filter if scanner id X then play on player 1 if scanner id Y then…

so if you are interested in a node-red solution i am happy to help… otherwise the hint above already helps and maybe there is already a blueprint for it?


image

Is this hardware compatible with pet RF chips? If so, what is the range, a few inches I’m guessing. I’d like to make my house respond to my pets going somewhere they should not (e.g. each other’s food, the guest room, etc.).

dear friends,
before working on the configuration of this work I would like to know something very important for me:
is it possible to get notification of the tag approched in realtime, keeping a NFC card attached to the reader continuosly or Home Assistant read just a single approach and the the next approach without understanding if the card is attached to the tag reader in realtime?
I don’t need to approach the card to the reader once in order to create an action but I do need to know if the NFC card is attached to the tag reader and it must be a realtime information as we have on HA for the lights/switchs when are on or off (card is attached or not).
Thank you for those who will reply me.

Not sure what happened with the last update. Now none of my readers will work. Kinda bites too. Grandson loved scanning his cards to start his movies. The card scans, logs show the tag reader see’s it, home assistant is clueless it happened.

@schmurtz
How do you detect the Black Corners of the card?
Can you share details?

hm, is it detect by home assistant ? Does the LED work ? Maybe removing the reader and readding it could solve the issue ?

Well. Its all working now. I had to reset home assistant to the last backup I had which was 6 months old (I need to do better at remembering to back up HA lol), reflashed the readers (built 4 so far) and things seem to be working. After that I backed up everything again and updated everything but esphome. (all the while getting full backups as I went). I updated esphome to 10.0 and same issue with the readers. Reset back to prior backup and reflashed the readers and they work. Didn’t update esphome until 10.2 and everything is still working. Not sure what the deal was with esphome 10.0 but it didn’t like my readers.

Thank you for sharing the readers with everyone. Its been fun watching the grandson use the reader to play movies with. Using jellyfin and roku media player since thats all I can get working. Hope to get plex to work but its hit and miss.

I set this up like presented here and its all working great. I wanted to be able to make the entity_id a little more flexible but still tied to the device that scanned the card, so I added a select component with a few entity_ids to the esphome config. I am trying to use HA templates to get the slected option from the select component, but I am getting stuck. This is what I have:

  action:
    - variables:
        media_player_entity_id: >-
            {% for entity in expand(device_entities(trigger.event.data.device_id))|map(attribute='entity_id')|list %}
              {% if is_state_attr(entity, 'friendly_name', 'Media Players') %}
                "{{ states(entity) }}"
              {% endif %}
            {% endfor %}

It seems not to evaluate. I tested in developer tools | templates (substituting trigger.event.data.device_id with the actual device_id and it seemed to work ok.
What am I doing wrong?

Hello @adonno,
Is it possible to replace the D1 mini with a C3 mini so that I get all the existing features plus a Bluetooth repeater? If so, do you know what would be the pinout?

It would be nice if tags could be added to groups and even assigned to users… Been playing with a nfc card reader for a possible door access control system and having home assistant as the way to control users access using the tag scanned feature of esphome would be nice to be able to get new tags into the system without having the create a new binary sensor on the esphome config firmware everytime.