Play radio in Sonos and get proper station title

I want to have a couple of TuneIn channels start on different occasions, which I am doing with a script:

sequence:
  - service: media_player.play_media
    target:
      device_id:
        - ab1375438eb866229dc620c2f93fb856
        - 153737b0746a4585374a87bc1a5281af
    data:
      media_content_id: >-
        x-rincon-mp3radio://listen.radiotunes.com/premium_high/hit70s.pls?listen_key=XXXXXXX
      media_content_type: music
mode: single
alias: Play 70s Hits

But when I do this, the Sonos shows in the “Now playing” view, not the radio channel’s name, but instead the last part of the URL, after the last “/”. This is not pretty, and a bit annoying. Is there some way to make it show something else there instead? I tried with “media_channel: ‘70s Hits’” and “source: ‘70s Hits’”, but that wasn’t accepted.

I use Mini Media Player and have some button presets within it that allow me to pick from UK stations on Tune In - bit different to what you’ve done but might help?

          buttons:
            - id: media_player.select_source
              cover: /local/bbcradio5.png
              type: service
              data:
                entity_id: media_player.kitchen_sonos
                source: BBC Radio 5 live
            - id: media_player.select_source
              cover: /local/bbcradio2.png
              type: service
              data:
                entity_id: media_player.kitchen_sonos
                source: BBC Radio 2
            - id: media_player.select_source
              cover: /local/timesradio3.png
              type: service
              data:
                entity_id: media_player.kitchen_sonos
                source: Times Radio

I think I got the source name from the name of the station when it’s playing. The cover is just a local image so it looks better in the widget. I’d have thought you could use the same type of source in your automations.

I think the difference is you’re using ‘play_media’ rather than ‘select_source’.

2 Likes

That was it, thank you! I needed to add the stations to My Sonos, then I could use them as source. So this works:

sequence:
  - service: media_player.select_source
    target:
      device_id:
        - ab1375438eb866229dc620c2f93fb856
        - 153737b0746a4585374a87bc1a5281af
    data:
      source: RadioTunes 70s Hits
mode: single
alias: Play 70s Hits
2 Likes

Some of the radio station names/metadata were bothering me so I opened this PR. Hopefully this will fix the display for other stations without needing to add them as a favorite.

Do you have any advice about radio station metadata? Seems related but apologies if I am posting in the wrong place.

So good when BBC recently became a music source on Sonos - I can listen to my radio subscriptions using the Sonos app - excellent. However most of the time I just listen to live radio controlled by HA. Perfect. No more TuneIn radio stations for BBC.

Apart from a tiny niggle. Not crucial but it annoys me that I can’t find a solution.

When I select a BBC radio station (set as a Sonos favourite) my mini-media player Lovelace card momentarily shows the correct name of the programme. A few seconds later it changes to add some unparsed data. And it never updates - it’s static - it doesn’t update to show the next programme.

Using developer tools, the entity state attributes include for example:
media_title: ‘Sketches: Stories of Art and People’

but if I refresh a couple of seconds later, this changes to:
media_title: 'Sketches: Stories of Art and People • BR P|TYPE=SNG|TITLE |ARTIST |ALBUM ’

and then the media_title is static thereafter.

Seems odd behaviour. If you have any suggestion as to what is going on, I would appreciate a nudge in the right direction - but I accept I may just need to live with this.

Thanks

Possibly bad metadata provided with the radio station. Can you create a github issue here for the Sonos integration? I’m guessing it may need to be addressed in the underlying library, but would need to gather some info from you first.

Edit: I’m not sure if BBC is region-locked, but I’m not able to add it as a source in the US to test.

Thanks - will log.

From my limited experience of connecting outside the UK, BBC seems to be region locked for somethings but not others.