Enable Output on Intel Video When TV is Turned On

For media consumption at home I use MythTV. Connected to my TVs are 3 small, low power computers. One is an older Atom with discrete Intel GPU. The other two are newer. One is an ECS Liva X (ECS Liva X). Great little system for about $100. The last device is an Intel NUC 5th gen Core i5 (Intel NUC5I5SYJ).

When first setting them up, each had Mythbuntu 14.04 installed. They both do a good job of powering a TV at 1920x1080. The Liva X has a few quirks, but for the price is ok. The NUC, while considerably more expensive, has been great.

I will not cover all the details, but the Liva X fails to boot if no monitor is connected. The solution is to fake a VGA monitor connection with a couple resistors. The problem with this is that once the connected TV is powered on the HDMI output is not automatically enabled. The same issue appears to affect the NUC since I upgraded it to Mythbuntu 16.04.

Here is how I solved the issue:

  • Create a udev rule to run a script when the video output is changed.
    • Create a new file:/etc/udev/rules.d/99-hdmi.rules
    • File contents: KERNEL=="card0", SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/enable_output.sh"
  • Create the script, that runs as root, that will call a script as the logged in user
    • Create a new file: /usr/local/bin/enable_output.sh
    • File contents:
      export XAUTHORITY="/home/user/.Xauthority"
      export DISPLAY=":0.0"
      echo "enable_output.sh starting" | ts | tee --append $LOGFILE
      # Now run the enable HDMI script as the user
      su - user -c "/home/user/bin/enable_hdmi.sh"
      #xrandr --output HDMI1 --mode "1920x1080" 2>&1 | ts | tee --append $LOGFILE
      #xrandr | grep "HDMI1 connected" 2>&1 | ts | tee --append $LOGFILE &
      echo "enable_output.sh exiting" | ts | tee --append $LOGFILE
  • Create the script that runs as the logged in user.
    • Create file: /home/user/bin/enable_hdmi.sh
    • File contents:
      # Setup our X environment variables
      export XAUTHORITY="/home/user/.Xauthority"
      export DISPLAY=":0.0"
      # 2016-08-20 this seems to run before the output is actually enabled
      # adding a sleep 3
      date > $LOGFILE
      sleep 3
      xrandr -q | grep "connected" >> $LOGFILE
      xrandr --output HDMI1 --mode "1920x1080" 2>&1 | ts | tee --append $LOGFILE
      xrandr -q | grep "connected" >> $LOGFILE
      date >> $LOGFILE

The user that autologins and runs MythTV is named "user." Change to the user on your system. You may need to change the output name and mode. Run "xrandr -q" as the user to see the possible output names and their state.