How to play radio channel on Home Assistant Voice Media Player

I have created a helper selector to select the radio channel. and an automation to play the channel when selected.

Mine is far more complex as i have 6 media players and 8 regularly listened to stations.

1 Like

Thank you!!
I got it!

There isn’t a way to save them directly in the Media panel, but you can add radio stations via url in Music Assistant if you are using that. Once added to Music Assistant, they will also appear in the Media panel.

You can also add radio browser to.music assistant and then add radio browser links to music assistant favourites.

Ok, I´ll try that.
But where do I find the URL of a radio station?

If you.open radio browser in a web browser.

https://www.radio-browser.info/

You can then find the radio station you want and click a few bits on the station page and somewhere in there will.be the link.

Ok, maybe I´m stupid.
I have saved a radio station in music assistant as favourite.
I created an automation to start music assistant radio when I say “Radio on”.
Voice Assist confirms it wit “done” but nothing happens.
I can not choose which radio station to play nor to play my favouites.
Where is my mistake?

I will share my current setup, perhaps it will be of interest or of use to someone.

1)Add integration “Radio Browser” once added. Look in “Media” you should have “Radio Browser” as a media source.

2)Then in “Add-ons” install “Music Assistant Server”

3)Go to “Music Assistant” webgui either from add-on or from the left menu of HA.

4)From Home (in Music Assistant) click the cog (top left) to enter settings, click “ADD MUSIC PROVIDER”, select radio browser (this is all from memory) I assume you can choose radi browser here as a media source.

5)Then click “ADD PLAYER PROVIDER”, I chose home assistant media players, add you media players (only ha media players will be available to choose if you players are a different type choose a different provider

6)From here you should be able to search you favourite radio station and add it to you favourites and also play from here to you chosen media player

Asking HA voice assistant to play a particular station requires an automation to be setup to trigger to the sentences assist hears from you device.

Assuming assist is set up and working, here is and example automation.

For the trigger:

trigger: conversation
command:
  - "[Clay] [Play] [Plays] Classic [FM]"
id: Play Classic F-M
variables:
  voice_assistant: " {{ trigger.device_id }} "
  voice_assistant_mediaplayer2: " {{ device_entities(voice_assistant) | regex_replace(find='_media_player', replace='_media_player_2', ignorecase=False) }} "
  voice_assistant_device: " {{ (voice_assistant_mediaplayer2) | regex_findall('media_player.h.*_2') }} "

For the action:

choose:
  - conditions:
      - condition: trigger
        id:
          - Play Classic F-M
    sequence:
      - action: media_player.play_media
        target:
          entity_id: " {{ (voice_assistant_device) }} "
        data:
          media_content_id: library://radio/1
          media_content_type: music
        metadata:
          title: Classic FM (UK)
          thumbnail: https://www.classicfm.com/assets_v4r/classic/img/favicon-196x196.png
          media_class: music
          children_media_class: null
          navigateIds:
            - {}
            - media_content_type: music_assistant
              media_content_id: radio
        enabled: true

I may have left a few steps out but this is the jist of it.
Please note I am not sure if the regex part (the variables) will work for you, so leave this out and try to get one working by selecting the media_player and station via the automation gui editor. This is only necessary if you have multiple HA voice PE devices so it targets the device where the radio station was requested from. Hope this helps someone, all I can say is that it works extremely well for me.

1 Like

Thank you for sharing this.
I did all the steps already but I can not figure out how to tell Voice Assistant to play or which radio station to play.
I can´t see any ID in the radio stations that I could point to.

In the automation in question.

1)Add Action, select “Media player” > “Play Media”(Play media on media player) > then select media player in the drop down list.

2)If you have HA Voice PE device and music assistant server setup there maybe be 2 of the same entity name but one will have something like _2 on the end, the name may not be visible as the name is long but there should be 2 media players of a very similar name e.g

Home Assistant Voice xxxx Media Player and
Home Assistant Voice xxxx Media Player 2

The one with media player 2 is the one you want it is the entity that relates to music assistant.

If you edit the action in yaml and you get to choose “Radio stations” or another source from music assistant you will see the name in “entity_id”

Choose this one.

3)Then click the + button “Pick One”

Scroll to “Radio Stations” and you should see the radio stations you have flagged as favourites in Music assistant. Choose the ration you want to play on the media play you chose above.

You may see “Radio Browser” also. I haven’t used that as Music Assistant gives only stations that I have added as my favourites. So adding from “Radio Browser” should work but I have not tried adding it via Pick one so can’t tell you if that works or not.

Note: there is another “Play Media”(Starts playing specified media) option do not choose this one.

Is playing a radio station from “Music Assistant” working via the Music Assistant web gui to your HA voice PE device?

Could you plase explain the trigger variables in more detail to find the voice pe that made the request? In particular how does regex_findall(‘media_player.h.*_2’) work?

You may want to refer to the following post as the music assistant entity is now using the friendly name instead of adding _2, at least this is what happened on my system.

There’s a bit more discussion in there and hopefully answers your question? I am also using a different method in the above link but both the one you refer to and the current method that is used are discussed.

I also encountered a bug (reported) that seems to be related to a suspected change to friendly name however you would have to check to see what entity_id value Music Assistant is using for your voice PE device

I tried using friendly name and it did not work.
I reverted back to using *_2 names and voice recognition of the speaker worked!

   variables:
      voice_assistant: " {{ trigger.device_id }} "
      voice_assistant_mediaplayer2: " {{ device_entities(voice_assistant) | regex_replace(find='_media_player', replace='_media_player_2', ignorecase=False) }} "
      voice_assistant_device: " {{ (voice_assistant_mediaplayer2) | regex_findall('media_player.*_2') }} "

So, I am both pleased and confused.
Are you using the beta version of music assistant?

Good to hear and yes it is confusing. Not sure why mine changed to using friendly_name.

For more information on what is going on you can see the variables in the trace of your automation, you just have to match the name to what ever MA is using.

I am using MA 2.3.6 simply the add-on for HASSIO.

It maybe because I imported the voice PE devices in ESPHOME builder and I changed the friendly_name in the configuration.

But for you it seems the _2 is the MA entity of the voice PE device so there are 2 entities for the device one “native” and the other is MA specific regardless of what it is called.

Another difference is I am using respeaker lite with the koala esphome config.
It is pretty much identical to voice pe but with much better sound.
See:
https://github.com/formatBCE/Koala-Satellite

1 Like

One small annoyance is the need to reboot music assistant if the voice satellite is turned off and on again. Music assistant forgets the *_2 media player when this happens rebooting ma seems to be needed for the music assistant *-2 media player to be recognized again

Yes I reported something similar here:

I now add the variables part at the same level as the trigger rather than inside each trigger (I did this at the time of the original post) so it is only required in the automation once (more efficient) and applies for all triggers in the automation if that makes sense.

Edit:

I put the variables in “var_3”, script wide level variable (it will appear at the bottom of the automation script after saving it and then going back to edit it in yaml mode):

Understood. I will modify my automation accordingly,