How to pull state of tv via CEC

Evening,

I just installed OSMC on my pi 4 and I have been reading up on things that I want to do with it. Before, I had a pi2 my dad set up with OSMC from quite a few years ago but never used it for anything but backlight control for my TV so I am a noob when it comes to OSMC/Kodi.

My pi is supposed to be always on running docker services and being used to turn on/off the tv with this.

Being always on, I don’t want to keep any playback running if I turn off the TV (or the TV turns itself off via timer) so I googled for a way to stop playback. I did find the setting in system > input > peripherals in this thread but it didn’t work as intended.

Reading further in said thread I found mention of /sys/class/amhdmitx which sounded like something I could use but I can’t find this on my pi at all. Looking through this forum the best I could find was this but that obviously wasn’t helpful. Google didn’t help any also, 2018 this was the way, and any later there is no mention of it anymore, or what succeeded it.

I looked through /sys/class myself and found some hdmi stuff in /sys/class/drm/card1-HDMI-A-1/ but only status did anything useful at all and that only gave me connected and disconnected as output. edid and modes gave me output, but I can’t see a way to use those to detect if my TV is on or in standby mode with those.

Ideally, I would like to find some hook to query the tv state that doesn’t break cec control via tv remote and then use that to stop playback (and maybe set kodi to the main screen so I don’t have to back out whichever menu I was in when I turn the tv on).

This hook seemed to be amhdmitx but what succeeded it?

amhdmitx refers to AMLogic HDMI TX. You’ll only find this interface on AMLogic based SoC devices, such as Vero.

Then what do I do on a pi to check the status of the connected device ( and how the hell did I find posts of ppl having this on pis via google)?

It can’t exist on Pi.

You need to use the new DRM sysfs interface to monitor things now.

So basically what I found and can’t use because nothing I can see there reports anything different with the TV on or off… The statetopic gives of only connected or disconnected and if I try /card1-Writeback-1/state it is always unknow. Seems my best hope is find something that can actually display the edid output and hope there is a difference there.

tvservice might be able to do it still.

Excuse me if I’m missing something here and am posting something that doesn’t fit into your use case (which I’ve not quite rapped my head around).

So your using cec-client to turn your TV on/off but that breaks CEC in Kodi so you can’t use the automatic stopping playback in Kodi’s CEC settings. Is it a viable solution to just use Kodi to turn the TV on/off instead with

kodi-send -a "CECActivateSource"
kodi-send -a "CECStandby"

thereby removing the need to use cec-client and discover current TV state as those commands essentially act as dedicated power states instead of a power toggle.

I am not using cec-client at all, and so far I haven’t even tried turning the tv on or off via kodi, that is a future project. Right now I am looking for a way to monitor the status of my tv via cec so that I can stop playback and navigate back to the main menu for the next time I want to use kodi with the tv.

The only solution I saw so far, outside of the vero-only solution, was the use of cec-client monitoring but that is known to break cec for kodi and I need that working

Sadly, it does not seem so. Only thing I can get are a status and an edid dump. Monitoring cec does not work, I tried with sudo and without but I did not see anything when turning the tv on or off or using the tv remote with kodi. List is always empty, and without an id from list device is a no go, too. The power off from tvservice is also broken. I don’t think this is usable right now.

The link under “this” you posted says your using cec-client to turn the TV on/off

The first time you cec-client in OSMC it breaks CEC in Kodi until you reboot. Is running that in docker mitigating that problem?

Note the supposed to, it is not implemented and apparently this was the wrong link. It was supposed to go to a thread of how to use this script with my house automation on another pi. Apparently I saved the wrong link from their forum. I did the research into this a few weeks ago and did not re-read my saved link today.

Also, nothing of this will run in a docker, the docker was thrown in there as a reason why the pi is supposed to always be on, because I will run completely unrelated services on there. This misunderstanding is my fault, for not considering how my sentence can be read in other ways than the one I intended in English.

Gotcha. So just to back up a bit on the issue, are you sure CEC is enabled on the TV and in Kodi and working? I use the stop playback on TV switch off and change source CEC settings and tested it recently and it was working as it should.

I am sure cec is working, after all, I have been using my tv remote to interact with kodi. That should not be possible without cec (or if it is, my understanding of cec is completely wrong). I do know cec is turned on on the tv because I had a FireTV stick in the same port 2 weeks ago to test exactly that. And since the pi responds to the tv remote signal, it should be active there, also. The only thing I noticed is that it takes 30sec for the remote signal to reach kodi at all after I turn the tv on, but my guess is, that it needs this time to (re)activate it after edid ran through.

If the TV remote is interacting with Kodi then CEC is working but the 30 second thing is a bit odd. CEC is normally active on a TV even when it is off/low power which it would need to be in order for an external device to turn the TV on. You may have one of those TV’s that just are not as nice regarding CEC which is not uncommon. That may explain what the stopping playback is not working if the TV is not sending out that information when it turns off.

Okay, apparently some part of cec was turned off on the tv. Now I got at least the stop video to work. What I am still not sure on is how do I detect when the tv was turned on/off to in order to do other stuff (like navigation to the main menu)?

I also stopped kodi and used cec-client to monitor what if going on, both before and after I found the extra setting on my tv and this has me stumped.

Nothing happens until I turn the tv on once. Then I get

DEBUG:   [            8646]     CLinuxCECAdapterCommunication::Process - ioctl CEC_RECEIVE - rx_status=01 len=5 addr=0f opcode=87
TRAFFIC: [            8646]     >> 0f:87:00:e0:91
DEBUG:   [            8646]     TV (0): vendor = LG (00e091)
DEBUG:   [            8646]     >> TV (0) -> Broadcast (F): device vendor id (87)
DEBUG:   [            8646]     device TV (0) status changed to present after command device vendor id
DEBUG:   [            8646]     replacing the command handler for device 'TV' (0)
DEBUG:   [            8646]     TV (0): CEC version 1.3a
DEBUG:   [            8646]     TV (0): menu language set to 'eng'

Then it starts spamming regardless of the tv is turned on or off, but it needed to be on once.

DEBUG:   [           36200]     CLinuxCECAdapterCommunication::Process - ioctl CEC_RECEIVE - rx_status=01 len=5 addr=0f opcode=87
TRAFFIC: [           36200]     >> 0f:87:00:e0:91
DEBUG:   [           36200]     >> TV (0) -> Broadcast (F): device vendor id (87)

After changing the missing cec setting (cec was on but there was an extra setting for powering on/off other devices) I always get

DEBUG:   [          118723]     CLinuxCECAdapterCommunication::Process - ioctl CEC_RECEIVE - rx_status=01 len=4 addr=0f opcode=86
TRAFFIC: [          118723]     >> 0f:86:20:00
DEBUG:   [          118723]     >> TV (0) sets stream path to physical address 2000
DEBUG:   [          118724]     >> TV (0) -> Broadcast (F): set stream path (86)

in between of all that spamming.

But when I turn the tv off I only sometimes get

DEBUG:   [          154641]     CLinuxCECAdapterCommunication::Process - ioctl CEC_RECEIVE - rx_status=01 len=2 addr=0f opcode=36
TRAFFIC: [          154641]     >> 0f:36
NOTICE:  [          154641]     resetting SL initialised state
DEBUG:   [          154641]     Broadcast (F): power status changed from 'unknown' to 'in transition from standby to on'
DEBUG:   [          154641]     TV (0): power status changed from 'unknown' to 'standby'
DEBUG:   [          154641]     >> TV (0) -> Broadcast (F): standby (36)
DEBUG:   [          154713]     CLinuxCECAdapterCommunication::Process - ioctl CEC_RECEIVE - rx_status=01 len=2 addr=0f opcode=36
TRAFFIC: [          154713]     >> 0f:36
NOTICE:  [          154713]     resetting SL initialised state
DEBUG:   [          155820]     CLinuxCECAdapterCommunication::Process - ioctl CEC_RECEIVE - rx_status=01 len=2 addr=0f opcode=36
TRAFFIC: [          155820]     >> 0f:36
NOTICE:  [          155820]     resetting SL initialised state
DEBUG:   [          155892]     CLinuxCECAdapterCommunication::Process - ioctl CEC_RECEIVE - rx_status=01 len=2 addr=0f opcode=36
TRAFFIC: [          155892]     >> 0f:36
NOTICE:  [          155892]     resetting SL initialised state

Whatever does it need to transition from standby to on in order to go to standby? I only managed to get this message once when monitoring, the other times it didn’t output anything at all when turning off.