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?
To have one automation for all tags: use this blueprint PlayMusicTag.yaml No more automation programming of each card one by one
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
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
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!
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
In Sonos app, add the station to My Sonos
Write your tag with short sonos-2:// url
Put the name of the station exactly like Sonos registered it to the music_info field
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!
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
Hope you’ll enjoy this new jukebox experience the same as I do. Cheers!
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
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
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.
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.
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
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.
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.
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.
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
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.
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.
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?