How to use CEC from windows?
Is there any way to programmatically turn a HDMI TV on/off on windows?
Either using an application or script/programming interface.
First check if your graphics card (hardware) supports HDMI CEC. Then also the drivers must support it. But according to this review, very few cards have CEC support.
For PCs without CEC support, there exists various products which add CEC support. They connect between the PC and TV on HDMI cable plus via USB to PC. The software sends CEC commands to adapter via USB. One example of such product is: USB HDMI CEC adapter from Pulse-eight.
There is a workaround to shutdown the TV (especialy samsung tvs)from the PC: over TCP/IP.
If your tv supports tcp/ip commands (nearly all Samsung tvs with network capability), you can schedule shutdown script on the pc. The script will run a python code automatically to send the "power button" interaction to the TV over TCP/IP, when you shutdown the pc. All you will need some SW;
- python for windows - https://www.python.org/downloads/windows/
- samsungctl python library and the code - https://github.com/Ape/samsungctl ,
- Windows Group Policy Editor to link the script to the shutdown events (included in windows).
- The sample python code
GUIDE:
- Install the python for windows,
- Download the samsungctl zip,
- Follow the installation guide on the github page to install the samsungctl,
- Assign a static IP to your TV on TV's menu,
- Save the following code on Notepad as shutdown.py (Don't forget to change the defined IP in the code with the TV's static IP -> "host:xxx.xxx.xxx.xxx" ) :
#!/usr/bin/env python3
import samsungctl
import time
config = {
"name": "samsungctl",
"description": "PC",
"id": "",
"host": "192.168.0.10",
"port": 55000,
"method": "legacy",
"timeout": 0,
}
with samsungctl.Remote(config) as remote:
for i in range(1):
remote.control("KEY_POWEROFF")
time.sleep(0.5)
- Then create and save a batch(BAT) file like below:
"PATH of python installation folder"\python "PATH of the SHUTDOWN.PY folder"\shutdown.py
- Then run the group policy editor and select "Group Configuration\Windows Settings\Scripts\Shutdown" and select the BAT file that you have created above.
That's it! Whenever you shutdown the PC the script will run automatically and shutdown your samsung TV over TCP/IP.