Sonos Media_Player remains paused (via script and automation)

Hi,
i’m controlling my Sony TV and Sonos through scripts and automation - works fine except for my Sonos speaker, which remains “paused” when triggered.

script.mediacenter_on
Works fine, Sony TV turns on, Sonos turns on, Sonos source is changed to “Line-In” - but the speaker remains “paused”

mediacenter_on:
  alias: BraviaTV and Sonos On
  sequence:
    - service: homeassistant.turn_off
      entity_id: script.mediacenter_on

    - service: media_player.turn_on
      entity_id: media_player.sony_bravia_tv

    - service: media_player.sonos_unjoin
      entity_id:
        - media_player.sonos_eg_wohnen
        - media_player.sonos_eg_buero
        - media_player.sonos_og_philipp
    - service: media_player.turn_on
      entity_id: media_player.sonos_eg_wohnen
    - service: scene.turn_on
      entity_id: scene.sonos_play_livingroom
    - service: media_player.select_source
      data:
        entity_id: media_player.sonos_eg_wohnen
        source: 'Line-in'

Already tried to add a scene, which sets the state to “playing” - but the speaker remains “paused”

scene.sonos_play_livingroom

name: Sonos play Livingroom
entities:
#
  media_player.eg_buero:
    state: paused
#
  media_player.eg_wohnen:
    state: playing
#
  media_player.og_kind_philipp:
    state: paused

After that i tried adding an automation, to switch the Sonos speaker depending of my TV turned on - automation fires, but the speaker remains “paused”.

automation.media-player_sonos_source

  - alias: Sonos LineIn when BraviaTV On
    trigger:
      - platform: state
        entity_id: media_player.sony_bravia_tv
        to: 'playing'
        from: 'idle'
      - platform: state
        entity_id: media_player.sony_bravia_tv
        to: 'playing'
        from: 'off'
      - platform: state
        entity_id: media_player.sony_bravia_tv
        to: 'on'
        from: 'off'
    action:
      - service: media_player.turn_on
        entity_id: media_player.sonos_eg_wohnen
      - service: media_player.volume_set
        data:
          entity_id: media_player.sonos_eg_wohnen
          volume_level: 0.2
      - service: scene.turn_on
        entity_id: scene.sonos_play_livingroom
      - service: media_player.select_source
        data:
          entity_id: media_player.sonos_eg_wohnen
          source: Line-in
      - service: notify.telegram
        data_template:
          message: "Sonos LineIn for BraviaTV"

I’m out of more ideas, there must be a solution. :wink:

Any succes on this issue?

@Vayain since this has been bumped, here’s a few quick tips. Playing line-in on sonos is a little funky because if you think of it, you’re just telling it to select the line-in, not play anything. The post I’ve quoted below will hopefully help.

Also, you are calling the service script.turn_off . There is no such thing for scripts or scenes, because they are just executed immediately, they don’t have an on or off.

Good luck you two, and post any further issues or progress you have here!

I hope you can give me a solution for my problem as well, I try to let an mp3 file play at the sonos when there is movement in the house. It worked for a while however now it stopt working.

This was after an update of home assistant and after I put the whole configuration behind ssl. I rolled back everything but nothing seems to work.

{
"entity_id": "media_player.woonkamer","media_content_id": " https://www.mydomainname:8123/local/dog.mp3","media_content_type":"MUSIC"
}

The url above is producing the sound, I tried the option /local/dog.mp3 and local/dog.mp3 as well but also this don’t work.

By the way the dog.mp3 file is in the www map.

The frontend shows
image
Which suggest the file is being played but it is not actually.

Error executing service <ServiceCall media_player.play_media: entity_id=[‘media_player.woonkamer’], media_content_id=local/dog.mp3, media_content_type=MUSIC>
15:23 components/media_player/sonos.py (ERROR)

Do you have an idea?

Any luck? I am having trouble playing mp3 over htts on Sonos as well. Perhaps we can use a playlist?

Sonos will not play from self-signed HTTPS connections.

I have a https homeassistant setup in docker on a Synology with a Letsencrypt certificate, please find my working code underneath:

    entity_id: media_player.woonkamer
    media_content_id: https://www.mydomain.xxx/local/dog.mp3
    media_content_type: MUSIC

Hope this works for you as well,

André

I found this thread looking for a solution and wound up getting help on Discord.

This works:

 sonos_billiards_line_in:
   alias: "Sonos Set Input Bluetooth"
   sequence:
     - service: media_player.select_source
       entity_id: media_player.billiards_room_2
       data:
         source: "Line-in"
     - service: media_player.media_play_pause
       data:
         entity_id: media_player.billiards_room_2