Music Assistant and Sonos Port Line-In

I have collection of Sonos speakers with a few scripts to play music. After fighting
and losing to get the default Sonos integration to play specific Spotify playlists, I switched to Music Assistant. This has made it way easier to specify the music I want in Scripts.

The only snafu I’m hitting is changing the input on my Sonos port. I have a turntable attached and a script to switch Sonos to the Line-in source. This uses the default Sonos devices rather than the MA devices, as I can’t find a way to adjust this through MA.

Switching to line-in works fine, but switching back to MA/spotify playlists causes problems. The script below is able to correctly stop the players, adjust the volume, and enable shuffle mode. But if I try to set the source to a playlist on the MA devices, nothing happens (“nothing” as in no music plays but also no error message). If I run the script once, wait a few minutes, and then run it again, then the playlist starts correctly.

I’m guessing the issue is that I’m throwing commands to both the Sonos devices directly and the MA devices, because even the Sonos app seems to get confused about the source immediately after this script. The only time I call the Sonos speakers directly is to set the line-in source. Other than that, everything happens in MA. Is there a way to set MA to the Port’s line-in so that I can stop “talking” to the Sonos devices directly?

Script to enable line-in (this works fine every time):

sequence:
  - action: media_player.media_stop
    metadata: {}
    data: {}
    target:
      floor_id: apartment
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: 0.3
    target:
      floor_id: apartment
  - action: media_player.play_media
    metadata: {}
    data:
      media_content_id: x-rincon-stream:RINCON_[serial number]
      media_content_type: music
    target:
      label_id: sonos
alias: Set source to turntable
description: ""

I’ve tried using the same media_content_id with MA, but that just seems to use value as a search and plays the closest matching track from Spotify

And here is the script to switch to a Spotify playlist. Everything except the last step seems to work as expected; no music plays but no error is thrown if I’m immediately transitioning out of the line-in. (but it works correctly if I wait a few minutes after the line-in has been stopped):

sequence:
  - action: media_player.media_stop
    metadata: {}
    data: {}
    target:
      floor_id: apartment
  - action: media_player.shuffle_set
    metadata: {}
    data:
      shuffle: true
    target:
      label_id: music_assistant
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: 0.2
    target:
      label_id: music_assistant
  - action: music_assistant.play_media
    metadata: {}
    data:
      media_id: spotify://playlist/37i9dQZF1DX4sWSpwq3LiO
    target:
      label_id: music_assistant
alias: Play sleep music
description: ""

Hello easing6,

Is there any particular reason you didn’t ask in the thread for Music assistant? The people that are watching that thread are all either interested. users of, or authors of Music Assistant. They are likely your best resource.

There is also a discord server for it. Not certain if this invite link still works, but here it is.

Because I just went with the same category as the first Music Assistant post I found without searching further :laughing: Thank you! I’ll move this there.

1 Like