using a Samsung TV as computer screen

I recently replaced my two 22 Inch computer screens with a 40 Inch, 4K Samsung TV. these things are incredibly cheap and make for a good PC monitor with a little tuning:

the right display settings

by default a TV has tons of image optimizers to make any possible source look good on your tv. however, that doesn't work out quite so well when all you want to see is one pixel per pixel in the exact color as the computer delivers it. Luckily on a Samsung TV you can simply change you source type to PC by pressing the source button and then pressing the up key after selecting the source where your computer is attached. now chose edit and switch to PC. this will remove all “enhancers” and provide you with a nice clean picture.

turning the TV on after the PC wakes up from standby

now this was a little more complicated: when the PC goes into standby or suspends the screen by dpms, the samsung TV stays on for a little while displaying a “no signal found, switch source” message. after a while it will then simply switch off. the main problem is now, that it won't turn on, once the signal returns. so after moving your mouse around, you need to grab the remote and turn on your tv. depending on your os, there are probably different ways to monitor your display output state and to invoke some scripts upon wakeup but the problem is, that the samsung screen cannot be turned on via its ethernet port because when the tv is turned off, it also turns off its ethernet card. Luckily, it still listens to HDMI-CEC commands. Sadly though, NVIDIA cards don't support HDMI-CEC while intel and most other graphics adapters do support it. Of course i am using an Nvidia card, so i had to come up with a little workaround: I am using a Raspberry Pi with an HDMI cable attached to it to turn on the monitor. You can indeed turn on the TV via a CEC command on HDMI2 and the TV will still stay on HDMI1 where it was when it was turned off.. that makes all this a whole lot simpler. So here is how I did that. you may of course run more code on the raspberry and less on your pc like, write a web service for your Rpi that will turn on your screen if you prefer that solution :) i just wanted something quick and dirty:

  1. download and install raspbian (the light version will do, no need for graphical output)
  2. on the raspberry:
    1. connect raspberry pi to a free HDMI port on your screen
    2. enable ssh:
      systemctl enable ssh
      systemctl start sshd
    3. change the password for the pi user
    4. set up password less ssh from your computer's root user to the raspberri's pi user.
    5. install cec utils:
      apt install cec-utils
    6. set a fixed ip either by configuring it on the os or by adding a dhcp reservation
  3. on your computer (assuming it is running ubuntu-gnome or anything similar) you can then use this script wich could be saved to /opt/checkScreen.sh:
    #!/bin/bash
    while true; do
    	xset -q | grep "Monitor is On"
    	if [ $? -eq 1 ]; then
    		if [ "`cat /tmp/displaystate`" != "off" ]; then 
    			ssh pi@192.168.168.63 'echo 'standby 0' | cec-client -s RPI'
    			echo "off" > /tmp/displaystate
    		fi
    		sleep 1
    	else 
    		if [ "`cat /tmp/displaystate`" != "on" ]; then 
    	                ssh pi@192.168.168.63 'echo 'on 0' | cec-client -s RPI'
    	                echo "on" > /tmp/displaystate
    	        fi
    		sleep 10
    	fi
    done
  4. now make sure this script is started as background process on boot. I simply added it to the autostart list of applicatoins in gnome. Here is the command I autostart:
    /opt/checkScreen.sh > /dev/null 2>&1 &
  5. in order to test if everything is working, you can force your screen to standby by running this command in a terminal
    xset dpms force suspend

    . your tv should switch off in no more then 10 seconds and it should swick back on in about 1 second after moving the mouse