Help me get started with (simple?) script!

Hello everyone,

Trying to keep this as short as possible:
Been using Volumio for a long time, mainly with Spotify connect with an older RPI. Now I’ve gotten a Pi zero with a justboom card which (after some transformer signal isolation) seems to work good. I’ve been using Nocs NS2 speakers, which have been abandoned since long by its developers, but luckily there is an AUX input. Not as luckily, they turn themselves off after 20 minutes if no sound is played. Also bad is the fact that the USB which powers the RPI shuts down along with them.

  1. In order to keep them always on, I would need to play a sound every 10 minutes or so, hopefully a short 30hz or so sound will work without being audible. However, this should only happen when no other sound is playing. I would need some simple pointers to get started:

    • Which scripting language would work nicely alongside Volumio2, is javascript preferred? Do I need to download any further packages and stuff
      to be able to run the script at startup? I know some basic programming/scripting and often manage to figure out that part, but I am confused
      over linux and what can be done alongside Volumio.
    • Some pointer to a command to know if Volumio is playing (needs to detect volumio player, spotify connect as well as airplay!)
    • Some pointer for which command to play audio file, most reasonably stored locally (alternatively synthesized sound, but I assume this will be
      more complicated and overkill)
  2. I would like to schedule an alarm, but a bit more advanced than the built-in one, so would like to use IFTTT or similar service.
    Any reasonably easy way to hook Volumio up to IFTTT?

  3. If possible, the alarm should start play a specific spotify playlist. But I guess this is a bit more tricky to achieve…
    (Currently the integrated spotify plugin through browser does not work for me, cannot see or play playlists. - UPDATE: Followed these instructions and can now see playlists etc
    And even more optimal would be if this could be played with spotify connect. Any ideas?
    (I use iphone, and the “shortcut” automation service would be perfect with airplay if it actually worked as an automation, but currently it only sends notification with prompt to start action, not ideal when sleeping…)

Perhaps a messy explanation of what i’m trying to do, but if anyone has any ideas and quick pointers what to start reading up on it would be most welcome! Thanks in advance!

Hello again,

So managed to do following, not at all sure if this is considered a legit solution, but it seems as if I am close to solving this:

  1. I use a bash script scheduled in cron every 5th minute to play a wav-file with a sinewave at 45 hz:

prevol=$(volumio volume)

aplay -D plughw:CARD=sndrpijustboomd,DEV=0 ~/myScript/noise9.wav

if [ "$check" = "0" ];
volumio volume 40
aplay -D plughw:CARD=sndrpijustboomd,DEV=0 ~/myScript/noise9.wav
volumio volume $prevol
echo "sound played at" >> /home/volumio/myScript/log.log
echo "$date1" >> /home/volumio/myScript/log.log
echo "no sound played, possibly due to other audio playing, at:" >> /home/volumio/myScript/log.log
echo "$date1" >> /home/volumio/myScript/log.log

(If error - in this case when something is already playing - it skips playing sound at specific volume level)

Took some trial and error to find a compromise between how audible the sound is vs actually keeping speakers alive. This keeps the speakers alive past the 20 min limit, but unfortunately something is not reliable enough to keep them alive 24/7. Trying to figure out whether its the Pi or the speakers (which powers the pi) which dies first… any ideas regarding if this bash script should behave reliably?

2 & 3. Using node.js script which also is scheduled in cron (every weekday at certain time) I play one of the “my daily mix” playlists in Spotify:

var io=require('');

var socket= io.connect('http://kitchen-jam.local:3000');

//Report successful connection
socket.on('connect', function () {
      console.log('Client Connected')

//Report disconnection
socket.on('disconnect', function () {
          console.log('Client Disconnected')

var randList = Math.floor(Math.random() * 6);

switch(randList) {
        case 0:
                var listUri = "spotify:playlist:(URI link)";
                console.log('Daily Mix 1 playing');
        case 1:
                var listUri = "spotify:playlist:(URI link)";
                console.log('Daily Mix 2 playing');
        case 2:
                var listUri = "spotify:playlist:(URI link)";
                console.log('Daily Mix 3 playing');
        case 3:
                var listUri = "spotify:playlist:(URI link)";
                console.log('Daily Mix 4 playing');
        case 4:
                var listUri = "spotify:playlist:(URI link)";
                console.log('Daily Mix 5 playing');
        case 5:
                var listUri = "spotify:playlist:(URI link)";
                console.log('Daily Mix 6 playing');

socket.emit('volume', 28);

socket.emit('replaceAndPlay', {"name": "Spotify", "service": "spop", "uri": listUri});

Soo after some more investigation it seems as if the aplay command starts behaving strangely after the other script is run…

Normally the “noise” script is running fine through crontab. But it seems after playing the spotify script

socket.emit('replaceAndPlay', {"name": "Spotify", "service": "spop", "uri": listUri});

And later stopping the music, the noise file stops playing when scheduled.

The command:

playresponse1=$(aplay -D plughw:CARD=sndrpijustboomd,DEV=0 /home/volumio/myScript/noise12.wav 2>&1) 

Gives following response (saved in log file) Playing WAVE '/home/volumio/myScript/noise12.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
But is not playing any sound through the raspberry (or rather the justboom card).

I can hear 2 subtle “clicks” from the speaker instead of the sound it is supposed to play.
Is there anything I can add to the script to check and restart the service if something needs restarting etc?
Any ideas?