Help with CEC commands (N2)

My setup is: N2 (CE 9.2.5) -> Onkyo TX-NR575 AVR -> Panasonic GX800
Using premium quality HDMI cables. Using eARC for tv, so HDMI2 is used as input on tv.

I keep the N2 on all the time. I don’t really use the AVR that much, so the HDMI Passtrough is activated.
My issues is that CEC works perfectly fine until I switch input on tv other than HDMI2, like TV DVB-C. If I switch back, I loose cec in Kodi. I can do two things:

  1. In Pana TV menu select Viera link app and select the Player (that is N2) and CEC returns.
  2. In Yatse I select Activate CEC -> cec in Kodi start to work immeadiatelly

I also tried to ssh, and issue
echo r | cec-client -s -d 1
CEC restarts (quite slowly, compared to above two solutions, which are nearly instant), this takes about 10-15 seconds, but after it works again.

My idea is that somehow cec device is lost and not reconnected on input switch. Any ideas how to fix this?

Btw, anybody knows what command could Yatse send on Activate CEC option? Maybe doing a script, like when resuming from screensaver run the Activate CEC command. That would probably work.

Or what cec-client sommand should I use? Restart ® is slow.

How are you switching inputs? Via remote, home automation (Amazon Echo, Google Home, Home Assistant, etc.) or another method?

No, 90% I use the N2 and switch the HDMI/TV(DVB-C, Netflix, YouTube) on tv remote. And rarely switch avr to other input for xbox.

It’s possible using cec-client to switch the input might keep things “connected”, rather than directly with the TV. For instance, I had scripts that ran on my N2, and now on an H2 (running Kodi on a stripped-down Lubuntu), that switch the HDMI input on voice command (via Alexa). It’s a reverse situation than many, where the Odroid controls the TV via CEC rather than the TV control the Odroid. Those scripts are also linked to items in my shutdown menu on Kodi, so I can switch inputs and sleep the display directly from within the Kodi UI. Using a script also allows for the simultaneous on/off toggle of Hyperion. My TV remote collects dust in the corner as a result.

I’m not overly familiar with Yatse (not an Android user), but if Yatse is able to run shell scripts, you can use it as your gateway to HDMI switching. As long as your CE box/Kodi is running, even if it’s not the current input, it should still be able to switch inputs for you.

Apparently the hexadecimal codes can vary dependent on model of TV, but this is pretty common for many TVs:

echo "tx 4F:82:10:00" | cec-client -s -d 1

The third hexadecimal number (in the above case 10) represents input. HDMI-1 = “10”, HDMI-2 = “20”, HDMI-3 = “30”, etc.

Test it out; see if it stays connected. If it does, I can probably help you to set up a script to do it.

Many thanks! I will check the code you sent and report back!

OK, I checked the above command.

echo “tx 4F:82:10:00” | cec-client -s -d 1

I can swithc between HDMI inputs 1-2 by changing 10 and 20. So I have CEC and remote working on Kodi (HDMI2). I swithc using the above command to HDMI1 and back to 2, but sometimes I have remote, sometimes not. More often not.

What keeps working is the Activate CEC command that I can send with Yatse. But I don’t know what command is sent and how by Yatse. And if we figure this out somehow, still need to find a way to kick in the command. But maybe mapping to a not used button on the remote.

Indeed, whatever remote you’re using for Kodi should be able to have a script function mapped to it. Yatse seems to be just using the kodi built-in activate command, rather than addressing cec-client directly. It doesn’t look like Yatse can send SSH commands directly, but can send direct keyboard commands as custom buttons.

So what in theory should work is this:

  1. SSH into your CoreELEC box.
  2. Create a folder (not sure if this is a default folder on CE):

mkdir /storage/scripts

3a) Make a script in that folder:

nano /storage/scripts/changeinput.py

3c) C&P the following:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import os
import sys

if sys.argv[1:]:
        arg = sys.argv[1][:1]
        if not arg.isdigit():
                print("Don't try and be tricky.")
                exit()
        else:
                cecinput = "echo \"tx 4F:82:" + arg + "0:00\" | cec-client -s -d 1"
                os.system(cecinput)

else:
        print("We need an input [1-9].")
        exit()
  1. Make it executable:

chmod a+x /storage/scripts/changeinput.py

5a) Now, create the following file (if it doesn’t already exist):

nano /storage/userdata/keymaps/keyboard.xml

5b) Add (as needed if you already have the file):

<keymap>
	<global>
		<keyboard>
			<period>RunScript(/storage/scripts/changeinput.py,1)</period>
			<comma>RunScript(/storage/scripts/changeinput.py,2)</comma>
			<backslash>RunScript(/storage/scripts/changeinput.py,3)</backslash>
			<y>RunScript(/storage/scripts/changeinput.py,4)</y>
		</keyboard>
	</global>
</keymap>

if keyboard.xml already exists, just add all the stuff inside the < keyboard > tag.

  1. Here’s the part that I can’t really help with, as I don’t have access to Yatse. But using the info here to set it up, create a custom command for each input. They should be sent as keyboard keys. I’ve tried to use some of the more useless key commands for CE, but also ones accessible via a mobile keyboard. Yatse can only send key presses without modifier keys, otherwise they’d be set up as “one”,“two”,“three” with mod=“ctrl” added.

Info on how to set up custom commands is here:

My configuration:
Odroid-N2 -> Denon AVR -> Panasonic OLED TV (HDMI 2)
N2 is configured with CEC Wake-Up enabled so it is back online when I choose HDMI 2 on TV remote.
Sometimes when I power on TV (which automatically power on AVR) and immediately select HDMI 2 then CEC doesn’t work not reacting for TV remote buttons (but N2 is back online - I see it is starting responding for ping) Usually it works if I wait for 10-20 seconds at least and then go from TV source to HDMI 2 source.
In case I select HDMI 2 as the source (so I can see CoreElec) and CEC doesn’t work and I send “CEC Activate” command in Yatse TV is switching to HDMI 1 source where nothing is connected. Why “CEC Activate” command is causing TV to switching to HDMI 1 instead of HDMI 2?

If you’re using the script I posted above, then it’s likely you’re running it with the argument “1” which would switch the HDMI-1.

If this is unrelated to the script then I’m assuming the “CEC activate” YATSE command is set to HDMI-1.

I am curious to know why there’s nothing plugged into input 1 though. Is the jack in a hard to reach spot or something?

No, I wasn’t using your script.
I’m just reporting weird behavior: using Yatse I’m sending CEC Activate command to KODI which is running on Odroid-N2 connected through Denon AVR to HDMI-2 in TV and TV is switching to HDMI-1 input. Isn’t a weird result?
Regarding your statement “YATSE command is set to HDMI-1” - my assumption is that if I have configured Yatse to control Odroid-N2 via IP address then CEC activate command should be send to this device but is it configurable in Yatse which CEC line/input should be activated?
Why are you curious that I have nothing plugged to HDMI-1? A, OK, maybe you are surprise that I have AVR connected to HDMI-2 instead of HDMI-1? OK, then the answer is easy: because HDMI-2 is ARC but HDMI-1 is not :slight_smile:

It might just be that Kodi’s HDMI port number needs to be changed. I believe there’s supposed to be automatic detection there, but automatic redundancies are always a point of failure. Default is 1, but try changing it to 2 and see if that fixes the issue. You’ll find that in Settings -> System -> Input -> Peripherals -> CEC if memory serves correctly.

That all said, with ARC, the TV likes to be the “hub”, so it might be a competition issue between the AVR and the TV as to who’s controlling what. Technically, connecting the N2 to HDMI-1 and keeping the AVR on HDMI-2 should also work for Kodi’s audio, but you will lose any additional video-related functionality the AVR may be having on the N2.

1 Like

I had the same problem. Go to settings system peripherals, cec adapter and change the physical port from 1 to 2 and your cec will work fine.

Changing physical port from 0 to 2 in CEC Adapter settings is not permanent.
It is changing back to 0 after device reboot.
Is it a bug?

I just checked it a bit and it’s definitely broken.

So I checked my settings before changing physical address:

I changed it to just like 3. After OK I lost CEC connection and when I re-enter the options look now:


The options changed! Now I am able to set the HDMI port number and it’s set to default 1.

I see on my TV Kodi is now on HDMI1, but in “real” it’s on HDMI3. So I changed the HDMI port to 3 and CEC is working again now, physical address is still 0.

Ok, but now the next issue:

bPAAutoDetected is false, OK
m_configuration.baseDevice is NOT CECDEVICE_UNKNOWN -> useless
m_configuration.iHDMIPort < CEC_MIN_HDMI_PORTNUMBER -> useless
m_configuration.iHDMIPort > CEC_MAX_HDMI_PORTNUMBER -> useless

CEC_MIN_HDMI_PORTNUMBER is 1,
CEC_MAX_HDMI_PORTNUMBER is 15

The user is not able to set a number smaller then 1 or higher than 15.
So strPhysicalAddress("0") will be set every time as the condition is never met.

I guess this is wrong:

If iPhysicalAddress is set by user m_configuration.iHDMIPort need to be set to 0 (CEC_HDMI_PORTNUMBER_NONE), then it should work. Then iPhysicalAddress get higher priority over iHDMIPort. libCEC check first by else if HDMI port set, then afterwards by else if physical address is set. So this will never be hit if HDMI port is set to 1 - 15:

Physical addresses are valid from 0x1000 - 0xFFFE.
The TV would be 0000, my device connected to HDMI port 3 should be then: 3000 by this description: https://elinux.org/images/d/d9/Verkuil.pdf

Physical Address
Physical address: Hierarchy placement
Range: 0.0.0.0 - F.F.F.F
Root device: 0.0.0.0: HDMI Sink, typically a TV
First device: 1.0.0.0: Device connected to HDMI port 1 on root device
Second device: 2.0.0.0: Device connected to HDMI port 2 on root device
Third device: 1.1.0.0: Device connected to HDMI port 1 on first device

Or another example:
0x2200 is [TV] -> HDMI 2 -> [AVR] -> HDMI 2 -> [CE DEVICE]

I will need to check it in more detail the next days.

1 Like

Absolutely amazing troubleshooting action done!
Glad to see our reports that something is wrong with CEC / HDMI were “productive” and delivered kind of input for further investigations.
Looking forward for a solution.
Thanks a lot.

1 Like

I will test these days a fix to match up the priority again from Kodi to libCEC. This should bring back the priority HDMI port, if set to 0 use physical address, if set to 0 use auto detection like before.

1 Like

One additional observation:
When I’m changing “Physical address (overrules HDMI port)” to whatever value: 1 or 2 or 3 and confirm with OK button then:

  1. I’m not loosing CEC functionality and
  2. Those two additional options “Connected to HDMI device” nor “HDMI port number” are not appearing

I’m running CoreELEC 9.2.5 on Odroid-N2 -> Denon AVR-X2200W -> Panasonic OLED TV (HDMI port 2 ARC)

I had absolutely the same options as you do on the nightly. Hope you can fix it

I am not sure, it’s a forward/backwards of config options with auto detection and some other stuff.

I am now able to set a HDMI port 1-15. On next reboot, HDMI port become 0 again and libCEC does set the physical address instead. This looks “ok” for me. My HDMI port 3 on TV become 3000 as physical address. libCEC just convert the HDMI port 3 to 3000 physical address and set HDMI again to 0 as physical address should be used.

But now I changed the physical address to a “wrong” value like 1000 it become the old/correct value 3000 again after a reboot as libCEC does test and auto detect the correct one. Do the setting is useless right now.

It’s completely mixed up and the options are changed on multiple places in Kodi and libCEC…

Maybe it’s better to drop the option HDMI port at all.
For example a physical address like 2200 is not possible to be adjusted. And the physical address do have priority in libCEC as well. It’s just confusing that a user set a HDMI port and on next reboot it’s set to 0 again.

1 Like

About | FAQ | Terms of Service | Privacy Policy | Legal Notice