White noise playback repeat not working on Sonos

I have been using HA with my Sonos to provide white noise for my bedroom. It was working great until Wednesday (2025-02-26). It plays the clip once (for 60m), but then stops. This is my automation:

alias: Play rain noise at 2130hrs
description: ""
mode: single
triggers:
  - at: "21:30:00"
    trigger: time
conditions: []
actions:
  - data:
      volume_level: 0.52
    target:
      device_id:
        - 32eb344022dc3b28b0151dbffb084f48
    action: media_player.volume_set
  - target:
      entity_id: media_player.sonos_roam
    data:
      media_content_id: media-source://media_source/local/03-White-Noise-60min.mp3
      media_content_type: audio/mpeg
    metadata:
      title: 03-White-Noise-60min.mp3
      thumbnail: null
      media_class: music
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://media_source
    action: media_player.play_media
  - data:
      repeat: all
    target:
      device_id: 32eb344022dc3b28b0151dbffb084f48
    action: media_player.repeat_set

My questions is 2 fold: 1) How can I make the repeat work again, and 2) Does anyone do something similar with white noise, and if so, how is it done so that it is reliable?

I recently tried to use repeat_set with my Sonos speakers (within the last week) and could not get it to work. I had never tried before.

You could enclose the media_play call in a repeat loop. But that means you won’t be able to easily stop playback from the Sonos device without additional code.

@d921 I can definitely try that, but I am afraid it will stop for a second and then start again, which will wake me up. I am a VERY light sleeper, which is why I need the white noise. Every sound the house makes, or the cat, or the dog wakes me up.

You’ll obviously have to try it first when not sleeping, and that’s going to be the case with just about any solution you try.

Note that if you’re okay with the limitation that you have to stop the automation using HA rather than using the Sonos app or the device physical toggles, you might (or might not) need a delay statement after the call to media_play. I cannot remember right now whether the media_play waits for the media to finish playing or not.

1 Like

Thanks. I am going to give it a go now (3 hours before bedtime) and see how it goes.

Good luck. Happy to help brainstorm how to fine-tune.

I re-read your earlier post about stopping for a second and then starting again. If you are really sensitive at that level of time–as opposed to, say, a minute–it’s going to be pretty hard to fine-tune the loop to avoid a pause. Was it truly continuous when you had repeat_set working?

An alternative might be to set the -delay time, assuming it needs to be used, to something shorter than the full length of the media file. I don’t know how much of a pause that would create, or if it would; nor whether that would be acceptable depending on how the white noise varies over time.

Anyway, I also suggest that you file a bug report with the Sonos integration, because it does feel like this is a bug, especially since it was working for you. Not clear if it was triggered by an HA update on your end or perhaps by a Sonos firmware update (or something else altogether).

Agreed. I am looking at some other options as well. It was continuous when I had repeat_set. I don’t know how that was even possible, but it was working great. I should probably make a shorter file (not 60m) so I can really test things. I will submit a ticket with the sonos integration and see what they say. Thanks for the idea!