• 1
  • 4
  • 5
  • 6(current)
  • 7
  • 8
  • 11
XBMC on Pi: Add TV/monitor Power Save support when idle?
#76
@MilhouseVH

So I take it I need to change the command in rc.local from
Code:
sleep 20 && /home/pi/texturecache.py @logfile=/home/pi/t6.txt @debug=yes @xbmc.host=localhost @bin.tvservice=/home/pi/mytv.sh rbphdmi 420
to
Code:
sleep 20 && /home/pi/texturecache.py @logfile=/home/pi/t6.txt @debug=yes @xbmc.host=localhost @bin.vcgencmd=/opt/vc/bin/vcgencmd @bin.ceccontrol=/home/pi/mytv.sh rbphdmi 420

Main changes being adding of
@bin.vcgencmd=/opt/vc/bin/vcgencmd and changing of @bin.tvservice=/home/pi/mytv.sh to @bin.ceccontrol=/home/pi/mytv.sh
Noting that for Raspbmc vcgencmd is located in [b]/opt/vc/bin/[b] folder, and my script is used to power off the TV if the HDMI port on the Pi is powered off (switched off), and my script is
Code:
#!/bin/bash

/opt/vc/bin/tvservice $1

case "$1" in
  "--off")        echo "standby 0" | /opt/xbmc-bcm/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

Does that seem right? Suppose I could give it a try, but don't want to annoy the wife if it goes wrong. LOL.
Media Companion Dev.
Media Companion - Kodi / XBMC - Media Companion
Reply
#77
I haven't tested on Raspbian, but I think you can get away with just the following:
Code:
sleep 20 && /home/pi/texturecache.py @logfile=/home/pi/t6.txt @debug=yes @xbmc.host=localhost @bin.ceccontrol=/home/pi/mytv.sh rbphdmi 420

assuming that tvservice and vcgencmd are both on your $PATH, which I think they should be, so the script will find them automatically.

If they're not on your PATH then specify the location of these two binaries with @bin.tvservice and @bin.vcgencmd.

Note also that the arguments passed to the @bin.ceccontrol script are now simply "on" and "off" whereas before it was "--preferred" and "--off", and the cec script no longer needs to call the "real" tvservice, so your cec script becomes:
Code:
#!/bin/bash

case "$1" in
  "off")      echo "standby 0" | /opt/xbmc-bcm/xbmc-bin/bin/cec-client -s >/dev/null;;
  "on")       echo "on 0" | /opt/xbmc-bcm/xbmc-bin/bin/cec-client -s >/dev/null;;
esac

echo "$(date) called with $1 param" >> /tmp/tvservice.log

One more thing - I haven't tried this add-on as I don't have a monitor that supports CEC, but it allows you to execute a limited number of CEC commands using JSON and the XBMC CEC "channel". Once installed, the following should then work:
Code:
./texturecache.py exec script.json-cec command=activate

The three "commands" supported by the addon are:
Code:
activate -> xbmc.executebuiltin('CECActivateSource')
toggle -> xbmc.executebuiltin('CECToggleState')
standby -> xbmc.executebuiltin('CECStandby')
Not sure if this is of use to you or not, I'm not even sure what the commands do, but it might avoid any problems resulting from the use of cec-client and subsequent "breakage" of the CEC communication channel.
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.
Reply
#78
Think I'll stick with one solution right now.

I did an echo $Path but that only returned an empty line.
So with that I assume $Path is not set in Raspbmc.
so I'll try this in rc.local
Code:
sleep 20 && /home/pi/texturecache.py @logfile=/home/pi/t6.txt @debug=yes @xbmc.host=localhost @bin.vcgencmd=/opt/vc/bin/vcgencmd @bin.tvservice=/opt/vc/bin/tvservice @bin.ceccontrol=/home/pi/mytv.sh rbphdmi 420

I'll look at the log file and see if anything weird occurs in it.
Media Companion Dev.
Media Companion - Kodi / XBMC - Media Companion
Reply
#79
It's case sensitive, so $PATH not $Path.

Just try "which vcgencmd" and "which tvservice" to see if they're "on your PATH" - if you get nothing back, then they're not on your path.
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.
Reply
#80
That didn't quite work. It turned off the Pi HDMI, but the TV remained on.
Pressing a button on the remote, and the Pi Rebooted.
Debug log Here

I updated to miappa's build, which should have updated the start and fix files.

Not sure about the kernel.

Result of echo $PATH
Code:
pi@raspbmc:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/opt/vc/bin:/home/pi/.xbmc-current/xbmc-bin/bin
pi@raspbmc:~$
Media Companion Dev.
Media Companion - Kodi / XBMC - Media Companion
Reply
#81
You haven't updated your cec control script as I outlined in post #77 - your script is still calling tvservice and ignoring the new parameters ("on" and "off").

Also your current firmware doesn't support "vcgencmd display_power" so rbphdmi will still be using the "old" behaviour (ie. calling @bin.tvservice to disable HDMI, also now calling @bin.ceccontrol, and restarting xbmc.bin when HDMI is re-enabled). You need firmware from 23 May 2014 onwards for the new functionality, which should kick in automatically with the way you have it configured (just fix up your cec control script).
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.
Reply
#82
with the changes, I can't seem to get the log file to write.
rc.local has
Code:
2014-05-25 10:26:00.430752:MainThread: Command line args: ['/home/pi/texturecache.py', '@logfile=/home/pi/t6.txt', '@debug=yes', '@xbmc.host=localhost', '@bin.ceccontrol=/home/pi/mytv.sh', 'rbphdmi', '300']
2014-05-25 10:26:00.431864:MainThread: Current version #: v1.6.1
2014-05-25 10:26:00.432612:MainThread: Current platform : linux2
2014-05-25 10:26:00.433420:MainThread: Python  version #: v2.7.3.0 (final)
2014-05-25 10:26:00.448360:MainThread: RPC connection established with IPv6
2014-05-25 10:26:00.449786:MainThread: libVersion.JSON SOCKET REQUEST: [{"jsonrpc": "2.0", "method": "JSONRPC.Version", "id": "libVersion"}]
2014-05-25 10:26:00.453476:MainThread: libVersion.BUFFER RECEIVED (len 89)
2014-05-25 10:26:00.455039:MainThread: libVersion.PARSING JSON DATA: {"id":"libVersion","jsonrpc":"2.0","result":{"version":{"major":6,"minor":15,"patch":3}}}
2014-05-25 10:26:00.456123:MainThread: libVersion.PARSING COMPLETE, elapsed time: 0.001589 seconds
2014-05-25 10:26:00.462255:MainThread: libVersion.FINISHED, elapsed time: 0.008938 seconds
2014-05-25 10:26:00.464043:MainThread: libPVR.JSON SOCKET REQUEST: [{"jsonrpc": "2.0", "params": {"booleans": ["System.GetBool(pvrmanager.enabled)"]}, "method": "XBMC.GetInfoBooleans", "id": "libPVR"}]
2014-05-25 10:26:00.501594:MainThread: libPVR.BUFFER RECEIVED (len 85)
2014-05-25 10:26:00.502828:MainThread: libPVR.PARSING JSON DATA: {"id":"libPVR","jsonrpc":"2.0","result":{"System.GetBool(pvrmanager.enabled)":false}}
2014-05-25 10:26:00.503814:MainThread: libPVR.PARSING COMPLETE, elapsed time: 0.001210 seconds
2014-05-25 10:26:00.504724:MainThread: libPVR.FINISHED, elapsed time: 0.039727 seconds
2014-05-25 10:26:00.505911:MainThread: JSON CAPABILITIES: {'isodates': True, 'texturedb': True, 'setseason': True, 'setresume': True, 'filternullval': True, 'removeart': True, 'setmovieset': True}
and is owned by root

Changing the start in rc.local to
Code:
sleep 20 && su pi -c '/home/pi/texturecache.py @logfile=/home/pi/t6.txt @debug=yes @xbmc.host=localhost @bin.ceccontrol=/home/pi/mytv.sh rbphdmi 300'
ie: adding su pi -c and wrapping the command in ' still has the same lines, but owner is now pi

Thoughts?
Media Companion Dev.
Media Companion - Kodi / XBMC - Media Companion
Reply
#83
Just delete the logfile owned by root (sudo rm /home/pi/t6.txt)

How have you been running texturecache.py up until now? As root? Eeek. Yes, you want "su pi -c '...'" in rc.local in order to run it under pi. This should then re-create the logfile but now owned by pi not root.
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.
Reply
#84
Was running as su pi -c before, so added this to the rc.local line, and change the logfile to t8.txt.

ran /etc/rc.local to kick it off again and got this message
Quote:pi@raspbmc:~$ ./etc/rc.local
-bash: ./etc/rc.local: No such file or directory
pi@raspbmc:~$ /etc/rc.local
Password:
FATAL: The task you wish to perform requires a valid path specified
in the property "bin.tvservice".

The current value [None]
is either not set or cannot be accessed.

Check settings in properties file texturecache.cfg
pi@raspbmc:~$
Interestingly it asked for a password, probably cause it was a root owned file.
But the other message about bin.tvservice??
Media Companion Dev.
Media Companion - Kodi / XBMC - Media Companion
Reply
#85
Most likely your PATH variable has never been setup correctly for user pi (ie. didn't have /opt/vc/bin on it, probably missing one or two others too) and now texturecache.py isn't able to find the binaries automatically.

Either fix the PATH for user pi (which probably involves editing /home/pi/.profile or something), or - easiest solution, though only fixes this particular problem - pass the @bin.tvservice and @bin.vcgencmd paths on the command line when calling texturecache.py (or add them to texturecache.cfg).
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.
Reply
#86
Edited rc.local to this
Code:
sleep 5 && su pi -c '/home/pi/texturecache.py @logfile=/home/pi/t8.txt @debug=yes @bin.tvservice=/opt/vc/bin/tvservice @xbmc.host=localhost @bin.ceccontrol=/home/pi/mytv.sh rbphdmi 300'

and manually ran.
Quote:pi@raspbmc:~$ /etc/rc.local
Password:
2014-05-25 11:29:59.992334: [rbphdmi] HDMI Power off delay: 300 seconds (ignored when Can Suspend is yes)
2014-05-25 11:29:59.995501: [rbphdmi] Player OnStop delay : 5 seconds (ignored when Can Suspend is yes)
2014-05-25 11:29:59.997895: [rbphdmi] Path to tvservice : /opt/vc/bin/tvservice
2014-05-25 11:30:00.000410: [rbphdmi] Path to vcgencmd : None
2014-05-25 11:30:00.002692: [rbphdmi] Path to ceccontrol : /home/pi/mytv.sh
2014-05-25 11:30:00.006455: [rbphdmi] Connecting to XBMC on localhost...
2014-05-25 11:30:00.060144: [rbphdmi] Connected to XBMC
2014-05-25 11:30:00.065707: [rbphdmi] HDMI power management thread - initialising XBMC and HDMI state
2014-05-25 11:30:00.220157: [rbphdmi] HDMI is [on], Screensaver is [active], Player is [inactive], Library scan [inactive], CanSuspend [no], CanDisable [no]
2014-05-25 11:30:00.223147: [rbphdmi] HDMI power off in 300 seconds unless cancelled
2014-05-25 11:35:00.333746: [rbphdmi] HDMI is now off
2014-05-25 11:41:12.646337: [rbphdmi] Screensaver has deactivated
2014-05-25 11:41:12.651130: [rbphdmi] Sending Application.Quit() to XBMC
2014-05-25 11:41:12.746786: [rbphdmi] XBMC exited - waiting for restart...
2014-05-25 11:41:12.977021: [rbphdmi] HDMI is now on
2014-05-25 11:41:27.779571: [rbphdmi] XBMC not responding, retries remaining 12
2014-05-25 11:41:32.805091: [rbphdmi] Connected to XBMC
2014-05-25 11:41:32.807855: [rbphdmi] HDMI power management thread - initialising XBMC and HDMI state
2014-05-25 11:41:32.940959: [rbphdmi] HDMI is [on], Screensaver is [inactive], Player is [inactive], Library scan [inactive], CanSuspend [no], CanDisable [no]
Interestingly, 2014-05-25 11:41:12.651130: [rbphdmi] Sending Application.Quit() to XBMC so Raspbmc restarted.

Please note, I am still a beginner on Linux, so am piecing together all info and how to's as I go.
Latest log

Code:
pi@raspbmc:~$ uname -a
Linux raspbmc 3.10.36 #4 PREEMPT Sun Apr 13 21:25:32 UTC 2014 armv6l GNU/Linux

Code:
pi@raspbmc:~$ vcgencmd version
May 23 2014 19:17:25
Copyright (c) 2012 Broadcom
version 21d0de90961749983d49ec4e819a98a8ba4287fc (clean) (release)

mytv.sh
Code:
#!/bin/bash

case "$1" in
  "off")      echo "standby 0" | /opt/xbmc-bcm/xbmc-bin/bin/cec-client -s >/dev/null;;
  "on")       echo "on 0" | /opt/xbmc-bcm/xbmc-bin/bin/cec-client -s >/dev/null;;
esac

echo "$(date) called with $1 param" >> /tmp/tvservice.log

rc.local
Code:
sleep 5 && su pi -c '/home/pi/texturecache.py @logfile=/home/pi/t8.txt @debug=yes @bin.tvservice=/opt/vc/bin/tvservice @xbmc.host=localhost @bin.ceccontrol=/home/pi/mytv.sh rbphdmi 300'

Doh! did I need the @bin.vcgencmd also?
Media Companion Dev.
Media Companion - Kodi / XBMC - Media Companion
Reply
#87
Yes, I am an Idiot!

This in my rc.local
Code:
sleep 5 && su pi -c '/home/pi/texturecache.py @logfile=/home/pi/t8.txt @debug=yes @bin.tvservice=/opt/vc/bin/tvservice @bin.vcgencmd=/opt/vc/bin/vcgencmd @xbmc.host=localhost @bin.ceccontrol=/home/pi/mytv.sh rbphdmi 300'
and Working as it should.

Noticed in logfile, the last entry, anything to be concerned about? Oh, and texturecache.py updated to 1.6.2.
Code:
2014-05-25 11:54:26.904393:Thread-1  : [DEBUG] HDMI power off in 300 seconds unless cancelled
2014-05-25 11:59:26.906603:Thread-1  : bin.tvservice (checking if TV is powered on) calling subprocess [/opt/vc/bin/tvservice --status]
2014-05-25 11:59:26.934712:Thread-1  : bin.tvservice response: [state 0x12001a [HDMI CEA (4) RGB lim 16:9], 1280x720 @ 60.00Hz, progressive]
2014-05-25 11:59:26.941364:Thread-1  : bin.vcgencmd (enabling/disabling HDMI power) calling subprocess [/opt/vc/bin/vcgencmd display_power 0]
2014-05-25 11:59:26.971061:Thread-1  : bin.vcgencmd response: [display_power=0]
2014-05-25 11:59:26.973993:Thread-1  : [DEBUG] HDMI is now off
2014-05-25 11:59:26.976504:Thread-1  : [DEBUG] Executing CEC Control script [off]
2014-05-25 11:59:26.977376:Thread-1  : bin.ceccontrol calling subprocess [/home/pi/mytv.sh off]
2014-05-25 11:59:30.456986:Thread-1  : bin.ceccontrol response: []
2014-05-25 12:00:36.948198:MainThread: libListen.BUFFER RECEIVED (len 97)
2014-05-25 12:00:36.949782:MainThread: libListen.PARSING JSON DATA: {"jsonrpc":"2.0","method":"GUI.OnScreensaverDeactivated","params":{"data":false,"sender":"xbmc"}}
2014-05-25 12:00:36.950914:MainThread: libListen.PARSING COMPLETE, elapsed time: 0.001434 seconds
2014-05-25 12:00:36.951933:MainThread: libListen.PERFORMING CALLBACK: Name [rbphdmi_listen], with Id [None], Method [GUI.OnScreensaverDeactivated], Params [{u'data': False, u'sender': u'xbmc'}]
2014-05-25 12:00:36.966542:Thread-1  : [DEBUG] Screensaver has deactivated
2014-05-25 12:00:36.967910:Thread-1  : bin.vcgencmd (enabling/disabling HDMI power) calling subprocess [/opt/vc/bin/vcgencmd display_power 1]
2014-05-25 12:00:36.971660:MainThread: libListen.CALLBACK RESULT: [False] Name [rbphdmi_listen], Id [None], Method [GUI.OnScreensaverDeactivated], Params [{u'data': False, u'sender': u'xbmc'}]
2014-05-25 12:00:36.972665:MainThread: libListen.READING SOCKET UNTIL CALLBACK SUCCEEDS...
2014-05-25 12:00:37.033763:Thread-1  : bin.vcgencmd response: [display_power=1]
2014-05-25 12:00:37.040675:Thread-1  : [DEBUG] HDMI is now on
2014-05-25 12:00:37.044822:Thread-1  : [DEBUG] Executing CEC Control script [on]
2014-05-25 12:00:37.045721:Thread-1  : bin.ceccontrol calling subprocess [/home/pi/mytv.sh on]
2014-05-25 12:00:40.761386:Thread-1  : bin.ceccontrol response: [/home/pi/mytv.sh: line 3:  2123 Done                    echo "on 0"
      2124 Segmentation fault      | /opt/xbmc-bcm/xbmc-bin/bin/cec-client -s > /dev/null]
Media Companion Dev.
Media Companion - Kodi / XBMC - Media Companion
Reply
#88
(2014-05-25, 02:05)vbat99 Wrote: and Working as it should.

Smashing. Smile

(2014-05-25, 02:05)vbat99 Wrote: Oh, and texturecache.py updated to 1.6.2.

Just a minor change to enable HDMI and call ceccontrol before sending Application.Quit() to xbmc.bin (rather than after) to benefit those users with pre-23 May firmware. Basically, this change allows the cec control script to communicate with xbmc.bin before xbmc.bin is terminated (kind of hard afterwards). Shouldn't affect anyone using new firmware and vcgencmd (such as yourself).

(2014-05-25, 02:05)vbat99 Wrote: Noticed in logfile, the last entry, anything to be concerned about?
Code:
2014-05-25 12:00:40.761386:Thread-1  : bin.ceccontrol response: [/home/pi/mytv.sh: line 3:  2123 Done                    echo "on 0"
      2124 Segmentation fault      | /opt/xbmc-bcm/xbmc-bin/bin/cec-client -s > /dev/null]
Yes, probably - that's not good. This looks like cec-client is crashing. You might want to investigate that further, I can't really help much more here I'm afraid. It could be a consequence of xbmc.bin already communicating with the CEC device, so you might want to try the addon approach so that only xbmc.bin is communicating with the CEC device.

Unlike before, xbmc.bin isn't being restarted so the state of the CEC communication channel may now be left in an indeterminate state by the mixture of xbmc.bin communication and cec-client communication. As we know, when you use cec-client you break xbmc.bin communication. Try the addon.
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.
Reply
#89
I'll look into the json-cec script in a couple of days.

For now, I'll monitor the log file, and take note if any issues occur due to that Seg fault.

Thanks so much for your help.
Media Companion Dev.
Media Companion - Kodi / XBMC - Media Companion
Reply
#90
Thank you for the script, it works fine for me.

Suggestion for a new version:
Maybe you could also handle the key "0 / Off" key to disable HDMI output.

I use a Zotac remote for all OpenElec/XBMC devices, and every station uses the same key mapping, so I would not like to modify that on the RPi devices.
According to the console "irw" command, the name of the key is "74 0 KEY_POWER".

I am not familiar with the JSON output, but maybe the keypress also is logged there and you could handle it in the script?

Thank you
Reply
  • 1
  • 4
  • 5
  • 6(current)
  • 7
  • 8
  • 11

Logout Mark Read Team Forum Stats Members Help
XBMC on Pi: Add TV/monitor Power Save support when idle?1