home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.65k stars 30.79k forks source link

Sonos integration: BBC Radio station - metadata incorrectly displaying #64569

Closed SurreyMichael closed 2 years ago

SurreyMichael commented 2 years ago

The problem

I have set up BBC Sounds as a music service on Sonos, and added some BBC Radio stations as favourites.

In Home Assistant I use the mini-media player card to control my Sonos system and can successfully select those radio stations. The card correctly picks up from metadata the radio station name against 'source' and also 'media_channel'.

However 'media_title' but this has some strange behaviour:

I suspect this may be a problem with how BBC have implemented their Sonos service but thought I would report.

Examples: (copied from media_player entity attributes in developer tools)

media_content_id: >- x-sonosapi-hls:stations%7eplayable%7e%7ebbc_radio_fourfm%7e%7eurn%3abbc%3aradio%3anetwork%3abbc_radio_four?sid=325&flags=288&sn=15 media_content_type: music media_duration: 0 media_title: Think with Pinker media_channel: 'Radio 4 ' source: Radio 4

a couple of seconds later, the media_title line changes to: media_title: 'Think with Pinker • BR P|TYPE=SNG|TITLE |ARTIST |ALBUM '

subsequently media_title does not change unless I restart the radio station

What version of Home Assistant Core has the issue?

core-2021.12.10

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Sonos

Link to integration documentation on our website

https://www.home-assistant.io/integrations/sonos

Example YAML snippet

Full attribute listing referred above:

Entity: media_player.living_room
State: playing

Attributes -
source_list:
  - LBC London
  - LBC UK
  - Radio 3
  - Radio 4
  - Radio 4 Extra
  - Radio 5 live sports extra
  - talkRADIO
  - talkSPORT 2
  - Times Radio
volume_level: 0.26
is_volume_muted: false
media_content_id: >-
  x-sonosapi-hls:stations%7eplayable%7e%7ebbc_radio_fourfm%7e%7eurn%3abbc%3aradio%3anetwork%3abbc_radio_four?sid=325&flags=288&sn=15
media_content_type: music
media_duration: 0
media_title: 'Think with Pinker • BR P|TYPE=SNG|TITLE |ARTIST |ALBUM '
media_channel: 'Radio 4 '
source: Radio 4
shuffle: false
repeat: 'off'
sonos_group:
  - media_player.living_room
  - media_player.bathroom
  - media_player.workshop
  - media_player.portable
  - media_player.bedroom
entity_picture: >-
  /api/media_player_proxy/media_player.living_room?token=aac1cdcf2a73f07251f3b71ba946c45ead5460b9b58620facf779ed6ce67a6bd&cache=7ea49d466fd9b2cc
friendly_name: Living Room
supported_features: 457279

Anything in the logs that might be useful for us?

No response

Additional information

No response

probot-home-assistant[bot] commented 2 years ago

Hey there @cgtobi, @jjlawren, mind taking a look at this issue as it has been labeled with an integration (sonos) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)


sonos documentation sonos source (message by IssueLinks)

SurreyMichael commented 2 years ago

Additional info:

I checked with the Sonos app on my laptop (i.e. not HA). When I select a radio station, the Sonos app shows the station and name and a station picture. After a few seconds this changes to show a picture of the specific programme playing. On talk channels it continues to show the station name. On a music channel, it updates to show the track/artist currently playing.

So Sonos seems to know what the metadata means.

(I tried to paste a screenshot but it didn't work)

jjlawren commented 2 years ago

I was about to ask you to run some python scripts using the underlying library, but then I realized an upcoming HA feature would make this way easier. In 2022.2 you'll be able to grab a diagnostics dump from an integration, so I added this: https://github.com/home-assistant/core/pull/64576. That should give us all of the raw information we'll need to figure out what's going on here.

If you're feeling adventurous, you can run a 2022.2 beta release (once it's out) to collect the data, but otherwise hopefully you can live with this until the next release.

SurreyMichael commented 2 years ago

No worries about waiting - this is a nice to have, not need. I'll look out for the beta - but I confess to knowing enough to get me into trouble and not enough to get me out.

Can I take the opportunity to thank you for what you do? And your collaborators. Home Assistant has been useful in my home and fun to learn - I use the Sonos integration every day of my life and it is better for it. Many thanks.

jjlawren commented 2 years ago

@SurreyMichael if you're on 2022.2.X, grabbing diagnostics for the Sonos integration (or the specific speaker) after the metadata appears incorrect should hopefully give us enough info to understand what's going on.

SurreyMichael commented 2 years ago

OK - here is a diagnostics file. I am playing a radio station - BBC Radio 4. My lovelace card shows the title correctly for the program that was playing when I first selected the station "The Curious Case of Rutherford and Frye" - but has not updated now that the program has changed. When I play a music radio station, it correctly shows the track being played and updates.

sonos-616bda02be3f436bae503709c8f08738-Living Room-c91e1c69d76c4859a671e7f5b4792872.json-2.txt

jjlawren commented 2 years ago

Okay, looking at the diagnostics, the best we can make is "Radio 4 • The Curious Cases of Rutherford & Fry" which is "<channel><radio_show>". There's just nothing else provided by BBC in the metadata.

Although I can't seem to add the BBC music service, I can access a few BBC stations through TuneIn. Are you able to reproduce the same issues with those BBC stations? If so, then I could try to reproduce locally. I've tried a couple stations but none seem to include any info besides the radio show name--no artist/track/etc.

If those TuneIn stations don't behave in the same way, having a comparison that includes the integration diagnostics along with a screenshot of what the native Sonos app is showing would be very useful.

SurreyMichael commented 2 years ago

Thanks for looking at this. So "Radio 4 • The Curious Cases of Rutherford & Fry" was perfect info and displayed correctly when I started listening. The niggle is that it doesn't update. 30 minutes later the should have changed, but it doesn't automatically refresh. I can re-select the radio station and then it refreshes, but left to its own devices it doesn't.

I guess that may just be because of the Sonos feed rather than the integration.

This really is only a niggle - please don't feel you need to spend time on this!

I'll install a TuneIn version of the station and see what happens - and post more data.

SurreyMichael commented 2 years ago

OK - this is diagnostic with a TuneIn version of the station. This time my Lovelace card just shows the radio station name but doesn't show the programme playing - even though it is there in the diagnostic file (following copied from file): "stream_content": "BBC Radio 4 FM", "radio_show": "From Our Own Correspondent Podcast,p111"

If I examine the entity state on the developer tab in HA, I find these entries: (NB the radio show has changed to 'Money Box' since the diagnostic file)

using TuneIn/BBC station.... media_title: BBC Radio 4 FM media_channel: BBC Radio 4 • Money Box [Lovelace card displays "BBC Radio 4 FM" - i.e. ]

I waited for the next radio programme and the entry updated automatically albeit with a minute lag... media_title: BBC Radio 4 FM media_channel: BBC Radio 4 • The News Quiz

So my workaround is to put a separate Lovelace entity card to show and voila!

Back to my much preferred Sonos stations using the BBC Sounds service (sadly not yet available outside UK).... media_title: Radio 4 • Money Box media_channel: Radio 4 • Money Box [Lovelace card displays "Radio 4 • Money Box". So although this metadata happens to include the programme when started, it is static info]

I think state does update, although I have to keep waiting 30 minutes to check the next programme so not 100% sure. Will keep monitoring.

If I switch to a music station (Sonos/BBC Sounds station - BBC Radio 3) media_title: Cantata BWV 36, 'Schwingt freudig euch empor' (VI. Der du bist dem Vater gleich; VII. Auch mit gedämpften) media_artist: Johann Sebastian Bach media_channel: Radio 3 • Inside Music

In this case the and states update as the music changes during the programme. A little bit weird that is static for voice radio but updates for music.

Conclusions:

  1. Your wonderful Sonos integration seems to pick up the right metadata from the gobbledegook stream and store this in attributes.
  2. I can't find a way to change the Lovelace media player card / mini media player card settings to change which attributes are displayed - but maybe that's my lack of knowledge.
  3. My workaround of adding an extra entity card solves the problem sufficiently for me.

Many thanks for looking this. Happy to close issue unless you have any further insight.

sonos-616bda02be3f436bae503709c8f08738-Living Room-c91e1c69d76c4859a671e7f5b4792872.json-5.txt

jjlawren commented 2 years ago

Thanks, that's very thorough. If the data is there it's solvable.

Any chance you've upgraded to 2022.3.1 yet? There's a minor metadata fix included, I'm curious if it has any effect here.

SurreyMichael commented 2 years ago

Now updated to 2022.3.1 - can't see any difference on this issue.

But I now realise the problem is with the metadata feed rather than the integration. Listening via Sonos/TuneIn, the attribute updates fine. The Sonos/BBC Sounds feed doesn't.

jjlawren commented 2 years ago

Okay, so it seems the BBC music service simply doesn't update with the new radio show name. It would require keeping the native Sonos app open & active during a transition (which could be hard to time), but that test could prove the theory. If it doesn't change, there's no message we can receive to do the same.

SurreyMichael commented 2 years ago

I've contacted the BBC to see if there is a glitch with their BBC Sounds service for Sonos.

github-actions[bot] commented 2 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.