Kodi Community Forum
Help - Cec-client to identify Tv's current selected source - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: General Support (https://forum.kodi.tv/forumdisplay.php?fid=111)
+---- Forum: OS independent / Other (https://forum.kodi.tv/forumdisplay.php?fid=228)
+---- Thread: Help - Cec-client to identify Tv's current selected source (/showthread.php?tid=189391)



Help - Cec-client to identify Tv's current selected source - vbat99 - 2014-03-17

This is in the General thread as any help with my request may be of help to anyone with Pulse-Eight CEC control.

I have a Pi with Raspbmc installed, and with the help of MilhouseVH I have been able to get the Pi to power off the TV after 15 minutes of inactivity.

The Catch!. If the TV has been changed to another input, after 15 minutes, the Pi power's off the TV.

This is the current script I have, with help from MilhouseVH texturecache.py script which detects when the screensaver has been active for 15 minutes
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

What I am interested in, is somehow detecting if the TV is still on HDMI1 (the source the Pi is connected to), then run the
Code:
"--off")        echo "standby 0" | /opt/xbmc-bcm/xbmc-bin/bin/cec-client -s >/dev/null;;
otherwise skip this line.

I have had a look at CEC-O-MATIC, but can not figure if I can get the TV to report what it's current source is.

So, to the great XBMC community, I ask if someone who's familiar with libcec or cec-client, can point me in the right direction.


RE: Help - Cec-client to identify Tv's current selected source - mk01 - 2014-05-26

there is OPCODE 85 to ask devices for active source. each device is responsible to "report" itself if this is the case. because cec-client -s is not waiting for responses, your only chance is to use "scan" and grep last line from the output:

Code:
echo "scan" | cec-client -s | grep "currently active"

in your case this will be a bit tricky as the device which should send "i'm active source" is the one where you run cec-client -s - this means cec-client just started doesn't have a history in memory to know that it is active source.

so you can just assume that if you get (-1) - active source unknown - that it was this one RPI - and you can shut the TV down. solution would be to keep continuity (don't start & stop cec-client (cec-client -s)).

after XBMC's start start cec-client with redirected output and input to two files - IN and OUT:
Code:
cec-client  < IN >> OUT

then you can issue command with
Code:
echo "command" >> IN

by polling file "OUT" you get normal cec-client output. you can check working implementation here:
https://github.com/xbianonpi/xbian-package-xbmc-scripts/blob/master/content/etc/init/xbmc-screensaver.conf
and starting of cec
https://github.com/xbianonpi/xbian-package-xbmc-scripts/blob/master/content/etc/init/xbmc.conf (post-start section)


RE: Help - Cec-client to identify Tv's current selected source - andyj280 - 2019-08-29

(2014-05-26, 06:56)mk01 Wrote: there is OPCODE 85 to ask devices for active source. each device is responsible to "report" itself if this is the case. because cec-client -s is not waiting for responses, your only chance is to use "scan" and grep last line from the output:
Code:
echo "scan" | cec-client -s | grep "currently active"
  
When I use "tx 10:85" or "tx 1F:85" either by piping it to cec-client as a single command, or issuing the command to a running cec-client, the result is the same; no response.
But obviously the active source is  detectable, as the above method of "scan" and "grep" for active source does  work.

Does this mean that the OPCODE 85 command is broken and that a sequence of other commands is required instead?


RE: Help - Cec-client to identify Tv's current selected source - andyj280 - 2019-08-29

I have found an answer to my own question.
When the CEC adapter _or_ the TV is the source, I run into the above problem.

However, if I change to a DVD or Blu-Ray player, the broadcast message "1F:85" does indeed result in a response starting with OPCODE 82 followed by the physical address.