Sonos script to change source not working

Dear all,

I’m trying to set up a system in which I can use HA to change the source from my Sonos. The sonos, including its sources is detected by HA:

The script I made is quite simple for now, just to test. Upon calling it, I hear the sonos taking a little pause, but then it continues to play “Studio Brussels”, no matter what I

This is my sonos.yaml script:

sonos:
  alias: Sonos Kitchen
  sequence:
    - service: media_player.select_source
      data:
        entity_id: media_player.Sonos.Kitchen
        source: "VRT Radio 1"

Is there anybody who got a similar thing working and if so, could you please share your code?

Thank you in advance,
Erwin

EDIT:
I already tried source: "VRT Radio 1", source: 'VRT Radio 1' and source: VRT Radio 1, but that didn’t change anything.

UPDATE:
This seems to work:


But my script doesn’t… I don’t get it.

Could you format your code using the </> button in the editor please? It makes it easier to see whether there are obvious syntax/indentation issues
image

I’m sorry, I was planning to, but apparently it didn’t came through upon posting. I was already fixing it :slight_smile:

Regards,
Erwin

I guess for starters, if sonos is the name of your script, it’s missing : after it

Also I don’t have a sonos so bear with me. For AV Receivers, changing the source means selecting another input. What is actually the source on your sonos?
If it’s a different media stream, I’m not sure your script will work on its own, you may have to use media_player.play_media

Hi,

Again sorry, the lack of a : was a typo, it’s fixed in the original post now.

The script that I’m using, is based on another post. However, I have the feeling that the sonos component has changed quite dramatically since than.

What I do notice now, is that in the above screenshot all radio stations are listed under “source_list” instead of “source”. Not quite sure if the key to the solution is in there?

Not sure actually, but is it case sensitive in the entity_id? You write Sonos_Kitchen in your code, but in the services view you write sonos_kitchen

Not sure actually, but is it case sensitive in the entity_id? You write Sonos_Kitchen in your code, but in the services view you write sonos_kitchen

Exactly… also you have a point in your entity id.

This should work then:

sonos:
  alias: Sonos Kitchen
  sequence:
    - service: media_player.select_source
      data:
        entity_id: media_player.sonos_kitchen
        source: "VRT Radio 1"

You guys!

I thought I already thought about that, and changed it nevertheless, but apparently I didn’t… So it’s a good thing that I tried it again and indeed: the script of AlmostSerious works!

Thank you all!

1 Like