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.
Thanks for sharing, one remark though.
Why not locating the file in
/home/volumio instead of a location that you only have?
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.
If you want this to work with triggerhappy instead of on play :
I spend some time searching for a sollution (no program skills) so i tought id share for fellow noobs
systemctl disable mpdcron.service
sudo nano /etc/triggerhappy/triggers.d/audio.conf
KEY_A 1 /usr/local/bin/activate_sleep.py
Now this command needs root previllages, since triggerhappy executes everything with the user ‘nobody’.
nobody ALL= NOPASSWD: /usr/local/bin/activate_sleep.py
To check which key/code is being generated by you keyboard
> sudo thd --dump /dev/input/event*
Anyone has an idea why my players always shuts down instead of stopping the music ?
I adjusted the sleep menu - activity to stop music but this doenst help.