Bash command to stop playback (when tv is off)?

Hi,

I would like to automatically stop playback when I switch off my tv

The best solution I have found to detect the status of my TV is the script below. It ping 3 times my tv every 5 minutes and execute some commands if ping failed the 3 times. (“tvservice -s” or “tvservice -n” commands were my first candidates, but they don’t react to the standby mode of my samsung tv)

while true; do
ping -c 3 10.0.0.10 | grep “0 received” && kodi_stop_playback
sleep 300
done

The last pieces missings are the command in bold and a good way to launch the script. (I have try some kodi-send commands without succes…)

So I’ll be glad if a linux/bash/kodi/osmc wizard can help me

Thanks

Isnt pausing playback when the TV is turned to the mediaplayer channel an option in CEC?

xbmc-send --host=localhost --port=9777 --action=“PlayerControl(Stop)”

Should do the trick for the command. Of course you need to exchange the ip and port if necessary.

As for starting the script, you can register it as a systemd service.

There is an option in CEC to turn off/suspend when TV is switched off. But, (as tvservice), the standby mode of my TV doesn’t trigger it.

And there is another option that stop playback when TV source is switched that works, but, unfortunately, switching off the TV is not recognized as a source switch.

Thank you mcobit!