This article covers advanced usage of cec-client for users who are scripting or automating CEC commands. It assumes you have already installed libcec and confirmed your adapter is detected. For initial setup, see Getting Started — CEC Adapter.
The Connection Overhead Problem
The standard single-command syntax opens a new connection to the CEC adapter for every command:
echo voldown | cec-client -s -d 1
This works for one-off commands, but if you need to send the same command many times in a script — for example, lowering the volume by 20 steps — each call re-initialises the connection with the adapter. This adds significant delay and makes the script slow.
The solution is to pipe multiple commands into a single cec-client session, so the connection is only established once.
Sending Multiple Commands in One Session
Linux / macOS
Use a grouped command with & to chain multiple echo statements, then pipe the entire group into cec-client. Always end with echo quit to close the session cleanly:
(echo voldown & echo voldown & echo voldown & echo quit) | cec-client -d 1
This sends three voldown commands in a single session. Extend the pattern for as many commands as you need.
-d 1 flag sets the debug level to 1 (minimal output). Use -d 8 for full debug output if you are troubleshooting. Omit the -d flag entirely to use the default output level.Windows (Command Prompt)
The same pattern works in Windows CMD using the & operator to chain commands:
(echo voldown & echo voldown & echo voldown & echo quit) | cec-client -d 1
cec-client on its own line in a batch file without piping input to it. Running cec-client without piped input opens an interactive session and waits indefinitely for user input — the rest of the script will not execute.Windows (PowerShell)
In PowerShell, use cmd /c to run the grouped command syntax:
cmd /c "(echo voldown & echo voldown & echo voldown & echo quit) | cec-client -d 1"
Common Command Reference
| Command | Action | Notes |
|---|---|---|
on 0 | Power on the TV | Address 0 = TV |
standby 0 | Put the TV into standby | Address 0 = TV |
volup | Volume up one step | Repeat as needed |
voldown | Volume down one step | Repeat as needed |
mute | Toggle mute | Behaviour varies by TV |
as | Set as active source | Switches input to the adapter's port |
is | Make TV the active source | Switches away from adapter's port |
scan | Scan the CEC bus | Lists all detected CEC devices |
quit | Exit cec-client | Always include at end of piped command |
Practical Examples
Lower volume by 10 steps
(echo voldown & echo voldown & echo voldown & echo voldown & echo voldown & echo voldown & echo voldown & echo voldown & echo voldown & echo voldown & echo quit) | cec-client -d 1
Power on TV then set as active source
(echo on 0 & echo as & echo quit) | cec-client -d 1
Put TV into standby
(echo standby 0 & echo quit) | cec-client -d 1
Scan the CEC bus to see all connected devices
(echo scan & echo quit) | cec-client -d 1
Multiple USB-CEC Adapters
If you have more than one USB-CEC Adapter connected, you can specify which adapter to use with the -p flag followed by the COM port (Windows) or device path (Linux/macOS):
# Windows — specify COM port (echo on 0 & echo quit) | cec-client -p COM3 -d 1 # Linux — specify device path (echo on 0 & echo quit) | cec-client -p /dev/ttyACM0 -d 1
Run cec-client -l to list all detected adapters and their port assignments before building your script.
Related Articles
- Getting Started — CEC Adapter
- CEC Adapter — Raspberry Pi
- CEC Adapter — Linux Setup
- CEC Adapter — macOS Setup
Contact Pulse-Eight support with details of your setup and what you are trying to achieve.
UK: 01202 413 610 | US: (858) 748-8250 | support@pulse-eight.com