I have several Sonos devices setup on my network working nicely.
I would like to automate them playing radio streams at various points of the day, but i can’t seem to get it to work.
The streams in question are BBC ones, i have tried the following JSON payloads, but nether seems to work. They are based on the media id’s returned by the devices to Home Assistant.
The easiest way to determine the URL to be used for media_content_id is to play the station in Sonos (choosing it via Sonos Radio or TunieIn) and then have a look at Developer Tools/States - it will show the exact URL to be used:
One may ask why bother, why not simply add the radio stations you are interested in to the Sonos Favorites and then have them available in the source list? The answer is to that is that you may not want to add everything you want to be able to play from HA to the Sonos favourites. Or that you would like to create different sets of favourite radio stations in HA - one for yourself, another one for you wife or your kids. As Sonos still doesn’t have multi-user support, so using HA can mitigate that shortcoming to a small extent.
(Choosing a entry from above drop down menu will immediately start playing that station on the Sonos boxes in my room)
In case the radio station you are interested in is not available in Sonos Radio or TuneIn, you can go to your radio’s station website to figure out the URL to be used there. This youtube clip shows how that works:
URLs to be used for media_content_id for Sonos are a bit different - they typically have a prefix and will not work without. E.g. the media_content_id for Melbourne’s RRR radio station is not just https://ondemand.rrr.org.au/getstream?id=wshq but will require a x-rincon-mp3radio:// prefix:
This was exactly my solution. I’ve been searching everywhere for this, but couldn’t find it.
I created an automation, once a tag has been scanned:
alias: Top versuz
description: ''
trigger:
- platform: tag
tag_id: {{TAG ID}}
condition: []
action:
- service: media_player.play_media
data:
media_content_id: >-
x-rincon-mp3radio://{{PLACE YOUR HTTPS:// URL HERE}}
media_content_type: music
enqueue: play
target:
entity_id: {{FILL IN THE NAME OF YOUR RADIO}}
mode: single