Use CEC in Python script

Hi, i’m trying to use cec in python script to catch cdc-traffic, but in OSCM there is error ImportError: No module named cec

How can I resolve it?

Thanks,
Denis

check pypi.python.org for the module ?

and perhaps do the magical command pip install cec might be a plausible solution :wink:

Cec at pypi.python.org looks outdated.
BTW, docs on libcec github page says:

the API is exported to Python through Swig

What should i do to use CEC Python. Sorry for stupid question, please consider I’m not experienced Python-dev.

Ok. Tried to compile libcec from source using manual for RPi. Now cec module is found.
Got new error:

No adapters found

And when i try to use cec-client binary i get:

No device type given. Using ‘recording device’
CEC Parser created - libCEC version 3.1.0
no serial port given. trying autodetect: FAILED
WARNING: [ 2] libCEC has not been compiled with detection code for the Pulse-Eight USB-CEC Adapter, so the path to the COM port has to be provided to libCEC if this adapter is being used

Any advice?

AFAIK this will not work while Kodi is running.
Try sudo systemctl stop mediacenter if it works then but this may not be the solution you are looking for.

Nope, at OpenELEC everything works fine (Kodi + cec-python script as daemon).
I can confirm that its also working at OSMC, i can run Kodi and cec-client simultaneously.

You can, but for some TV’s it will cause problems as cec-client and Kodi present themselves as different devices to the TV. This can cause issues with some TV’s - usually the result is that Kodi’s CEC will stop working after you use cec-client.

Depending on what you are trying to do with CEC you can send some basic CEC commands (like active source) through Kodi using kodi-send:

http://kodi.wiki/view/List_of_built-in_functions

CECActivateSource	Wake up playing device via a CEC peripheral	v13 Addition
CECStandby	Put playing device on standby via a CEC peripheral	v13 Addition
CECToggleState	Toggle state of playing device via a CEC peripheral	v13 Addition

This avoids the issue of the TV seeing multiple CEC devices.

Hi, Simon.

My main goal is not sending commands but catch some cec-event like source change.

Can you please give me direction how to turn libcec into python module.
Look like is swig used for this. Can it be done without compile libcec from source?

I see.

Can’t help you with the python libcec stuff, it’s not something I’m familiar with.