Command to test if TV is ON/OFF

  • Hello,


    Is it possible to know with a command line if the TV (connected with HDMI) is ON or OFF? I want to use for bash script.


    Kind regards.

    • Official Post

    cec-client might also give you what you want


    echo h | cec-client -s -d 1

    for a list of available options


    cec-client [ad] {addr} checks whether the specified device is active.

  • I tried for a long time to use CEC to get info from the TV to my Pi (to change inputs and toggle on/off). From what I've read and from what I've seen others with far more knowledge write, the protocol doesn't support it.


    So I use a this USB to RS232 dongle, pyserial and a python script to test if my TV is on or off.


    Edit: Some TVs also can be controlled via their Ethernet connections. Check your manual/online.

  • Code
    LibreELEC:~ # echo pow 0 | cec-client -s -d 1
    opening a connection to the CEC adapter...
    power status: standby
    LibreELEC:~ #
  • Code
    LibreELEC:~ # echo pow 0 | cec-client -s -d 1
    opening a connection to the CEC adapter...
    power status: standby
    LibreELEC:~ #

    Thanks afl1!


    It works, but how could I add in a script?


    I want to execute some command if the output is "power status: on" and other if the output is "power status: unknown".


    Best regards.