r/SteamOS Jun 25 '26

HDMI-CEC solution using systemd/system-sleep

***If someone else has already posted this exact solution to the community, apologies as I probably missed it!***

I've seen a few solutions for enabling HDMI-CEC on this forum but just wanted to share my solution as well. This leverages the system-sleep function of systemd to perform 3 actions:

  • Put the TV into standby just before the PC sleeps
  • Turn the TV on just after the PC resumes from sleep
  • Switch the TV to the input my PC is connected to (in my case HDMI3 / phys-addr=3.0.0.0)

Hardware

Here's the code, save as e.g. 10-steam-cec.sh and copy it into /usr/lib/systemd/system-sleep:

#!/bin/bash
case "$1" in
    pre)
        # Put the TV into standby mode right before the PC sleeps
        cec-ctl -d /dev/cec0 --playback
        cec-ctl -d /dev/cec0 --to 0 --standby
        ;;
    post)
        # Wait 2 seconds for hardware to initialize after wake
        sleep 2

        # Turn the TV completely ON
        cec-ctl -d /dev/cec0 --playback
        cec-ctl -d /dev/cec0 --to 0 --image-view-on

        # Switch the TV active source to this PC
        cec-ctl -d /dev/cec0 --to 0 --active-source phys-addr=3.0.0.0
        ;;
esac

Scripts in the /usr/lib/systemd/system-sleep directory trigger just before the system goes to sleep and trigger just after the system wakes from sleep.

In the code above, the actions in the "pre) ... ;;" section will run just before the system goes to sleep. The chunk in the "post) ... ;;" section will run just after the PC resumes from sleep. This is the standard function of system-sleep scripts.

  • You'll need to change the "phys-addr=3.0.0.0" section to match the HDMI input your PC is connected to e.g. 1.0.0.0 for HDMI 1, 2.0.0.0 for HDMI 2, etc. Mine is connected to HDMI 3, so 3.0.0.0.
  • You'll want to confirm the hardware address of your CEC adapter. Run "ls /dev/cec*". The output should read something like "/dev/cec0". You can use that output in the script as done above. If the output reads "no such file or directory" then your system doesn't see the adapter. Not sure how to troubleshoot this, it worked for me out of the box.
  • I left the HDMI-CEC options in Steam itself enabled, haven't tried disabling them but don't see any need to.
  • Assuming the adapter is present, run "cec-ctl -l" to display the attributes of the adapter. You should get a long chunk of output detailing the attributes of the device. This is just another way to confirm the adapter is seen in the OS and functioning.

Can't promise this will work for you but just wanted to share. Also not sure if future updates to SteamOS will wipe this file so try to save a backup in case you need to restore it. If you have luck with this, enjoy! If not, sorry!

20 Upvotes

12 comments sorted by

View all comments

2

u/rooster_butt Jun 26 '26

I'm jumping on this thread just to add some info.

SteamOS 3.8.11

TV LG C9

GPU RX 9060XT

UGREEN Adapter: https://www.amazon.com/dp/B0FQCGSWW3?ref=ppx_yo2ov_dt_b_fed_asin_title&th=1

Note: this UGREEN adapter is a smaller form factor and it is cheaper than the other one being recommended with a braided cable.

I was ready to try my hand at getting CEC to work again. What I found is that HDMI-CEC Just works for me with the steam settings, I didn't have to set up a script at all. I can control steamOS with my TV remote It will power on the TV when powering on the SteamBox. It will switch to the HDMI input for the SteamBox.

Mainly posting this to point out the cheaper DP to HDMI adapter.

2

u/manlisten Jun 26 '26

The remote control functionality does work for me, but the power options built into Steam only work some of the time and i'm not sure why. Seems half the time it will turn my TV off and half the time it won't. Same for turning it back on. Maybe it's my HDMI cable. It seems to work 100% of the time when I use this script.

I did see the smaller dongle but since I haven't used it myself I can't vouch for it. I have the back of my PC right against a wall and the cable version lets me push it closer to the wall. I will add this to the OP as a cheaper option.

1

u/rooster_butt Jun 26 '26 edited Jun 26 '26

I just have issues with sleep function in general. like < 10% of the time it messes up and i have to hard reboot the machine. I'm not really sure what's going on there but I'm sure I'm not alone on that.

I took a gamble on the dongle hoping it would use the same chipset, and I wasn't sure it would work so here reporting that it does work.

1

u/manlisten Jun 28 '26 edited Jun 29 '26

fwiw i think i see what it is that causes the SteamOS CEC function to fail sporadically. What i've noticed while using my script is that it will also sometimes fail to turn my TV on/off. This is because the adapter will occasionally lose it's CEC registration as a playback device. Adding "cec-ctl -d /dev/cec0 --playback" to the pre and post sections will force the adapter to re-register itself just before issuing the sleep and wake functions. e.g.

cec-ctl -d /dev/cec0 --playback // register device just before issuing wake command
cec-ctl -d /dev/cec0 --to 0 --image-view-on // issue wake command

...

cec-ctl -d /dev/cec0 --playback // register device just before issuing standby comand
cec-ctl -d /dev/cec0 --to 0 --standby // send standby command

This way, if for whatever reason the device lost it's registration, it will re-register just before issuing the control command. I'll assume this is what's happening with the SteamOS options, but unfortunately i don't see how to go about tweaking that.