Tagreader jukebox: old dog, new tricks!

With my recent contributions 1d3a58f to @adonno great Tag Reader project, we can now play Apple Music and Spotify playlists URLs (maybe others? Deezer for sure is not working) written directly to NFC cards as NTAG URLs.
Why?

  1. To have one automation for all tags: use this blueprint PlayMusicTag.yaml No more automation programming of each card one by one
  2. To use the same cards for HA jukebox and for playing with your phone: as long as you’re using NTAG21x compatible cards and your phone can scan it, it will work the same with tagreader and your phone. Simple as that. Scan with tagreader and HA media player will play it. Scan with phone and it will open app with this playlist or album
  3. To share the cards with others: yes, you can now scan and play any card that has playlist url written directly as NTAG. Just write your mixtape playlist to the card and share with friends, family and anybody. Metaverse digital twin experience :wink:

How?

  1. Use latest release of tagreader.yaml
  2. Write your tag with write_music_tag service

    music_url is the URL of the album or playlist copied from Share option
    music_info is whatever description you want
    Call Service will beep, put your card on the reader, wait for 2 beeps and now you have Music Tag card!
  3. Set up PlayMusicTag automation
    Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.
  4. Scan the card and enjoy the music.

How? (with debugging)

  1. Open Developer Tools → Events
  2. Start listening to events named esphome.music_tag
  3. With every scan, tagreader will publish ha event with reader name, identified streaming service, url and info values read from the card
  4. The event triggers automation that grabs this data and uses media_player you’ve set up to play the url

Sonos extras
I’m using it with Sonos. The glitch here is that media_player.play_media service is not working with radio station urls. But there is a workaround for that

  1. In Sonos app, add the station to My Sonos
  2. Write your tag with short sonos-2:// url
  3. Put the name of the station exactly like Sonos registered it to the music_info field
  4. Write your card
    This card will also trigger esphome.music_tag event with source set to sonos and the automation will use media_player.select_source service to play it. Works every time!
  5. This sonos-2:// url if scanned with a phone will open Sonos S2 app. There is no way to point directly to the source you want to play - blame Sonos for not implementing universal links. But if you mark the card with a nice picture and a name you can select it yourself :wink:

Hope you’ll enjoy this new jukebox experience the same as I do. Cheers!

9 Likes

One more argument to use this. If you want to have more that 1 tagreader! With old firmware and HA tags automation it was difficult to make same tags work with different tadreaders combined with players in different rooms. So if you want to have tagreader per media player per room, this is your best choice :slight_smile:

1 Like

first off, this is a great project, thanks for sharing. I have it working great when using an output of a Sonos media player…

However, I cannot get it to work with any other type of output media player (Chromecast Audio, Muse, Browser…etc) I’ve tried many different media players that show up and work correctly within HA, I can only get tags to play when the blueprint is pointing to a Sonos player…

Is this a limitation or am I doing something wrong? thanks in advance. Martin

Can you post your esphome.music_tag event from developer tools?

here you go. I did xx’out the last five digits of the various IDs below, not sure what if anything there is sensitive; as stated, this is a really good automation that you’ve created - works like a charm when connected to an output of one of my Sonos media players but cant seem to get it to play on anything else.

Event 0 fired 11:52 AM:
{
“event_type”: “esphome.music_tag”,
“data”: {
“device_id”: “fd6918a7ac43dbd16bfdec7b3b1xxxxx”,
“reader”: “tagreader02-9bfc37”,
“source”: “spotify”,
“url”: “https://open.spotify.com/album/21jF5jlMtzo94wbxxxxxx”,
“info”: “Adele: 30”
},
“origin”: “LOCAL”,
“time_fired”: “2022-06-06T16:52:23.688589+00:00”,
“context”: {
“id”: “01G4WYX3086819B7SWHW2xxxxx”,
“parent_id”: null,
“user_id”: null
}
}

ok, this looks good.
It should work as described here

But I see it’s not. I also get this error from chromecast

2022-06-07 22:20:12 ERROR (Thread-22) [homeassistant.components.cast.media_player] Failed to cast media https://open.spotify.com/album/4uG8q3GPuWHQlRbswMIRS6?si=uYlLCh2mRwqyeDP-2mc6mg. Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address
2022-06-07 22:21:54 ERROR (Thread-22) [homeassistant.components.cast.media_player] Failed to cast media https://music.apple.com/pl/album/over-the-rainbow/1296697429?i=1296697430&l=pl. Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address

Well, if you’ll find a working yaml for playing url, please let me know and I can change the automation. For now it looks like only Sonos players allow to stream URLs.

Got the tagreader for adonno but its not showing up as a tagreader in the blueprint you posted

1 Like

Could it be a http vs https issue? Although that wouldn’t explain why it works with Sonos…

can you show me what is your device manufacturer?
image

I really don’t know. Just grab the url and try playing it. If it’s not working (and apparently it’s not) I think you can fill a bug for this because according to documentation Cast should work.

media_content_id		A media identifier. The format of this is integration dependent. For example, you can provide URLs to Sonos and Cast but only a playlist ID to iTunes.

So it looks like something is wrong here. Or maybe it’s about Yamaha Music Cast and not Chromecast :wink:

If you’d like other players working in this music_tag mode, please post your call service for your player. How do you point the player to proper playlist? By id, name, source? Maybe we could come up with a solution similar to Sonos stations as I’ve mentioned in the description. But then phone scan and card/tag sharing is probably lost. But multiroom tagreaders would still be working with their assigned players so still worth it.

1 Like

Using The spotcast integration:

service: spotcast.start
data:
  device_name: Livingroom
  spotify_device_id: 4363634563457346xcyvydgf3qwa
  entity_id: media_player.vardagsrum
  uri: spotify:playlist:37i9dQZF1DX3yvAYDslnv8
  account: my_wifes
  force_playback: true
  random_song: true
  repeat: track
  shuffle: true
  offset: 1
  start_volume: 50
  ignore_fully_played: true

Realy just needs the entity_id and URI

For the media_player.play_media:

service: media_player.play_media
data:
  media_content_id: >-
    spotify://47890c7612a952357bf0c7863ad02371/spotify:album:7bjzGhcdUmkqlgcNDboDkz
  media_content_type: spotify://album
target:
  entity_id: media_player.bedroom_speaker

Figured out what you are asking and changed the manufacturer name in the blueprint.

1 Like

So I changed some of the code in the blueprint to make Spotify playlists work. Doing it this way I would need a separate automation for playlists, albums and tracks.

  default:
  - service: media_player.play_media
    data:
      media_content_type: spotify://playlist
      media_content_id: '{{ "spotify:playlist:"+trigger.event.data.url[34:-20] }}'
    target:
      entity_id: !input 'player'

The reason I had to do it this way is because esphome.music_card only allows there to be a URL and not a URI. The Spotify integration with Chromecast goes based on URI. So the media_content_id: template basically reformats the regular open Spotify URL into a URI. What it does is add some text before and removes part of the URL from the front and back.

Plus i changed the media_content_type: to “spotify://playlist” because that’s what is needed to use the Spotify integration with Chromecast.

I want to make the whole thing a bit cleaner and then I will post my full blueprint but for now this works. It might take some time for me to figure out as I’ve never changed a blueprint before.

1 Like

Can you try using Music Assistant? I think is should work with Spotify url and Chromecast out of the box. Just select Music Assistant media player as your target

How will it know which speakers to play on?

Well, it creates virtual media player for every chosen physical media player. So just choose the one that matches your tagreader room speakers. Just like you would with physical media player entity. I’ve just seen Home Assistant ‘Let’s get loud’ event and I think this is the way to go rather then code for every media player there is out there.

ok thanks! ill try it out.

Hey Luka,

adding Music Assistant into the mix now makes your Tag Reader project work on practically anything - so so happy. As you know, it recently only worked streaming to Sonos due to some weird limitation but now using the virtual media_player.mass_xxx outputs pretty much anything I’ve tried works flawlessly.

this has made my jukebox project play happy music :slight_smile:

Thank you for your awesome work too. M

2 Likes

I would like to use a template sensor to play the latest scraped podcast episode like:
{{states.sensor.podcast_cbc_news.state}}
Could this code be written to the tag in place of the url?