Skip to main content

cecdaemon - CEC Daemon for linux media centers

cecdaemon is for managing the Consumer Electronics Control (CEC) capabilities of your linux media center. Some embedded systems (like Raspberry Pi) have native support for CEC. Many video cards do not have CEC capabilities, so you may need an adapter like the one offered by PulseEight to use CEC with your computer.

Currently it is able to translate remote buttons to computer input, run shell commands, and set the device name, and run shell scripts on standby and wake.

Requirements:

Installation:

Installation should be done as root to allow installing commands to /usr/bin/

Install from PIP

# pip3 install cecdaemon

Install using setuptools

# python3 setup.py install

Configuration

cecdaemon looks for a configuration file at /etc/cecdaemon.conf. The configuration file is a simple .ini style file. There are currently three main sections that can be configured:

The [tv] section allows you to set the name that will be displayed on the tv for your device. It is truncated to the 14 character max.

[tv]
name = HTPC

The [keymap] section allows you to map CEC user command codes to uinput events. The remote codes can be determined using the cecusercodes command. The command will output the CEC User Command name, and the code in both hex and decimal. The hex code matches the CEC Specification, the decimal code is what is used in the config for readability.

# /usr/bin/cecusercodes
Initializing CEC, please wait...
If this takes too long ensure the device is not already in use
CEC device initialized, press remote keys or hit ^C to quit
Select pressed (hex: 0x0, dec: 0)
Up pressed (hex: 0x1, dec: 1)
Down pressed (hex: 0x2, dec: 2)
Left pressed (hex: 0x3, dec: 3)
Right pressed (hex: 0x4, dec: 4)
F1 (Blue) pressed (hex: 0x71, dec: 113)
F2 (Red) pressed (hex: 0x72, dec: 114)
F3 (Green) pressed (hex: 0x73, dec: 115)
F4 (Yellow) pressed (hex: 0x74, dec: 116)
^C

Keypresses can be found in python-uinput ev.py file. The format for assigning a key to a cec code looks like this:

[keymap]
0 = KEY_ENTER
1 = KEY_UP
#STOP
69 = KEY_X
70 = KEY_PAUSE
113 = KEY_BLUE

The CEC Specification states that only Select, Directions, Exit, Numbers and Function Keys get forwarded to devices, but the actual implementation varies between vendors. The cecdaemon.conf-example file comes with a good baseline that works well with Kodi and Steam.

The [cmd_name] sections can be used to run shell commands when a button is pressed or held down. For a simple press set the holdtime to 1. Use a separate section for each command. Remember to use the absolute path for the command if you are unsure what the PATH environment variable will be for the daemon. A command hook currently overrides any uinput keypresses.

[cmd_reboot]
# Reboots when holding the red button for 400ms
key = 114
holdtime = 4000
command = /usr/bin/systemctl reboot

[cmd_switcher]
# Open the task switcher
key = 115
holdtime = 1
command =/usr/local/scripts/switcher

The [triggers] section can be used to run shell commands when the daemon receives events such as standby or wake.

[triggers]
standby = /usr/bin/systemctl stop hyperiond
wake = /usr/bin/systemctl start hyperiond

Usage

Running from the command line

# cecdaemon --help
usage: cecdaemon [-h] [-d] [-v] [-c FILE]

optional arguments:
  -h, --help            show this help message and exit
  -d, --debug           Print debug messages
  -v, --verbose         Print verbose messages
  -c FILE, --config FILE
                        Configuration file
#

Using the included systemd service

Copy the script to the systemd directory:

# cp examples/cecdaemon.service-example /etc/systemd/system/cecdaemon.service

Reload the daemons and start the service: # systemctl daemon-reload # systemctl start cecdaemon

And to enable the service use: # systemctl enable cecdaemon

Viewing the stderr and stdout for troubleshooting: # journalctl -f -u cecdaemon

Using in another python script

>>> from cecdaemon import cecdaemon
>>> cecdaemon.run()

Changelog

1.0.0 - Initial beta release

Metadata

Release files for cecdaemon 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cecdaemon 1.0.0
File Size Uploaded
cecdaemon-1.0.0.tar.gz 10.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for cecdaemon 1.0.0
File Interpreter ABI Platform
cecdaemon-1.0.0-py3.7.egg Legacy Egg format - - Details
cecdaemon-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 45.1 kB

Release files / cecdaemon-1.0.0.tar.gz

Download URL cecdaemon-1.0.0.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
81bb237b9711397dc993af1eeac1b9b6cb03026f59cee4d2df456029115fd406
BLAKE2b-256 checksum
How to use checksums
df102c0d638657be0ee547b5e7bf345de40f88158b8541e421c9ff939782f6bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.2 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

Release files / cecdaemon-1.0.0-py3.7.egg

Download URL cecdaemon-1.0.0-py3.7.egg
Size 21.8 kB
Tags Egg
SHA-256 checksum
How to use checksums
61d96b92847b456b8d6ba4875057864ddc35c5b575798e55e9d3217e585e9b42
BLAKE2b-256 checksum
How to use checksums
04c0e2705ef5ebd345c63520703e6668724a3e94133e9e6806b26e3958137e54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.2 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

Release files / cecdaemon-1.0.0-py3-none-any.whl

Download URL cecdaemon-1.0.0-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cb9f291124097a61cbd2782f004ce9d6190b31454d787e73e8af42081728cb6b
BLAKE2b-256 checksum
How to use checksums
368e1632536a631e3339dc55e4bc5ab588074517265afce39375359e33fa24cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.2 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

Release history Release notifications | RSS feed

This release

1.0.0 This release

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page