Initial commit: Add CEC control script for Raspberry Pi 4

- Add cec-control.sh with power, volume, and input commands
- Add README with installation and usage instructions

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-06 17:44:18 +01:00
commit 7395b7c94f
4 changed files with 275 additions and 0 deletions

71
README.md Normal file
View File

@@ -0,0 +1,71 @@
# CEC Control for Raspberry Pi 4
Control HDMI-connected devices (TVs, receivers, etc.) from your Raspberry Pi 4 using CEC (Consumer Electronics Control).
## Installation
1. Install the required CEC library:
```bash
sudo apt-get update
sudo apt-get install libcec-rpi
```
2. Make the script executable (already done):
```bash
chmod +x cec-control.sh
```
## Usage
```bash
./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` |
| `raw <command>` | Send raw CEC command | `./cec-control.sh raw 4f:82:10:00` |
| `help` | Show help message | `./cec-control.sh help` |
## Quick Start
1. Connect your Raspberry Pi to your TV via HDMI
2. Enable CEC on your TV (usually in settings)
3. Test the connection:
```bash
./cec-control.sh scan
```
4. Turn on your TV:
```bash
./cec-control.sh tv-on
```
## Troubleshooting
- **CEC not working**: Make sure CEC is enabled in your TV settings
- **Permission denied**: Run with `sudo` if needed
- **Device not found**: Check HDMI connection and try rescanning with `scan` command
## Advanced Usage
You can integrate this script into your own automation:
```bash
# 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
```