Skip to main content
inspire
Trending Lyricist I
January 9, 2019

Setting a sleep timer: Functions for improvement.

  • January 9, 2019
  • 11 replies
  • 5861 views
Because we have it on a bedroom, we'll use the sleep timer every time:
https://support.sonos.com/s/article/452?language=en_US
My wife ordered a chance to remember the last timer, so Next time I put music on play, it's on. Our sleep timer is set up in 30 minutes. Every night we'll set it again. It could be that he remembers the situation last and change when I change. I guess it's not all like that so. Maybe add a slider - ‘Remember my last sleep timer’. And then every time I put the music playing, it automatically started. What do you think of such thought?
    This topic has been closed for further comments. You can use the search bar to find a similar topic, or create a new one by clicking Create Topic at the top of the page.

    11 replies

    Belly M
    November 13, 2019

    The Python code I use, make a copy of this as it works… at the moment.


    basically “import soco” discovers your Sonos devices. The one I control is called Master Bedroom which matches the name within Sonos.

    it then plays, so the paused playlist resumes.

    it then sends a sleep commend for 3600 seconds, which is one hour, but could be any value.

     

    As I use the sleep command, the music fades out but Sonos pauses the playlist without resetting the playlist back to the start as would happen with using a stop command.


     

    import soco

    def get_speaker(name):
        for speaker in soco.discover():
            if speaker.player_name == name:
                return speaker

    sonos = get_speaker("Master Bedroom")

    sonos.play()
    sonos.set_sleep_timer(3600)