The project logs, technical runbooks, and problem-solving notes behind Ben’s engineering builds.
If you’ve ever repurposed an old living room TV to act as a computer monitor, you know the struggle: it doesn’t behave like a dedicated monitor. When you power on your PC, the TV stays off, and when you shut down, the TV stays on until you manually turn it off.
My wife recently got me a desk clock and calendar which has a Smart IR device built in. By leveraging the tinytuya Python library and some built-in Windows automation, I now have a TV that syncs perfectly with my PC power state.
To bridge the gap between Windows and the IR blaster, I used:
The Smart IR Device: A Tuya-compatible clock and IR blaster.
Python & TinyTuya: A library used to interact with the device locally.
Batch Scripts: To trigger the Python logic.
Group Policy Editor (gpedit.msc): To run scripts at startup and shutdown.
Setup the Clock and Smart IR device normally using the Android app. You should be able to control the TV from your smartphone. However, what we want to do is to automatically power on and shut down the TV with the PC.
You must first link your devices to a Tuya Developer account. This only needs to be done once to retrieve the device local keys.
Create a Developer Account: Go to iot.tuya.com and sign up.
Create a new cloud project and you need to take down the Access ID/Client ID, Access Secret/Client Secret and region.
Add the Smart IR device to the project using the QR code on the app.
pip install tinytuya
python -m tinytuya wizard
Enter the API Key (Access ID/Client ID) and API Secret (Access Secret/Client Secret) when prompted. Choose to scan for devices. Enter the region of your server when you created the cloud project.
Choose yes when prompted to Download DP Mappings and yes to poll local devices.
First you need to learn the base64-encoded string for the power button. Run the script below and point your TV remote at the Smart IR device and press the power button. Take down the raw IR code which will be used in the next script to power on the TV through python.
import tinytuya
import json
d = tinytuya.Device('fill in smart IR device ID', 'fill in smart IR device IP address address', 'fill in smart IR device key')
d.set_version('fill in smart IR device version')
payload = d.generate_payload(tinytuya.CONTROL, {'201':'{"control":"study"}'})
d.send(payload)
print("Smart IR Device is now in Learning Mode. Point your Samsung remote at it and press POWER.")
data = d.receive()
print("Received Raw IR Code:", data)
The following script (saved as main.py) triggers the Smart IR device to send a signal to power on and off the TV. It connects to the device using a unique ID, IP address, and local key. It sets the protocol version to 3.5 and sends a base64-encoded IR string that corresponds to the TV’s power button.
from tinytuya.Contrib import IRRemoteControlDevice
d = IRRemoteControlDevice('fill in smart IR device ID', 'fill in smart IR device IP address', 'fill in smart IR device key', control_type=1)
d.set_version('fill in smart IR device version')
ir_code = "Learned IR code from the button of your actual remote"
result = d.send_button(ir_code)
Running the script using python main.py should turn off the TV. With your screen off, you can press up to go to the previous command and enter to turn your TV back on.
To make this hands-off, I created two batch files to handle the startup and shutdown triggers. These scripts use the uv Python package manager to execute the code.
This script runs when the computer starts up to ensure the TV turns on.
@echo off
cd /d "C:\path\to\your\project"
python main.py
This script runs during the Windows shutdown process. It can be configured with a flag (like –shutdown-mode) if your script needs to handle the “off” command differently.
@echo off
cd /d "C:\path\to\your\project"
python main.py --shutdown-mode
The final step is telling Windows exactly when to run these files. Rather than using Task Scheduler, I used the Group Policy Editor for better reliability during the boot and power-off sequences.
Press Win + R, type gpedit.msc, and hit Enter.
Navigate to Computer Configuration > Windows Settings > Scripts (Startup/Shutdown).
Open Startup and add your startup.bat file.
Open Shutdown and add your shutdown.bat file.
Finally, you would want to reserve the IP address for the Smart IR device in your router so that the script will always be able to find the device by IP Address and power on / off the TV.
This can be done in your router configuration page by address reservation ( typically found at Advanced -> DHCP Server -> Address Reservation or similar). You will need the MAC address and current IP address from devices.json and reserve the currect IP address for the MAC address of the Smart IR device.
Now, my workstation feels like a professional setup. When I press the power button on my PC, the smart clock beams the IR signal across the desk, and the TV is ready by the time I reach the login screen. It’s a simple automation that makes using an old TV as a monitor much more seamless.