Set Sonos source to Line-In?

Is there any way to set the source on Sonos devices?

I have a pair of Play:5’s that I want to set to Line-in ® when I turn on my TV.

Bumping this to provide the answer, since this is the top result for this question on Google.

The sources listed in HASS are your Sonos favorites as-of startup, but since you can’t favorite a line-in, you can’t use media_player.select_source. Instead, you’ll have to use media_player.play_media and tell Sonos which specific speaker’s line-in you want to use.

Getting the Source ID

Open the Sonos app, and visit Settings > About my Sonos System, then find the device whose Line-in you want to use. Look at the part of the serial number before the :, and remove any dashes. Your ID is: RINCON_XXXXXXXXXXXX01400 (replace the Xs with your serial number).

For example, if my serial was 01-23-45-67-89-AB:F, my ID would be RINCON_0123456789AB01400.

(Alternatively, just visit http://[sonos device id]:1400/status/zp and make note of the LocalUID.)

Using the ID

You can call media_player.play_media with the following:

entity_id: media_player.[...]
media_content_id: x-rincon-stream:RINCON_[...]
media_content_type: music

EDIT 2021: At some point media_content_type switched from “MUSIC” (uppercase) to “music” (lowercase). If you’re having any problems, try the opposite casing.

9 Likes

It was probably updated, cause for me it works with:

media_player.select_source
entity_id: media_player.sonos_arc
source: TV
1 Like

This works for me now, (possibly because it’s using the line-in from itself):

  - service: media_player.select_source
    data:
      entity_id: media_player.basement_sonos
      source: Line-in
  - service: media_player.media_play
    data:
      entity_id: media_player.basement_sonos
1 Like

Thank you! now we need to add ‘data’ with last upgrade:

    - service: media_player.select_source
      data:
        entity_id: media_player.salle_tv
        source: TV

Thanks for this, very helpful.

In case someone want to use this with Node-Red, here is the service node to call.

[{"id":"fe19f54a.0edbe","type":"api-call-service","z":"776f4844.419d2","g":"19f4a5c7.121f4a","name":"Vinyl to Salon","server":"3c58bfa4.fb4fb","version":3,"debugenabled":false,"service_domain":"media_player","service":"play_media","entityId":"media_player.name","data":"{\"media_content_id\":\"x-rincon-stream:RINCON_XXXXXXXXX01400\",\"media_content_type\":\"music\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":720,"y":120,"wires":[[]]},{"id":"3c58bfa4.fb4fb","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Thanks works great​:blush::muscle::muscle:

is this still working, what is the latest trick. i can’t get Line-In to work. Thx

actually got it to work this way

  1. See example templates: Sonos - Home Assistant)
    {% for media_id, name in state_attr(“sensor.sonos_favorites”, “items”).items() %}
    {{ name, media_id }}
    {% endfor %}

Example: (‘Apple TV Family Room: Family Room: Family Room’, ‘FV:2/0’)

  1. Copy the media_content_id example: FV:2/0 and use below service call:
    service: media_player.play_media
    target:
    entity_id: media_player.kitchen
    data:
    media_content_type: “favorite_item_id”
    media_content_id: “FV:2/0”

I am new to HA and can’t seem to work out how to select the Line-in on a Sonos Connect. I have tried this but to no avail:

service: media_player.select_source
data:
  source: Line-in
target:
  entity_id: media_player.study_connect

I have also tried:

service: media_player.play_media
target:
  entity_id: media_player.study_connect
data:
  media_content_type: music
  media_content_id: x-rincon-stream:RINCON_949F3E26375E01400

Well it turns out the last one above was working, but when I ran the script from within the script editor it did nothing.
When I exited it and ran it from the the 3 dots menu against the same script it worked. I don’t understand then.

If you go to the sidebar menu → Developer Tools → States, find your speaker, and click on it, you’ll see the full state in a YAML textarea. Part of that YAML is a source list similar to the following:

source_list:
  - Line-in
  - TV

If you use one of these as your source when calling media_player.select_source, it should work. Make sure to use the exact case from the list.

I’d imagine this solution is less likely to break with an update, but the rincon URL solution above will allow playback of one device’s input through a different speaker