XBMC Idle detection
#1
Hi,

I am trying to figure out a reliable way to tell from either from the command line or the HTTP API, whether XBMC is totally idle, so not playing anything (music or video).

Basically i want to write a script to shutdown/suspend the machine if XBMC has not played anything for 30 mins. I have other processes running on this machine and it will be easy to check if they are idle but I have not been able to find a way to check XBMC.

I did see System.IdleTime(time) and tried this using wget but regardless of what time i put in, it returns OK.

Any ideas how i could achieve this?
ASRock Ion 330 | 6TB Drobo | Pioneer PDP-4270XD (s/pdif) | Sony DAV-DZ810W | Logitech Harmony 885 (MCE remote emulation)| diNovo Mini
Reply
#2
As poorly named as it may be...what's wrong with the settings > system > "shutdown function timer" setting?
Reply
#3
Funnily enough I spent about 20 minutes trying to figure that out today.

I totally agree it's very poorly named and a name change would help. IMO something like "action on idle" would be more appropriate (albeit grammatically incorrect Smile )
Also it's placement in the menus should be discussed, as I think it's more appropriate to place it together with the screensaver section (as this is where many OSes currently have them) or at least have a link from to the other and vice versa.
Reply
#4
althekiller Wrote:As poorly named as it may be...what's wrong with the settings > system > "shutdown function timer" setting?

Absolutely nothing if XBMC was the only process running on the machine. I have Myth running on the same machine so i need to check that it is not recording something when the shutdown occurs. I also have other processes such as hellanzb that could be downloading something, so i am trying to write a script that will check that hellanzb is not downloading anything, myth is not recording anything and then check if XBMC is idle and i am not watching something. If all of these are idle (and have been for x), shutdown/suspend.
Even if it was just XBMC on the machine and nothing else, i would like a non manual shutdown to occur after x as often i get caught up in something else or go out and forget to shutdown. With the new DPMS option in screensaver my tv get shut off saving about 100w per hour but i could save another 100w per hour if i could get the media center to detect it is idle and shutdown.

Im happy (and looking) to put a script in cron and have it check if all 3 processes are idle and shutdown. The System.IdleTime(time) function looked to be the most promising if it could be called via HTTP API as it looked to be able to determine how long in seconds XBMC was idle for so i could specify x then if true, shutdown, if false, terminate and wait until the script is ran from cron again checking all factors once more.
ASRock Ion 330 | 6TB Drobo | Pioneer PDP-4270XD (s/pdif) | Sony DAV-DZ810W | Logitech Harmony 885 (MCE remote emulation)| diNovo Mini
Reply
#5
The HTTP API returns the currently playing item with "xbmcHttp?command=getcurrentlyplaying" and the current slide with "xbmcHttp?command=getcurrentslide". Maybe you could use a combination of both to poll XBMC?
Always read the XBMC online-manual, FAQ and search the forum before posting.
Please read and follow the forum rules.
For troubleshooting and bug reporting, please make sure you read this first.


Image
Reply
#6
I created a patch for this feature .... http://trac.xbmc.org/ticket/5969 ...
Reply
#7
shagworthy_uk Wrote:Absolutely nothing if XBMC was the only process running on the machine. I have Myth running on the same machine so i need to check that it is not recording something when the shutdown occurs. I also have other processes such as hellanzb that could be downloading something, so i am trying to write a script that will check that hellanzb is not downloading anything, myth is not recording anything and then check if XBMC is idle and i am not watching something. If all of these are idle (and have been for x), shutdown/suspend.
Even if it was just XBMC on the machine and nothing else, i would like a non manual shutdown to occur after x as often i get caught up in something else or go out and forget to shutdown. With the new DPMS option in screensaver my tv get shut off saving about 100w per hour but i could save another 100w per hour if i could get the media center to detect it is idle and shutdown.

Im happy (and looking) to put a script in cron and have it check if all 3 processes are idle and shutdown. The System.IdleTime(time) function looked to be the most promising if it could be called via HTTP API as it looked to be able to determine how long in seconds XBMC was idle for so i could specify x then if true, shutdown, if false, terminate and wait until the script is ran from cron again checking all factors once more.

I would do it the opposite way then. MythBackend have a Check before shutdown and can do idle shutdowns. The Check could be a script quering http api as d4rk said.
If you have problems please read this before posting

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

Image

"Well Im gonna download the code and look at it a bit but I'm certainly not a really good C/C++ programer but I'd help as much as I can, I mostly write in C#."
Reply
#8
These are great solutions. I will give them a go over the weekend. Thanks (everyone) for your help!
ASRock Ion 330 | 6TB Drobo | Pioneer PDP-4270XD (s/pdif) | Sony DAV-DZ810W | Logitech Harmony 885 (MCE remote emulation)| diNovo Mini
Reply
#9
shagworthy_uk Wrote:Absolutely nothing if XBMC was the only process running on the machine. I have Myth running on the same machine so i need to check that it is not recording something when the shutdown occurs. I also have other processes...

This is where it helps everyone involved when you are COMPLETELY clear as to what your aim is right off the bat.
Reply
#10
I think he was fairly clear in his first post.
Quote:I have other processes running on this machine and it will be easy to check if they are idle but I have not been able to find a way to check XBMC.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Please read and follow the forum rules.
For troubleshooting and bug reporting, please make sure you read this first.


Image
Reply
#11
d4rk Wrote:I think he was fairly clear in his first post.

This is where it helps to NOT read the forums right after you wake up. Smile
Reply
#12
shagworthy_uk Wrote:These are great solutions. I will give them a go over the weekend. Thanks (everyone) for your help!

Shagworthy,

I was wondering how you got on setting this up? As I've just been puzzling over how to do pretty much the same thing whilst heading into work.

Checking the XBMC idle with a script and using the Myth idle timer seems to be the best approach to get what I want. However, have you looked into how to manually shutdown the box from within the XBMC interface whilst ensuring that myth will write the startup time to the RTC?

~Dan
Please ignore the specs in my sig, just noticed how out of date they are :oo:

XBMC 10.5 r31718 (Compiled) + Transparency! 3.06, Ubuntu Minimal Server 9.11 Karmic (2.6.31-22-generic)

Asus AT3N7A-I ION Motherboard, Intel Atom 330, 4GB (2x2GB) Corsair TwinX XMS2 DDR2 PC2-6400 (800), GeForce 8300 mGPU (Built-in), 320 GB Fujitsu MHZ2320BH Notebook 2.5" SATA, LG GGC-H20L Blu-Ray & HD-ROM, PicoPSU 120W Red
Reply
#13
I googled this old thread since I wanted to reach the same goal.

I eventually ended up letting XBMC/KODI to run the suspend command (on Ubuntu, it turns out to be "pm suspend") and then check if I really want to suspend or not from within pm suspend scripts:

Partial excerpt from /etc/pm/sleep.d/01_MythTV:
Code:
#!/bin/sh
PRE=01-MythTV
echo "$PRE: running as `whoami`."

if [ "$1" = "suspend" ]; then
# Check if we can suspend
if ! DISPLAY=:0 su -c "/usr/local/bin/mk_xbmc-idle.sh" myth01; then
   echo "$PRE: mk_xbmc-idle.sh returned non-zero status."
   exit 1
else
   echo "$PRE: mk_xbmc-idle.sh returned zero status, continueing suspend..."
fi

... the script continues here as needed ...

When this scripts exits with "1", KODI continues to run and the system does not suspend. KODI then tries to suspend again after its shutdown timer expires.

The script mk_xbmc-idle.sh checks various things - it is basically runs "mythshutdown --status" and few other checks (I use the HTPC as a regular computer, too, and need to block shutdown e.g. when another user is connected through SSH, etc.).
Reply

Logout Mark Read Team Forum Stats Members Help
XBMC Idle detection0