Turn off music playing playing on Sonos after 30 minutes

I want to be able to stop music/radio station stream playing on Sonos speaker after 30 minutes.
Below is what I currently have to get the music playing. I need to know what lines to add to the automation or script to stop the music after 30 minutes.

automation

# Morning Wakeup
- alias: 'morning wakeup'
  condition:
    condition: time
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
  trigger:
    - platform: time
      at: "06:45:00"
  action:
    - service: script.masterbedroomwakeup

script

masterbedroomwakeup:
  alias: 'Master Bedroom Wake Up Routine'
  sequence:
    - service: media_player.select_source
      data:
        entity_id: media_player.office
        source: "104.3 | Q104 (Country Music)"

FYI: The source is playing from my Sonos favorites

You could add a delay in the script, so something like:

masterbedroomwakeup:
  alias: 'Master Bedroom Wake Up Routine'
  sequence:
    - service: media_player.select_source
      data:
        entity_id: media_player.office
        source: "104.3 | Q104 (Country Music)"

    - delay: '00:30:00'

    - service: media_player.media_stop
      data:
        entity_id: media_player.office
        

If there’s an event like a door sensor opening & closing, and you want the music to keep playing till that happens then use ‘wait’

1 Like

Thanks for your feedback.

I found this solution after some extensive searching and it is working for my needs.
I added the following to my sequence in my script

- data:
    entity_id: media_player.master_bathroom
    sleep_time: 7200 # the number of seconds to wait
  service: sonos.set_sleep_timer
1 Like

I think I might like the delay option better. That way I won’t have to figure out how many seconds for the sleep timer. :slight_smile:

1 Like

Off the original question/topic

But, option for controlling volume level?

That would be the service:


media_player.volume_set

Happy musical mornings to ya :slight_smile:

1 Like