First requirement is python. There is an extension in PiCorePlayer.
We will be continuously checking the state of the soundcard. For this to work the squeezelite parameter '-C <n>' is required to tell squeezelite to release the soundcard after n seconds.
Get the script:
wget https://raw.githubusercontent.com/rawdlite/niche-audio/refs/heads/main/setup/check4sound/check4sound.pyEdit SOUNDCARD_DEVICE_FILE and SHUTDOWN_TIMEOUT to the required values and make it executable.
chmod u+x check4sound.py
For greater flexibility the script calls subprocesses start.sh and stop.sh. I am using Shelly Plugs, as they are easy to control via http and do not need a hub or external API service. The start script is as simple as:
curl http://192.168.2.203/relay/0?turn=on
There is a global DEBUG Variable that helps finding out what is going on, when started from the command line. When everything works, set the DEBUG Variable back to false.
In PiCorePlayer add '/home/tc/check4sound.py' to the User commands on the Tweaks page.
On other players setup a service or use supervisor.