XBMC on Pi: Add TV/monitor Power Save support when idle?

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
MilhouseVH Online
Posting Freak
Posts: 3,022
Joined: Jan 2011
Reputation: 71
Post: #61
(2014-03-07 23:21)vbat99 Wrote:  Seems it doesn't like calling my script if run from rc.local

It's calling your script OK, but the problem is that the PATH variable hasn't been set correctly now that its being called by rc.local, so cec-client can't be found when called from within your script.

Either set and export PATH in your startup script as it is defined for the user pi ("echo $PATH" to view it, then add "export PATH=<paths>" to you startup script, before the sleep), or alternatively specify the full path when calling cec-client in your /home/pi/mythtv.sh script - run "which cec-client" to see the full path and then use that full path when calling cec-client, ie. change:
Code:
echo "standby 0" | cec-client -s >/dev/nul
to
Code:
echo "standby 0" | /usr/bin/cec-client -s >/dev/nul

My choice would be to fix the PATH variable to avoid future problems, and running texturecache.py as the pi user (not root) would also avoid other problems (file ownership etc.) - maybe prefixing the call to texturecache.py with "su pi -c" will work, eg. "su pi -c /home/pi/texturecache.py @logfile=/home/pi/t3.txt etc."

Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
(This post was last modified: 2014-03-07 23:43 by MilhouseVH.)
find quote
vbat99 Offline
Posting Freak
Posts: 758
Joined: Aug 2009
Reputation: 20
Location: New Zealand
Post: #62
Had to find where cec-client was located and for Raspbmc its in a couple of locations:
Code:
pi@raspbmc:/$ find . -name cec-client
./opt/xbmc-bcm/xbmc-bin/bin/cec-client
./home/pi/.upgrade/xbmc-13-20140305-nc3/xbmc-bcm/xbmc-bin/bin/cec-client
./home/pi/.upgrade/xbmc-13-20140213-nc3-2/xbmc-bcm/xbmc-bin/bin/cec-client
./home/pi/.upgrade/xbmc-13-20140306-nc3b/xbmc-bcm/xbmc-bin/bin/cec-client
./home/pi/.upgrade/xbmc-13-20140228-nc3/xbmc-bcm/xbmc-bin/bin/cec-client

The .upgrade path isn't viable, so made changes and set as
Code:
#!/bin/bash

/opt/vc/bin/tvservice $1

case "$1" in
  "--off")        echo "standby 0" | /opt/xbmc-bmc/xbmc-bin/bin/cec-client -s >/dev/null;;
  "--preferred")    echo "on 0" | /opt/xbmc-bcm/xbmc-bin/bin/cec-client -s >/dev null;;
esac
echo "$(date) called with $1 param" >> /tmp/tvservice.log

But still have
Code:
2014-03-08 12:53:20.065752:Thread-1  : bin.tvservice (checking if TV is powered on) calling subprocess [/home/pi/mytv.sh --status]
2014-03-08 12:53:20.135903:Thread-1  : bin.tvservice response: [state 0x12001a [HDMI CEA (4) RGB lim 16:9], 1280x720 @ 60Hz, progressive]
2014-03-08 12:53:20.142789:Thread-1  : bin.tvservice (enabling/disabling HDMI) calling subprocess [/home/pi/mytv.sh --off]
2014-03-08 12:53:20.222834:Thread-1  : bin.tvservice response: [Powering off HDMI
/home/pi/mytv.sh: line 6: /opt/xbmc-bmc/xbmc-bin/bin/cec-client: No such file or directory]
2014-03-08 12:53:20.223948:Thread-1  : bin.tvservice (checking HDMI status) calling subprocess [/home/pi/mytv.sh --status]
2014-03-08 12:53:20.286904:Thread-1  : bin.tvservice response: [state 0x120002 [TV is off]]
2014-03-08 12:53:20.294417:Thread-1  : [DEBUG] HDMI is now off

Now, rc.local is
Code:
# By default this script does nothing.

sleep 20 && /home/pi/texturecache.py @logfile=/home/pi/t4.txt @debug=yes @xbmc.host=localhost @bin.tvservice=/home/pi/mytv.sh rbphdmi 420
exit 0
And I shoud change this to
Code:
sleep 20 && su pi -c /home/pi/texturecache.py @logfile=/home/pi/t4.txt @debug=yes @xbmc.host=localhost @bin.tvservice=/home/pi/mytv.sh rbphdmi 420
??

(Changed to 420 seconds so didn't have to wait as long)

Media Companion Dev.
Media Companion - XBMC Media Companion
find quote
MilhouseVH Online
Posting Freak
Posts: 3,022
Joined: Jan 2011
Reputation: 71
Post: #63
(2014-03-08 02:15)vbat99 Wrote:  Had to find where cec-client was located and for Raspbmc its in a couple of locations:
Code:
pi@raspbmc:/$ find . -name cec-client
./opt/xbmc-bcm/xbmc-bin/bin/cec-client
./home/pi/.upgrade/xbmc-13-20140305-nc3/xbmc-bcm/xbmc-bin/bin/cec-client
./home/pi/.upgrade/xbmc-13-20140213-nc3-2/xbmc-bcm/xbmc-bin/bin/cec-client
./home/pi/.upgrade/xbmc-13-20140306-nc3b/xbmc-bcm/xbmc-bin/bin/cec-client
./home/pi/.upgrade/xbmc-13-20140228-nc3/xbmc-bcm/xbmc-bin/bin/cec-client

The .upgrade path isn't viable, so made changes and set as
Code:
#!/bin/bash

/opt/vc/bin/tvservice $1

case "$1" in
  "--off")        echo "standby 0" | /opt/xbmc-bmc/xbmc-bin/bin/cec-client -s >/dev/null;;
  "--preferred")    echo "on 0" | /opt/xbmc-bcm/xbmc-bin/bin/cec-client -s >/dev null;;
esac
echo "$(date) called with $1 param" >> /tmp/tvservice.log

But still have
Code:
2014-03-08 12:53:20.065752:Thread-1  : bin.tvservice (checking if TV is powered on) calling subprocess [/home/pi/mytv.sh --status]
2014-03-08 12:53:20.135903:Thread-1  : bin.tvservice response: [state 0x12001a [HDMI CEA (4) RGB lim 16:9], 1280x720 @ 60Hz, progressive]
2014-03-08 12:53:20.142789:Thread-1  : bin.tvservice (enabling/disabling HDMI) calling subprocess [/home/pi/mytv.sh --off]
2014-03-08 12:53:20.222834:Thread-1  : bin.tvservice response: [Powering off HDMI
/home/pi/mytv.sh: line 6: /opt/xbmc-bmc/xbmc-bin/bin/cec-client: No such file or directory]
2014-03-08 12:53:20.223948:Thread-1  : bin.tvservice (checking HDMI status) calling subprocess [/home/pi/mytv.sh --status]
2014-03-08 12:53:20.286904:Thread-1  : bin.tvservice response: [state 0x120002 [TV is off]]
2014-03-08 12:53:20.294417:Thread-1  : [DEBUG] HDMI is now off

You've got a typo in the path for cec-client - it should be:
Code:
/opt/xbmc-bcm/xbmc-bin/bin/cec-client
but for --off you've typed:
Code:
/opt/xbmc-bmc/xbmc-bin/bin/cec-client
("/opt/xbmc-bmc" when it should be "/opt/xbmc-bcm")

(2014-03-08 02:15)vbat99 Wrote:  And I shoud change this to
Code:
sleep 20 && su pi -c /home/pi/texturecache.py @logfile=/home/pi/t4.txt @debug=yes @xbmc.host=localhost @bin.tvservice=/home/pi/mytv.sh rbphdmi 420
??

Actually, you may need to wrap the command being executed in quotes so that it's treated as one argument and not several:
Code:
sleep 20 && su pi -c '/home/pi/texturecache.py @logfile=/home/pi/t4.txt @debug=yes @xbmc.host=localhost @bin.tvservice=/home/pi/mytv.sh rbphdmi 420' &
Give it a go, it should work. Note also that I've added the & on the end which should cause su to fork a new process, other you might find that rc.local processing doesn't finish... in fact with that in mind, I'd change your startup script to be as follows:
Code:
(sleep 20 && su pi -c '/home/pi/texturecache.py @logfile=/home/pi/t4.txt @debug=yes @xbmc.host=localhost @bin.tvservice=/home/pi/mytv.sh rbphdmi 420') &

Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
(This post was last modified: 2014-03-08 02:33 by MilhouseVH.)
find quote
vbat99 Offline
Posting Freak
Posts: 758
Joined: Aug 2009
Reputation: 20
Location: New Zealand
Post: #64
YES!!! Yes yes yes!!!

It's A-Live!!

Thank you Sooooo much for persevering with me.

Don't know why I missed bmc suppose to be bcm I checked and re-checked before I posted. Dang it.

One Happy Chappy here!
(now to document it so I can remember it later.)

Media Companion Dev.
Media Companion - XBMC Media Companion
find quote
MilhouseVH Online
Posting Freak
Posts: 3,022
Joined: Jan 2011
Reputation: 71
Post: #65
Glad you got there in the end! Smile

Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
find quote
vbat99 Offline
Posting Freak
Posts: 758
Joined: Aug 2009
Reputation: 20
Location: New Zealand
Post: #66
So I got slammed at home the other night, when the wife switch from the Pi (HDMI1) to Freeview TV (HDMI3), and after 15 minutes, the Pi switched off the TV. LOL.

Took me like 5 seconds to realize what had happened, while I was getting dirty looks from the other end of the room.

So, a question
  • Is it possible for the Pi to detect what the current TV's input is, and if not HDMI1, don't send the
    Code:
    echo "standby 0"
    command?

Little bit of googling looks like I have to figure out cec-client.

If this is Off topic for this thread, let me know.

Media Companion Dev.
Media Companion - XBMC Media Companion
find quote
MilhouseVH Online
Posting Freak
Posts: 3,022
Joined: Jan 2011
Reputation: 71
Post: #67
(2014-03-17 00:08)vbat99 Wrote:  So, a question
  • Is it possible for the Pi to detect what the current TV's input is, and if not HDMI1, don't send the
    Code:
    echo "standby 0"
    command?

Little bit of googling looks like I have to figure out cec-client.

I would expect it is, the CEC-O-MATIC might provide some clues.

(2014-03-17 00:08)vbat99 Wrote:  If this is Off topic for this thread, let me know.

I'd say it has become OT as your remaining issues now concern generic CEC control rather than anything specific to enabling/disabling HDMI on the Pi when idle. Smile

A new thread with more appropriate title (and in the general section) may also get more eyes-on. Include a link here to any new thread as it may prove useful to anyone with the same problem.

Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
(This post was last modified: 2014-03-17 00:23 by MilhouseVH.)
find quote
vbat99 Offline
Posting Freak
Posts: 758
Joined: Aug 2009
Reputation: 20
Location: New Zealand
Post: #68
Thanks MilhouseVH

You've been a great help. Will post any relevant info here for future reference to other users.

Media Companion Dev.
Media Companion - XBMC Media Companion
find quote
schumi2004 Offline
Posting Freak
Posts: 1,055
Joined: Aug 2011
Reputation: 9
Post: #69
(2014-03-17 00:28)vbat99 Wrote:  Thanks MilhouseVH

You've been a great help. Will post any relevant info here for future reference to other users.

Nevermind. I'm running OpenELEC and this is for Raspbmc, right?

[Image: all-thin-banner.jpg]
(This post was last modified: 2014-04-11 17:19 by schumi2004.)
find quote
MilhouseVH Online
Posting Freak
Posts: 3,022
Joined: Jan 2011
Reputation: 71
Post: #70
(2014-04-11 17:10)schumi2004 Wrote:  Nevermind. I'm running OpenELEC and this is for Raspbmc, right?

No, it should work with any Raspberry Pi distribution.

It's thoroughly tested on OpenELEC, but also works on Raspbmc with a bit of tweaking (basically just specify the location of the tvservice binary, and remove the unecessary delay that Raspbmc introduces before xbmc is restarted). No reason why it shouldn't also work with Xbian and Raspbian.

For OpenELEC, just follow the original instructions in post #12.

Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
find quote
Post Reply