How to find the media_content_id to play_media

Hi folks-

I am trying to set up some scripts to play specific titles on my roon media player(s). My understanding is that I need to use media_player.play_media service, but I don’t (yet) know the media_content_id.

Is there any way to get the media_content_id from something that’s currently playing? I tried subscribing to the state_changed events in devtools but there isn’t a media_content_id in the payloads that I’ve seen.

Some stuff I would play is from my Roon catalog on my server, and some will likely be Tidal/Qobuz, so, ideally, I’d be able to see/capture different URLs

Many thanks,
-jamie

The state-attributes of the media_player in dev tools (states) will show you the content id.

1 Like

I guess this is part of why I couldn’t find it, apparently it doesn’t show it for Roon:

volume_level: 1
is_volume_muted: false
media_duration: 408
media_position: 9
media_position_updated_at: '2022-07-25T12:46:52.154126+00:00'
media_title: Cumberland Blues
media_artist: Grateful Dead
media_album_name: 'Dave''s Picks Volume 34 • Jai-Alai Fronton, Miami, FL • 06/23/1974'
media_album_artist: Grateful Dead
shuffle: false
group_members: []
friendly_name: Office Roon
entity_picture: >-
  /api/media_player_proxy/media_player.office_roon?token=55d7b1a7822b06a471db743d6000c2c3bcca08c1a797afee6155ed961e56e9c6&cache=5991bf880e11c0c8
supported_features: 710591

But it does for the sonos integration:

source_list:
  - 25 - Classic Rewind
  - 26 - Classic Vinyl
...
volume_level: 0.78
is_volume_muted: false
media_content_id: >-
  x-sonosapi-hls:Api%3atune%3aliveAudio%3a9450%3a44f9129f-579a-3d23-218f-3c3518036fc6?sid=37&flags=296&sn=20
media_content_type: music
media_title: Somebody Told Me
media_artist: Killers
media_album_name: Hot Fuss
media_channel: 12 - PopRocks
shuffle: false
repeat: 'off'
sonos_group:
  - media_player.office_sonos
friendly_name: Office Sonos
entity_picture: >-
  /api/media_player_proxy/media_player.office_sonos?token=96f44e98f1edd66cc3253a2036a82aa82cf077180d364a885af9aba4538cbb89&cache=1faf79faedb22036
supported_features: 457279

and for a local file:

media_content_id: x-file-cifs://crowley/Music/_38%20Special/Flashback_%20The%20Best%20Of%20.38%20Special/01%20Back%20To%20Paradise.m4a

While I still haven’t been able to find the content id for things that are playing, I was able to figure out how to work out the paths for things in my library and some things in tidal, for example:

  "media_content_id": "TIDAL/Your Favorites/Artists/Eric Clapton/Pilgrim"

A nice thing though is that, when it fails, it provides helpful text. For example, if I leave off the album name, I get (trimmed a bit and reformatted for readability):

ERROR (SyncWorker_2) [roonapi] Could not find media path element '' in 
['Play Artist',
...
 'Timepieces: The Best Of Eric Clapton',
 'Roswell The UFO Cover-up/Communion: Music From The Motion Pictures',
 'Unplugged (2013 Remaster)',
 "Eric Clapton's Rainbow Concert",
 'Old Sock',
 'Chronicles'
]

Not everything in Tidal meshes with what shows up in Roon, for example the playlists, but I can at least work with this…

Sorry I just saw this.

But just for anyone else who finds this, Roon itself doesn’t provide any type of content id (at least nothing is available via the api). So it isn’t possible to use this to play a particular track by id (or to save and restore a track that is playing.

So what you found is the best that can be done. Glad you found the error messages useful (I spent a while on them!)

Using the HA media browser can help work out the media paths (although please note any ids you see in the logs are only valid for the lifetime of that browse session!)

I’m facing the same problem. No idea where how to make up the correct media_content_id .
Even for Live radio , I can’t figure out the right content ID.

service: media_player.play_media
data:
  entity_id: media_player.office_speakers_2
  media_content_id: /My Live Radio/KDFC
  media_content_type: music

Any help would be greatly appreciated !

Using the HA media browser can help work out the media paths (although please note any ids you see in the logs are only valid for the lifetime of that browse session!)

I can’t see any of my Roon content in the HA media browser. Is this supposed to be provided by the Roon integration ?

The browser is accessible via the icon in the media players.

If your command isn’t working - hunt down the error in the HA logs, it should tell you the possible strings at the point the path doesn’t match.

Thanks for your help.
I have tried that browse media icon , but I only see my Plex and JRiver DLNA servers, not the Roon core media library. I looked at all the folders, but it’s not there.

It’s in the media player itself.

Thanks, Pavoni. It turns out I was looking at the wrong media player in the UI. Each of my 16 Chromecast devices is a media player, and there are 16 CC devices in the Chromecast integration, and another 16 for the Roon integration. They look exactly the same in the GUI except for their entity name.

I got an “Explore” window similar to yours. I am able to choose media or radio from there, and it plays on the corresponding media player. What I still can’t do successfully is use the integration to play anything at all. Even the exact examples from the documentation, with My Live Radio/BBC Radio 4 don’t work. And yes I did add this channel to “My Live Radio” folder using the Roon app.

What error do you see in the HA logs? The 'play_media" command should give good errors - including all he browser possibilities at the point it failed.

Just noticed your path starts with a leading / - which I don’t think it should.

But regardless you should look at the error in the HA logs

Here is an example of what I get with the following automation :

alias: Roon
sequence:
  - service: media_player.play_media
    data:
      media_content_id: My Live Radio/BBC Radio 4
      media_content_type: music
    target:
      entity_id: media_player.office_speakers_2
mode: single

Logger: roonapi
Source: components/roon/media_player.py:432
First occurred: 16:17:20 (1 occurrences)
Last logged: 16:17:20

Could not find media path element ‘BBC Radio 4’ in [‘BBC Radio 4 LW’, ‘KDFC-FM’]

I figured out I had two errors :

  1. I had a slash (/) prior to “My Live Radio”
  2. I needed to add BBC Radio 4 LW, unlike what the example in the doc says. Perhaps the station name changed. It’s no longer BBC Radio 4
  3. HA consolidates log messages of the same type, even with different strings (ie. all the messages for “Could not find media path element” were consolidated). I just cleared the logs and triggered my automation to be able to see the right message.

Thanks.

So I tried with a media_content_id of Library/Albums/Random (not being able to guess the exact name of the album).

I got this log message :

Could not find media path element 'Random' in ['West Side Story [1993 Studio Recording]', 'When Night Falls', 'Wiener Philharmoniker Karl Böhm', 'Wilhelm Furtwängler', 'Wilhelm Furtwängler', 'Wilhelm Furtwängler', 'William Bolcom: Songs of Innocence and of Experience', 'William Byrd: The Complete Keyboard Music', 'William Byrd, Thomas Tallis: Masses & Motets', 'William Kapell', 'William Kapell Edition', 'William Kapell Edition', 'William Schuman: Symphonies Nos. 3, 5 & 8', 'The Wind Beneath My Wings', 'Windswept', "With a Poet's Eye: New American Choral Music", 'Wolfgang Amadeus Mozart: 4 Hornkonzerte', 'Wolfgang Amadeus Mozart: Complete Works', 'Wolfgang Amadeus Mozart: Requiem', 'Working Classical', 'Working Classical', 'Working Classical', 'Works transcribed for ten-stringed & alto guitar', 'The World of Handel', 'The World of Sousa Marches', "The World's Favorite Piano Music", "World's Greatest Melodies", "World's Greatest Melodies", "World's Greatest Melodies", "World's Greatest Melodies", "World's Greatest Melodies", 'Wurlitzer Plus!', 'Yellowstone Remembered', 'Yellowstone Remembered II', 'Yeu Mai', 'Young at Heart', 'The Young Martha Argerich', 'Zelenka: Complete Orchestral Works', 'Zelenka: Complete Orchestral Works', 'Zelenka: Complete Orchestral Works', 'Zelenka: Complete Orchestral Works', 'Zelenka: Complete Orchestral Works', 'Zelenka: Complete Orchestral Works', 'Zelenka: Complete Orchestral Works', 'Zelenka: Complete Orchestral Works', 'Zelenka: Orchestral Works; Trio Sonatas', 'Zelenka: Orchestral Works & Trio Sonatas', 'Zelenka: Orchestral Works & Trio Sonatas', 'Zelenka: Orchestral Works & Trio Sonatas', 'Zelenka: Orchestral Works & Trio Sonatas', 'Zelenka: Orchestral Works & Trio Sonatas', 'Zoolook', 'スペースコブラ', 'フルートワールドポップス名曲集']

This looks to be the cropped end of the list of 2754 albums.
I was able to play an album with a media_content_id of Library/Albums/Zoolook .

Is there any way to list the album names for other albums and not just the tail end ?
I probably wouldn’t want the entire list dumped. But something like a wildcard search or shuffle support would be very helpful.

Also, it looks like the album names are not unique - that would make it difficult to pick a specific one.

Glad you found your problem.

The BBC have two different Radio 4 streams (they occasionally diverge) so you must have added the LW one to your radio favourites.

You can also access via Artists to find a specific album if there are duplicate names (Library/Artists/Neil Young/WhateverAlbum)

The names are just those from your roon library - so just look in the roon app to find the names.