Sonos automation stopped due to UPnP Error 800

For our daily morning routine I’ve created an automation that will turn on the lights (when it’s dark) and put on some music. This automation is most of the time (not always) stopped due to an error:

Stopped because an error was encountered at February 11, 2025 at 07:00:05 (runtime: 5.41 seconds)

Error calling SonosMediaPlayerEntity._play_media on media_player.sonos_arc_woonkamer: UPnP Error 800 received: from 192.168.1.244

Is there something in my automation that I can adjust to avoid these kind of errors?

Automation in YAML:

alias: Lights and music in the morning.
description: 
triggers:
  - entity_id:
      - schedule.lampen_aan_begane_grond
    trigger: state
    from: "off"
    to: "on"
conditions:
  - condition: state
    entity_id: input_boolean.kill_switch
    state: "off"
actions:
  - if:
      - condition: state
        entity_id: binary_sensor.dark_outside
        state: "on"
    then:
      - action: scene.turn_on
        metadata: {}
        target:
          entity_id: scene.beneden_verdieping_ontbijten
        data: {}
      - action: media_player.volume_set
        metadata: {}
        data:
          volume_level: 0.06
        target:
          entity_id:
            - media_player.sonos_arc_woonkamer
            - media_player.sonos_one_keuken
      - action: media_player.shuffle_set
        metadata: {}
        data:
          shuffle: true
        target:
          entity_id: media_player.sonos_arc_woonkamer
      - action: media_player.play_media
        target:
          entity_id: media_player.sonos_arc_woonkamer
        data:
          media_content_id: FV:2/101
          media_content_type: favorite_item_id
        metadata:
          title: Chill Morning Vibes by Dirk
          thumbnail: >-
            https://image-cdn-ak.spotifycdn.com/image/ab67706c0000da84f75a8dbd8a709a1c26894d29
          media_class: playlist
          children_media_class: null
          navigateIds:
            - {}
            - media_content_type: favorites
              media_content_id: ""
            - media_content_type: favorites_folder
              media_content_id: object.container.playlistContainer
      - action: media_player.join
        metadata: {}
        data:
          group_members:
            - media_player.sonos_one_keuken
        target:
          entity_id: media_player.sonos_arc_woonkamer
      - delay:
          hours: 0
          minutes: 0
          seconds: 5
          milliseconds: 0
      - action: media_player.play_media
        target:
          entity_id: media_player.sonos_arc_woonkamer
        data:
          media_content_id: FV:2/101
          media_content_type: favorite_item_id
        metadata:
          title: Chill Morning Vibes by Dirk
          thumbnail: >-
            https://image-cdn-ak.spotifycdn.com/image/ab67706c0000da84f75a8dbd8a709a1c26894d29
          media_class: playlist
          children_media_class: null
          navigateIds:
            - {}
            - media_content_type: favorites
              media_content_id: ""
            - media_content_type: favorites_folder
              media_content_id: object.container.playlistContainer
    else:
      - action: media_player.volume_set
        metadata: {}
        data:
          volume_level: 0.06
        target:
          entity_id:
            - media_player.sonos_arc_woonkamer
            - media_player.sonos_one_keuken
      - action: media_player.shuffle_set
        metadata: {}
        data:
          shuffle: true
        target:
          entity_id: media_player.sonos_arc_woonkamer
      - action: media_player.play_media
        target:
          entity_id: media_player.sonos_arc_woonkamer
        data:
          media_content_id: FV:2/101
          media_content_type: favorite_item_id
        metadata:
          title: Chill Morning Vibes by Dirk
          thumbnail: >-
            https://image-cdn-ak.spotifycdn.com/image/ab67706c0000da84f75a8dbd8a709a1c26894d29
          media_class: playlist
          children_media_class: null
          navigateIds:
            - {}
            - media_content_type: favorites
              media_content_id: ""
            - media_content_type: favorites_folder
              media_content_id: object.container.playlistContainer
      - action: media_player.join
        metadata: {}
        data:
          group_members:
            - media_player.sonos_one_keuken
        target:
          entity_id: media_player.sonos_arc_woonkamer
      - delay:
          hours: 0
          minutes: 0
          seconds: 5
          milliseconds: 0
      - action: media_player.play_media
        target:
          entity_id: media_player.sonos_arc_woonkamer
        data:
          media_content_id: FV:2/101
          media_content_type: favorite_item_id
        metadata:
          title: Chill Morning Vibes by Dirk
          thumbnail: >-
            https://image-cdn-ak.spotifycdn.com/image/ab67706c0000da84f75a8dbd8a709a1c26894d29
          media_class: playlist
          children_media_class: null
          navigateIds:
            - {}
            - media_content_type: favorites
              media_content_id: ""
            - media_content_type: favorites_folder
              media_content_id: object.container.playlistContainer
mode: single

Unfortunately Sonos and/or Spotify Connect has always been a bit unreliable when waking up from sleep. The last month or two it has now become super unreliable. Not sure there is much you can do about it really.

I have an alarm clock automation where I’ve put the media play action inside a loop to combat these issues. It attempts to play the media, waits a few seconds for it to begin to play, then if it doesn’t play we start over and try again. This used to work fine, if it didn’t begin playing on the first attempt, then it would almost always do so on the second or very latest third attempt.

But lately it seems that about every other day, it does not work, at all. About to change to Apple Music and see if that makes a difference, then at least I’ll know whether the problem is Sonos or Spotify (though I suspect the latter).

When I trigger the automation manually a few minutes later, It always start playing. So maybe this loop is a workaround I can test. Can you maybe share the code your using for this?

Here is a part of the automation. It uses a lot of variables, so you’ll probably need to do quite a bit of adaptation before it fits inside your automation.

I also set the shuffle parameter within the loop, because for whatever reason you cannot set this before starting playback or it will be reset. (But only if you do it in a HASS action, if you set it manually in the Sonos app it will be retained?!) And since I already set shuffle in there, I may as well set repeat as well, in case that eventually ends up with the same limitations.

- repeat:
    sequence:
    - if: "{{ state_attr(playback_entity, 'shuffle') not in [none, playback_shuffle] }}"
      then:
      - action: media_player.shuffle_set
        target:
          entity_id: "{{ playback_entity }}"
        data:
          shuffle: "{{ playback_shuffle }}"
        continue_on_error: true
    - if: "{{ state_attr(playback_entity, 'repeat') not in [none, playback_repeat] }}"
      then:
      - action: media_player.repeat_set
        target:
          entity_id: "{{ playback_entity }}"
        data:
          repeat: "{{ playback_repeat }}"
        continue_on_error: true
    - if: "{{ none not in playback_data.values() }}"
      then:
      - action: media_player.play_media
        data: "{{ playback_data }}"
        continue_on_error: true
      else:
      - action: media_player.media_play
        target:
          entity_id: "{{ playback_entity }}"
        continue_on_error: true
    - wait_template: "{{ is_state(playback_entity, 'playing') }}"
      timeout: "{{ repeat.index * 10 }}"
    - variables:
        playback_state: "{{ states[playback_entity] }}"
    until:
    - or:
      - and:
        - "{{ is_state(playback_entity, 'playing') }}"
        - "{{ state_attr(playback_entity, 'shuffle') in [none, playback_shuffle] }}"
        - "{{ state_attr(playback_entity, 'repeat') in [none, playback_repeat] }}"
      - "{{ repeat.index >= 5 }}"

Looking in traces at the value of the playback_state variable, I can see that my Sonos gear loads the correct playlist and for each iteration of the loop picks a new random song. It just seems to either never manage to begin playing it or take an awfully long time to do so. Just a month or two ago this was nowhere near as bad…

If there are still users that experience this problem; try using Music Assistant in your automations to trigger music in Spotify. For me, this solves the problem.