Skip to main content

cec2rs232

Overview

This project aims to turn a Raspberry Pi into a bridge between the HDMI CEC standard and arbitrary control protocols for audio systems.

The intent is to automate powering up and controlling volume of certain hifi systems as you would a dedicated home theater receiver.

RS-232 and IR controls are supported. RS-232 requires a USB adapter, while IR can be controlled via GPIO.

Installation

It is assumed that the Raspberry Pi is not doing anything important so it is suitable to install cec2rs232 globally and run it as root. The package is available from pip:

sudo pip install cec2rs232

Copy cec2rs232.example.json to /etc/cec2rs232/cec2rs232.json. Edit it as needed.

Then you can have it run as a service using the provided systemd file:

sudo cp systemd/cec2rs232.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable cec2rs232
sudo systemctl start cec2rs232

This will start the process and ensure it starts again at boot.

Supported televisions

The intent is to support any TV with CEC capabilities. However, the project was originally developed using a Samsung TU7000 and therefore may unintentionally be designed against its quirks. Please report any problems you experience with another model of television and an attempt will be made to add support.

Supported audio devices

Cambridge Audio CXA61/81

These two integrated amplifiers support controlling power, source, and mute status over RS-232 but require IR for volume controls.

A 3.5mm TRS can be connected to the IR In port on the back of the amp instead of using an actual IR transmitter. In this case, connect the GPIO pin to the tip and ground to the sleeve. The ring need not be connected.

Driver name:

cambridge_cxa61

Parameters:

Name Type Description
serial_port string Path to serial device, e.g. "/dev/ttyUSB0"
ir_gpio_pin integer GPIO pin number driving the IR transmitter
tv_source string (optional) Source to activate when TV turns on, e.g. "D2". Omit to not change.

Others

Please feel free to make a pull request to add support for other devices.

CEC behavior options

Some options to handle device CEC implementation quirks are supported.

Name Type Description
echo_device_keypress boolean Default false. If true, resends playback device audio buttons.
ignore_device_keypress boolean Default false. If true, ignores playback device keypresses.

The two flags are independent, i.e., ignore does not disable echo.

The echo flag is helpful if your playback device sends broadcast CEC volume commands but your TV does not display visual feedback in that case. The command will be repeated with the TV as a specific destination.

The ignore flag is helpful in two cases. One, if you have a playback device which sends spurious keypresses that you wish two ignore. Second, if enabling the echo behavior has unintended consequences, such as the TV itself echoing the command to the audio device again (effectively double-pressing it).

MQTT

The controls for the connected audio device can also be exposed over MQTT, with the intention of being controlled from Home Assistant.

To enable this functionality, add an "mqtt" section to the configuration file:

"mqtt": {
    "server": "homeassistant.local",
    "port": 1883,
    "username": "mqtt",
    "password": "password",
    "name": "cxa61",
    "topic": "homeassistant/button/cxa61",
    "discovery": true
}

Each supported input (e.g., power_on, power_off, volume_up, volume_down, etc...) is exposed as a separate button entity, and when pressed will execute that command as if it were pressed on a remote control.

If not using Home Assistant, disable discovery. Then, you can manually send commands to the chosen topic.

Dependencies

Bindings for libCEC are required: sudo apt install python3-cec.

If using a virtual environment, specify --system-site-packages so the native libcec can be used.

Pigpiod is required: sudo apt install pigpiod && sudo systemctl enable pigpiod && sudo systemctl start pigpiod.

Other dependencies should be brought in automatically by pip.

License and attribution

Released under the terms of the MIT License.

Metadata

Release files for cec2rs232 0.4.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 cec2rs232 0.4.0
File Size Uploaded
cec2rs232-0.4.0.tar.gz 11.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cec2rs232 0.4.0
File Interpreter ABI Platform
cec2rs232-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.9 kB

Release files / cec2rs232-0.4.0.tar.gz

Download URL cec2rs232-0.4.0.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
993009d24d61178e0fdbfcf4922ae1a9ea17c9a715a37bd6963f2d1ebbd31f6f
BLAKE2b-256 checksum
How to use checksums
53c3290c2820c8f3ace92f820b98f7bf8858dfe0294a0512630b54c777e162ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / cec2rs232-0.4.0-py3-none-any.whl

Download URL cec2rs232-0.4.0-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b9e8c923a02d77dcb7f95074f5ab0730dafd5acbca10f10afd75d9def9f1b46a
BLAKE2b-256 checksum
How to use checksums
2208b5c2f0905356efd4c04af837ab9b6b283d24001ea7c952e0b828b808d07a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1

2 release files

0.0.1

1 release file

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