script to pause only if playing

I’m controlling volumio via steering wheel controls with an arduino.

Currently when I turn the ignition off, it sends a stop command, then a backlight off command and then waits for 30 minutes to see if I start the car again, otherwise it send a shutdown command then finally cuts the power.

My issue is that Stop resets the position in the playing track - not an issue for music but painful with a podcast. I don’t want to use Toggle so that if nothing was playing, I don’t then want it to start.

I want to write a script that reads the status -

Pseudo code:
if (volumio status == play) {volumio toggle}

I’m new to linux, and don’t know the correct syntax.

That is strange behaviour. I tried it with the REST API, and even after multiple stop commands I cannot get Volumio to jump back to the first track in the queue.
You can also try ‘pause’ instead of stop first, see if that fixes it.

Otherwise it is easily solved in the script. The API’s have an option to request the current state, including the playback status. See the docs:
Simply check this status first and only send the stop/pause command if the status is actually playing.

This isn’t actually Linux, it’s more on the Arduino side of things. Maybe you can share a bit of code from the turn-off-ignition-part, if you need more help with that?