[Guide] Service: Auto Enable Sleep on play

I use rockbox on some old Sansa clip devices and it has a brilliant feature explained here where you can automatically enable sleep on boot and restart the countdown every time you press a key.

I wanted this on Volumio, so I wrote a Python client that connects to the socket.io server and enables sleep if it’s not already enabled on every play event. This is triggered when you start playing a track or when it skips to the next track. I used the brilliant mpdcron app to listen for the events as it’s very simple to install and use and seems pretty bulletproof.

I’m sure this could all have been done using curl or something within the mpdcron player hook script, but I’ve got much more experience in Python than bash so this was easier for me!

Rather than post it here directly, I’ve put the code and detailed installation instructions on Githubh here.

I’d love to hear if anyone uses this. I’m more than happy for people to fork my code and modify it if you include references to the original and if anyone wants to turn this into a plugin: brilliant! Go for it! That way upgrades etc won’t affect it hopefully.

I’ve posted this as a suggested feature here, but I’m impatient and implemented my own version. :joy:

Hi,
Thanks for sharing, one remark though.
Why not locating the file in /home/volumio instead of a location that you only have?
SLEEP_TIME_FILE="/media/32GB-USB/mpd_sleep_time.txt"

Thanks for your message. You can put it wherever you want, but I have mine on a mounted USB drive as that’s shared automatically by Volumio. I covered all that and how to change it on the github. I wanted it easy to change the sleep settings without having to use ssh to get to it.

I modified the default path to be the home folder as everyone already has that, but it’s best on a shared path.