Play radio-stream on button-press

Hi,
I’m trying to create a button that plays my favorite radio station.

Creating the button and making it call a service was easy. But how do I make the speakers actually play this stream?

I seem to be getting the configuration wrong:

show_name: true
show_icon: true
type: button
tap_action:
  action: call-service
  service: media_player.play_media
  target:
    entity_id: media_player.kuche_2
  data:
    media_content_id: 	http://stream.spreeradio.de/spree-live/mp3-192/radio-browser.info/
    media_content_type: audio/mp4
name: Spreeradio

Using radio-browser to search the station and start the stream works perfectly fine but is not very comfortable.

But since it is working with radio-browser: Is there a way to see the service-calls, radio-browser uses to play the stream?
This way I could copy calls it uses.

Thank you!

The way I have done it:

show_icon: true
type: button
tap_action:
  action: call-service
  service: automation.trigger
  target:
    entity_id: automation.11_71_sky_radio_action_volume_34
  data:
    skip_condition: true
name: Sky Radio
show_state: true
icon_height: 25px
icon: mdi:cast-connected


The button calls an action of an automation, though most likely it is possible to call the stream directly in the button setting.
In my example ‘mazal’ is group of various Google Chromecast and Nest Audio speakers.

There are a few ways to accomplish this but I think you’ve chosen the most awkward.

I would take the service calls in the action section of your automation and create a template button using them then use button.press service call for that button in both your automation action and the tap_action for your UI button.

You could also create a script with the automation action section and call that script in the automation and UI button.

Both would be preferable to calling an automation.trigger IMHO.

I fully agree with you.
I created this when I started HA and it was the only way I understood and, though I agree that there are better ways, it works.
Also, I have not worked with Templates yet and even do not yet understand the concept. I will spend some time watching YouTube videos to get it…
I like the script suggestion and already incorporated scripts in many of my automations that use the same action.
Thanks for your input.

Thank you. The core of your solution seems to the same:
Call media_player.play_media with the stream’s URL as “Content ID”.
Correct?

But for some reason, the music just does not play unfortunately.

Do you have the right audio type ?


It can be mp3, aac etc

I did not think yet of ‘aac’. But now I tried mp3, ogg, wma and aac, each with and without ‘audio/’ as prefix.

When checking the System-logs, I do see some errors though.

I use Chromecast/Nest Audio and am not familiar with Sonos.

A little late to the party but I was searching for the same and got this working.
A button calling this script to start a mp3 stream from a radio station:

service: media_player.play_media
metadata: {}
data:
  media_content_id: <stream url>
  media_content_type: music
target:
  entity_id: <your mediaplayer>

Instead of type: music, I had mp3 first which didn’t work and in the UI it says to specify what kind media


HTH

1 Like