- Add 'fix' command to diagnose CEC connection issues - Add detailed troubleshooting section for common errors - Fix handles errno=16 (device busy) by checking processes and trying sudo - Document solutions for CEC permission and connection issues Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
3.0 KiB
3.0 KiB
CEC Control for Raspberry Pi 4
Control HDMI-connected devices (TVs, receivers, etc.) from your Raspberry Pi 4 using CEC (Consumer Electronics Control).
Installation
- Install the required CEC utilities:
sudo apt-get update
sudo apt-get install cec-utils
- Make the script executable (already done):
chmod +x cec-control.sh
Usage
./cec-control.sh <command> [options]
Available Commands
| Command | Description | Example |
|---|---|---|
tv-on |
Turn on the TV | ./cec-control.sh tv-on |
tv-off |
Turn off the TV | ./cec-control.sh tv-off |
standby |
Put TV in standby | ./cec-control.sh standby |
wake |
Wake TV from standby | ./cec-control.sh wake |
vol-up |
Increase volume | ./cec-control.sh vol-up |
vol-down |
Decrease volume | ./cec-control.sh vol-down |
mute |
Mute audio | ./cec-control.sh mute |
input <port> |
Switch HDMI input (0-15) | ./cec-control.sh input 1 |
source <device> |
Switch source device (0-15) | ./cec-control.sh source 2 |
scan |
Scan for CEC devices | ./cec-control.sh scan |
status |
Show CEC adapter status | ./cec-control.sh status |
info |
Show TV information | ./cec-control.sh info |
fix |
Troubleshoot connection issues | ./cec-control.sh fix |
raw <command> |
Send raw CEC command | ./cec-control.sh raw 4f:82:10:00 |
help |
Show help message | ./cec-control.sh help |
Quick Start
- Connect your Raspberry Pi to your TV via HDMI
- Enable CEC on your TV (usually in settings)
- Test the connection:
./cec-control.sh scan
- Turn on your TV:
./cec-control.sh tv-on
Troubleshooting
Common Issues
ioctl CEC_S_MODE failed - errno=16 (Device or resource busy)
This error means something else is using the CEC device. Try these solutions:
- Run the built-in fix command:
./cec-control.sh fix
- Kill any existing CEC processes:
sudo killall cec-client
- Check what's using the device:
sudo lsof /dev/cec0
- Try running with sudo:
sudo ./cec-control.sh scan
- If using Kodi or LibreELEC, CEC may be enabled in the application. Disable it or stop the application first.
CEC not working
- Make sure CEC is enabled in your TV settings (often called "HDMI Control", "CEC Control", or branded names like "Bravia Link", "Anynet+", etc.)
- Try a different HDMI port on your TV
- Check that the HDMI cable is properly connected
Permission denied
- Add your user to the
videogroup:sudo usermod -aG video $USER - Then log out and back in
- Or run with
sudo
Device not found
- Check if
/dev/cec0exists:ls -l /dev/cec0 - Ensure
cec-utilsis installed - Try rebooting the Pi
Advanced Usage
You can integrate this script into your own automation:
# Turn on TV and switch to input 1
./cec-control.sh tv-on && sleep 2 && ./cec-control.sh input 1
# Use in cron jobs or other scripts
@reboot /path/to/cec-control.sh tv-on