I got this little smart display and followed the tutorial and got the code from Smart Home Junkie -
Its excellent. Great code and tutorial.
But I am a bit of a newbie -
Could anyone point me in the right direction to be able to code to display/output the ‘now playing’ artist and track name from a Sonos speaker onto the screen using esphome?
Each media player is a little different in the metadata it can show. However, if you pay a track on you Sonos, then look in the states section of the developer tools. There will be a whole lot of attributes, like this sort of thing
group_members:
volume_level: 0.3
is_volume_muted: false
media_content_id: {"index": 8, "urls": [{"url": "file:///music/John_Mayall_&_The_Bluesbreakers-Blues_Breakers_With_Eric_Clapton/01.All_Your_Love.mp3"}, {"url": "file:///music/John_Mayall_&_The_Bluesbreakers-Blues_Breakers_With_Eric_Clapton/02.Hideaway.mp3"}, {"url": "file:///music/John_Mayall_&_The_Bluesbreakers-Blues_Breakers_With_Eric_Clapton/03.Little_Girl.mp3"}, {"url": "file:///music/John_Mayall_&_The_Bluesbreakers-Blues_Breakers_With_Eric_Clapton/04.Another_Man.mp3"}, {"url": "file:///music/John_Mayall_&_The_Bluesbreakers-Blues_Breakers_With_Eric_Clapton/05.Double_Crossing_Time.mp3"}, {"url": "file:///music/John_Mayall_&_The_Bluesbreakers-Blues_Breakers_With_Eric_Clapton/06.Whatd_I_Say.mp3"}, {"url": "file:///music/John_Mayall_&_The_Bluesbreakers-Blues_Breakers_With_Eric_Clapton/07.Key_To_Love.mp3"}, {"url": "file:///music/John_Mayall_&_The_Bluesbreakers-Blues_Breakers_With_Eric_Clapton/08.Parchman_Farm.mp3"}, {"url": "file:///music/John_Mayall_&_The_Bluesbreakers-Blues_Breakers_With_Eric_Clapton/09.Have_You_Heard.mp3"}, {"url": "file:///music/John_Mayall_&_The_Bluesbreakers-Blues_Breakers_With_Eric_Clapton/10.Ramblin_On_My_Mind.mp3"}, {"url": "file:///music/John_Mayall_&_The_Bluesbreakers-Blues_Breakers_With_Eric_Clapton/11.Steppin_Out.mp3"}, {"url": "file:///music/John_Mayall_&_The_Bluesbreakers-Blues_Breakers_With_Eric_Clapton/12.It_Aint_Right.mp3"}]}
media_content_type: playlist
media_duration: 357
media_position: 178
media_position_updated_at: 2024-07-25T05:21:14.576932+00:00
media_title: Have You Heard
media_artist: John Mayall & The Bluesbreakers
media_album_name: Blues Breakers With Eric Clapton
shuffle: false
repeat: off
query_result:
{}
RIP John Mayall!!!
This is not for a Sonos, but you should be able to find what you want this way.