Skip to content

srevn/cec-control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CEC Control

An application for controlling HDMI devices over the CEC (Consumer Electronics Control) protocol. CEC Control provides both a daemon service for continuous HDMI device management and a command-line client for sending commands to your devices.

Features

  • Power Management: Turn devices on/off
  • Volume Control: Adjust volume, mute, and unmute
  • Input Source Switching: Change inputs on TVs and receivers
  • System Integration: Automatic handling of system sleep/wake events
  • Daemon/Client Architecture: Run as a background service with command-line control
  • Automatic Power Handling: Can automatically power off devices when putting PC to sleep
  • Automatic Suspend: The PC can be put to sleep when turning off TV

Requirements

  • Linux-based operating system
  • libcec 5.0.0 or newer
  • libsystemd 239 or newer
  • CMake 3.10 or newer
  • C++ 17 compatible compiler

Installation

From Source

  1. Install the dependencies:

    # Ubuntu/Debian
    sudo apt install build-essential cmake libcec-dev libsystemd-dev
    
    # Fedora
    sudo dnf install cmake libcec-devel systemd-devel
    
    # Arch Linux
    sudo pacman -S cmake libcec systemd
  2. Clone the repository:

    git clone https://github.com/srevn/cec-control.git
    cd cec-control
  3. Build & Install

    cmake -B build -S .
    cmake --build build
    sudo cmake --install build

Systemd Service Setup

After installation, you can enable the CEC daemon service:

sudo systemctl enable cec-control.service
sudo systemctl start cec-control.service

Usage

Basic Commands

# Power on the TV (logical address 0)
cec-control power on 0

# Power off the AV Receiver (logical address 5)
cec-control power off 5

# Turn up the volume
cec-control volume up 5

# Mute the audio
cec-control volume mute 5

# Change input source to HDMI 1
cec-control source 0 2

# Restart the CEC adapter
cec-control restart

# Prepare for system sleep
cec-control suspend

# Resume from sleep
cec-control resume

Command Reference

Usage: cec-control COMMAND [ARGS...] [OPTIONS]

Commands:
  volume (up|down|mute) DEVICE_ID   Control volume
  power (on|off) DEVICE_ID          Power device on or off
  source DEVICE_ID SOURCE_ID        Change input source
  restart                           Restart CEC adapter
  suspend                           Suspend CEC operations (system sleep)
  resume                            Resume CEC operations (system wake)
  help                              Show this help

Options:
  --socket-path=PATH                Set path to daemon socket
  --config=/path/to/config.conf     Set path to config file

SOURCE_ID mapping:
  0   - General AV input
  1   - Audio input
  2   - HDMI 1
  3   - HDMI 2
  4   - HDMI 3
  5   - HDMI 4

DEVICE_ID typically ranges from 0-15 and maps to CEC logical addresses:
  0   - TV
  1   - Recording Device 1
  4   - Playback Device 1 (e.g., DVD/Blu-ray player)
  5   - Audio System

Configuration

[Adapter]
# Name displayed by the CEC device on the network
DeviceName = HTPC
# Whether to automatically wake the TV when usb is powered
AutoPowerOn = true
# Whether to wake the AVR automatically when the source is activated
AutoWakeAVR = false
# Whether to activate as source on the bus when starting the application
ActivateSource = false
# Whether to use audiosystem mode
SystemAudioMode = false
# Whether to put this PC in standby mode when the TV is switched off
PowerOffOnStandby = true
# Comma-separated list of logical addresses (0-15) to wake on resume
WakeDevices = 0,5
# Comma-separated list of logical addresses (0-15) to power off on suspend
PowerOffDevices = 4

[Daemon]
# Whether to scan for devices at startup
ScanDevicesAtStartup = false
# Whether to queue commands during suspend
QueueCommandsDuringSuspend = true
# Whether to enable power state monitoring via sd-bus for suspend/resume handling
EnablePowerMonitor = true

[Throttler]
# Base interval between commands (milliseconds)
BaseIntervalMs = 200
# Maximum interval between commands (milliseconds)
MaxIntervalMs = 1000
# Maximum retry attempts for failed commands
MaxRetryAttempts = 3

File Locations

  • Config File: /etc/cec-control/config.conf
  • Log File: /var/log/cec-control/daemon.log
  • Socket Path: /run/cec-control/socket

Environment variables can override these paths:

  • CEC_CONTROL_CONFIG: Override the config file path
  • CEC_CONTROL_LOG: Override the log file path
  • CEC_CONTROL_SOCKET: Override the socket path

Acknowledgements

  • libCEC for providing the CEC communication library

About

Utility for controlling CEC compatible devices

Resources

Stars

Watchers

Forks

Releases

No releases published