Custom Script for TV Power On/Off

In the Yodeck Portal, the “Turned Off” option provides an easy way to turn off the connected TV screen.

How does it work?

The Yodeck Player (or Raspberry Pi) generally includes a CEC adapter on its HDMI screen/monitor port. If your screen supports HDMI-CEC, then the Player issues a CEC “standby” (or “power on”) command to turn your screen off (or on).

Suppose your TV screen/monitor does not support CEC (e.g., you have a computer monitor. Check out the CEC compatibility chart). In that case, the Player deactivates the HDMI port to allow the TV screen/monitor to power down by itself. This function is supported by all current computer screens/monitors, even some TVs.

How should the custom script behave?

  • The script should take 1 command-line argument.
  • This argument will always be present.
  • It will only have one of two possible values: on and off
  • The script should be idempotent. (That is, if it is called twice with the same argument (e.g., on), it should not cause trouble.)

That’s it.

The “standard” script

The script below simulates the standard behavior provided by the Yodeck Player. You can customize this script, add anything you need, and use it.



echo 'on 0' | cec-client -s | grep 'not present' > /dev/null
tvservice -s | grep -i 'tv is off' > /dev/null

if [ "$1" == "off" ]; then
    if [ $TV_IS_OFF -eq 0 ]; then
        echo 'Screen already off, aborting...'
        exit 0
    echo 'Turning off screen'
    if [ $NOT_CEC_COMPATIBLE -ne 0 ]; then
        echo 'standby 0' | cec-client -s > /dev/null
    tvservice -o
elif [ "$1" == "on" ]; then
    if [ $TV_IS_OFF -ne 0 ]; then
        echo 'Screen already on, aborting...'
        exit 0
    echo 'Turning on screen'
    FB_DEPTH=$(/bin/fbset | grep 'geometry' | awk '{ print $6 }')
    tvservice -p
    fbset -depth 8
    fbset -depth $FB_DEPTH
    if [ $NOT_CEC_COMPATIBLE -ne 0 ]; then
        echo 'on 0' | cec-client -s > /dev/null
    # Just for debugging, not required or used
    echo "Screens supports HDMI-CEC: $NOT_CEC_COMPATIBLE"
    echo "Screens current status: $TV_IS_OFF"
    echo 'You must specify "on" or "off"'

It does not HAVE to be a bash script. You can always provide an executable file or a script in any other language, like Python or Perl. Yodeck will use the contents you provide in Base64 (details below), will write the file to the filesystem, make it executable ( chmod +x ) and call it every time it is required.

Changing the standard script

In your Linux command line, you can use the yodeck_custom_power_script directive to provide your own custom TV on/off script. To create the custom script entry, run:

echo yodeck_custom_power_script=`base64 -w 0`

You should get a player directive (directive_name=base64_encoded_data) ready to be pasted in the Advanced Player Directive field. For the above standard script, that would be: