[Sonos] Select source without playing it

I want to reset the audio sources of my Sonos devices each night, so no matter what played during the day, radio station xy will be set for the next morning.

I tried it with media_player.select_source, but this will automaticall play the selected source. Is there any way to load a source without playing it? I don’t like messing around with mute, load, pause, unmute.

Can’t you just call 2 actions in one? Or do they not like receiving commands that close together?

script:
  reset_sonos_source:
    sequence:
      - service: media_player.select_source
        data_template:
          entity_id: "{{ id }}"
          source: "{{ source }}"
      - service: media_player.media_stop
         data_template:
           entity_id: "{{ id }}"

If that works, just use that script in your nightly automation

- alias: "Reset Media Devices"
  trigger: 
    platform: time
    at: "00:04:00"
  action:
    - service: script.reset_sonos_source
      data:
        entity_id: media_player.sonos_1
        source: "radio station 1"
    # Only one instance of script can run at a time....
    - wait_template: "{{ is_state('script.reset_sonos_source', 'off') }}"
    - service: script.reset_sonos_source
      data:
        entity_id: media_player.sonos_2
        source: "radio station 1"

But no, there is no way to select_source and not have it play that source.

I haven’t tried this because I don’t trust my Sonos at all and don’t want them to start playing at night. I guess the only way really is to mute them, start playing the sorce, then stop and unmute.

Or just try it?

Make the script and call it manually to see what happens

It does actually seem to work, even when you load a source for multiple rooms and stop them all at once :+1: Will keep an eye on it :slight_smile:

Update: Combining the two actions doesn’t work. To select a media source without hearing it play, you have to do this, which is not a clean solution in my opinion:

    - service: media_player.volume_set
      data:
        entity_id: 
          - media_player.bad
          - media_player.flur
        volume_level: 0.0
    - delay: '00:00:01'
    - service: media_player.select_source
      data:
        entity_id: 
          - media_player.bad
          - media_player.flur
        source: "SWR Aktuell"
    - delay: '00:00:10'
    - service: media_player.media_stop
      data:
        entity_id: 
          - media_player.bad
          - media_player.flur
    - delay: '00:00:02'
    - service: media_player.volume_set
      data:
        entity_id:
          - media_player.bad
          - media_player.flur
        volume_level: 0.2

Is there really no way to select a source without the device starting to play?

I have a similar need. Use case:

Single automation to 1/if paused, play. 2/ if mute, unmute. 3/play one station during the week 4/ play another station on the weekend.

If I change sonos source out of band (i.e. with the app) then it will stay in the source list and that is what will play even on the next day.

I’d like a way to clear the source after a certain period of time or on schedule. I suppose I could set it to a “Dead” line-in and then stop playback.

This may be an older topic and I used to have this problem, I used to do it by muting and selecting source etc. and every now and then it would fail and radio would start blaring at 5am.
My solution:
Create a scene with all concerned speakers with the source selected, your wanted volume, and all speakers paused and then call that scene from a script at your desired time using an automation.
My setup script is: Unjoin all speakers, Set scene, Join the speakers I want joined. (the scene does not seem to recall the grouping of speakers).
Now every morning I have my wished speakers grouped and qued to play my favourite radiostation
without there being a risk of othem playing during the setup.

1 Like

@andrec54 would you mind sharing your code for these scene/scriptd?
much appreciated