Advanced cec-client Commands

Modified on Mon, 27 Apr at 9:40 PM

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 with the USB-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.

The -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
Do not run 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

CommandActionNotes
on 0Power on the TVAddress 0 = TV
standby 0Put the TV into standbyAddress 0 = TV
volupVolume up one stepRepeat as needed
voldownVolume down one stepRepeat as needed
muteToggle muteBehaviour varies by TV
asSet as active sourceSwitches input to the adapter's port
isMake TV the active sourceSwitches away from adapter's port
scanScan the CEC busLists all detected CEC devices
quitExit cec-clientAlways 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
If you are running these commands on a schedule or from a third-party automation system, see also: CEC Adapter — Task Scheduler (TV On) and CEC Batch TV On/Off.

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.

USB hubs are supported — the CEC adapter's data rate is low enough that hub bandwidth is not a concern. You can connect multiple adapters through a standard USB hub without issues.

Related Articles

Need help building a CEC automation script?
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

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article