Skip to main content

Daemon and tools for managing CEC capabilities

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cecdaemon-1.0.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distributions

cecdaemon-1.0.0-py3.7.egg (21.8 kB view details)

Uploaded Source

cecdaemon-1.0.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file cecdaemon-1.0.0.tar.gz.

File metadata

  • Download URL: cecdaemon-1.0.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for cecdaemon-1.0.0.tar.gz
Algorithm Hash digest
SHA256 81bb237b9711397dc993af1eeac1b9b6cb03026f59cee4d2df456029115fd406
MD5 8da4549bc887a71a71a13e156d556b76
BLAKE2b-256 df102c0d638657be0ee547b5e7bf345de40f88158b8541e421c9ff939782f6bd

See more details on using hashes here.

File details

Details for the file cecdaemon-1.0.0-py3.7.egg.

File metadata

  • Download URL: cecdaemon-1.0.0-py3.7.egg
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for cecdaemon-1.0.0-py3.7.egg
Algorithm Hash digest
SHA256 61d96b92847b456b8d6ba4875057864ddc35c5b575798e55e9d3217e585e9b42
MD5 dd17988a90edcc2f02de7c347686a8da
BLAKE2b-256 04c0e2705ef5ebd345c63520703e6668724a3e94133e9e6806b26e3958137e54

See more details on using hashes here.

File details

Details for the file cecdaemon-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cecdaemon-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for cecdaemon-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb9f291124097a61cbd2782f004ce9d6190b31454d787e73e8af42081728cb6b
MD5 ced3864535cf476b507dbef047c8672d
BLAKE2b-256 368e1632536a631e3339dc55e4bc5ab588074517265afce39375359e33fa24cd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page