Screensaver that stops music playback

Hi, I am looking for a way to stop my pi (running osmc) from playing music when either the amp is turned off or no remote input is received for a long period of time (several hours).
I can get playback to stop when switching amp inputs (though switching back to kodi starts playback again), but not on powering off.
My TV is not cec enabled but my amp is and I use my amp remote to control kodi.
I looked at modifying a screensaver script to issue a stop command but this is over my head.
Is this an easy script to write or would it need cec support?
Thanks.

How do you want to determine if the amp is powered off without cec?
But as I understand your amp supports cec so you should be able to use it

Sorry I, meant would the cec support need to be upgraded at the kernel level to allow detection of power off or is it just a matter of writing something in Python to detect the power off state and send a stop command.
I know a little bit of Linux but nothing about Python.

Thanks.

cec-client can do this

libCEC also has a Python API. No firmware or kernel change should be necessary

Thanks for the pointers!
I am able to monitor the CEC status of my amp using echo “pow 5” | /usr/osmc/bin/cec-client -s -d 1 which gives me a status of ON or SUSPEND. Win!

I am also able to adjust the /system/peripherals.xml to add more options as per:

however can not get playback to pause or stop when either the amp is turned off (or the TV on another system).

Is there a way of poling the status of the amp and if the status is suspend, issue a STOP command to Kodi?
Likewise if there is no CEC activity (i.e. remote presses) for say, 3 hours.

Thanks.

Well most likely there are 100 methods to do that. What I would suggest is running a cronjob every minute that check the status via cec-client and then stop the playback with a json command http://kodi.wiki/view/JSON-RPC_API

I believe you should be able to quickly google that but if you ned help let me know.

Thanks fzinken.
I have had some success (but then again, it is 1am and I need to get up for work in 5 hours) :frowning:
I made a shell script:

#!/bin/bash
echo “pow 5” | /usr/osmc/bin/cec-client -s -d 1 | while read status
do
case “$status” in
standby) kodi-send --action=“stop”
esac
done

and call it every minute using crontab:
#*/1 * * * * sudo ./test.sh

And it all appears to work!!
My issue is that as soon as I use cec-client, I lose CEC control from my amp until I restart my pi.
Some searching leads me to believe that this is (or was) an issue.
Do you know if there is a workaround?

Cheers.

Does restarting mediacenter help? sudo systemctl restart mediacenter

Also check this thread

Well, it seems that I was trying to fix a simple problem with a complex (for me) solution… Which didn’t work anyway. I discovered that I can disable network standby on my receiver so just set a cron tab to ping my receiver hourly and run the kodi stop command if ‘0 packets received’. And it doesn’t break my remote!
Thanks for the assistance.

1 Like