Volumio - Making a button to play a web radio URI

I’m trying to set up some simple buttons in my Lovelace dashboard which when pressed play a specific web radio URI on another Pi running Volumio (ip address 192.168.0.220 via its JSON-API and I’m struggling a bit to set it up. At the moment I’m just trying to get the background stuff set up to pass the API command.

From what I can see from the Volumio REST API the command I want is
192.168.0.220/api/v1/replaceAndPlay

with a payload something like

{ "service": "webradio", "type": "webradio", "title": "Absolute CR", "uri": "http://ais.absoluteradio.co.uk/absoluteclassicrock.mp3" }

to play that station. I’ve tried this using a RESTful command and I’m not getting anywhere. Looking in developer tools, I can’t see anything under the services section.

The code I’m using is

rest_command:
  Play_ACR:
    url: "http://192.168.0.220/api/v1/replaceAndPlay"
    method: post
    content_type: "application/json"
    payload: '{ "service":"webradio", "type":"webradio", "title":"Absolute Classic Rock", "uri":"http://ais.absoluteradio.co.uk/absoluteclassicrock.mp3" }'

Am I going about this wrong, or is there some better way to send the commands to Volumio to make it play a specific URI? I have the integration installed (and it works fine to generally control the radio) although it doesn’t include a way to send such a command.

Do not recall exact setup, as I dropped volumio few months ago… But as I recall I simply created in volumio playlist that pointed to selected radio station and then I used media_player.play_media service with playlist as target media… Sorry do not recall details, but it worked flawlesly.

That’s the method I’m generally using at the moment, but it’s a bit of a kludge to have to create and maintain a playlist for each of the stations.

Looking at the API it should be possible to directly inject the URI, which would be much simpler and would be the preferred way I think. If not then yes I can do it that way, and I know already how to do that.

It was just eluding me how to send the command and payload correctly to send the URI, which is what I need the help and advice on.

Not sure if this would simplify (still require creation of playlists in volumio), but at least can somehow automate the process of selection of the playlist in HA. So you need to create input_select.playlists first to store playlists from volumio. Then you can following automation to sync (once per hour, in this sample) input_select.playlists with playlists available on volumio:

- id: 'Load Volumio Playlists'
  alias: Load Volumio Playlists
  initial_state: True
  trigger:
  - platform: time_pattern
    hours: '/01' 
  action:
    - service: input_select.set_options
      target:
        entity_id: input_select.playlists
      data:
        options: >
          {{ state_attr('media_player.volumio', 'source_list')  | list }}

Once you have list populated you can use it to feed data to media_player what to play… Again do not recall all details, just found this piece of code no completely cleaned up from my config…

I’ll have a play with it, but really it was the creation of all the playlists that I was trying to avoid.

From looking at the API it should be possible to pass the URI information directly, but I’m not so experienced with REST and JSON so need some help in getting the formating and syntax right (and indeed confirming that I’m using the correct protocol and method).

But thanks for the inputs anyway, most useful to expand my knowledge of all this. I haven’t played with input selection much at all so far.

Edited to add - had a look, got the input_select list and playlists set up, but now hopelessly confused about how to actually use it. I can do the individual playlists playing directly via a rest call (the thing that I was trying to avoid doing in the first place), but the input_select is confusing me on how to implement it as the examples in the docs are not very clear.

Lets take a look at this post:

It looks very similar to what I used.

OK now I’m getting somewhere. Have an input_select working now, but still using the playlists.

So it’s functional, but not really what I was originally after. I’m still curious as to how I can get the HA pi and the Volumio Pi talking properly via the REST API’s.

Would also be simpler if I could select a specific “track” from a playlist (so I could make one playlist with all stations in and then just select the one I want), but that seems to be beyond what the APIs allow.

To play a radio station by its URL, I am using the following skript:

alias: Skript Volumio-Arbeitszimmer Antenne Saar
sequence:
  - service: media_player.play_media
    data:
      media_content_id: >-
        {"uri": "http://streaming01.sr-online.de/antennesaar_2.m3u", "service":
        "webradio"}
      media_content_type: channel
    target:
      entity_id: media_player.volumio_arbeitszimmer
mode: single
icon: mdi:radio-tower

Thanks, that works perfectly :smiley: