5

I am trying to detect the display power status of a HDMI connected display with a Raspberry Pi 3.

Running

tvservice -s

gives the same state 0x12000a for a powered-on and powered-off display.

Are there solutions to this?

7
  • Try tvservice -n and see if that changes. I think the -s "status" refers to the pi, not the display.
    – goldilocks
    Commented Sep 20, 2016 at 18:31
  • 1
    tvservice -n displays device_name=SAM-SAMSUNG for both cases, display turned off by remote control and display powered off by unplugging.
    – alex
    Commented Sep 20, 2016 at 19:10
  • @alex did you get the solution for this? Commented Mar 2, 2018 at 17:34
  • @AbhinandanSatpute No news, I did not pursue that issue since the time of posting.
    – alex
    Commented Mar 3, 2018 at 8:43
  • @alex oh okay. No problem. Thanks fro getting back. Commented Mar 5, 2018 at 17:21

4 Answers 4

4

If your TV supports CEC you can do it.

CEC, or Consumer Electronics Control, is a feature of HDMI which allows controlling devices connected through HDMI using a remote control.

Install the cec-utils package (cec-client is part of this package)

sudo apt install cec-utils

Now that cec-utils is installed, let's scan the CEC bus for available devices:

echo 'scan' | cec-client -s -d 1

Take the device's address from this information. And now ask for the status of the device.

echo 'pow 0.0.0.0' | cec-client -s -d 1 |grep power

The answer is something like this:

    power status: on
or
    power status: standby
1

I use this Display - "17,3" LED Display Screen (non-glossy) Full HD LP173WF1 (TL)(B2)"

and this controller: - "HDMI + VGA + AV + USB + RF Eingang LCD Controller Board für B156HW01 LP173WF1 15,6 '' 17,3 '' 1920x1080 40Pins LCD".

I have a Magic Mirror with two displays. My problem was to know if they are running or not. Everything should be controlled by one of the two Rasps. So if the state is MAGIC Mirror ON. Check if the DISPLAY is on or off and set it to the correct state. The same for turning off. This helps a lot e.g. after booting to be sure both monitors are in the correct state.

I found a solution working perfectly for me.

Control the displays: I use two GPIO out to control the right and left monitor independently. The output of the pin is soldered to the display control bar. This enables me to turn on and of the display by GPIO out.

Figure out if the displays are on or off: To read out the status of the display I have two GPIO inputs connected to the infrared input. The infrared cable has five pins. The cable in the middle goes to low or high when the display is off or on. The output is 0V or 2,3V and could be connected directly to the GPIO input of the rasp.

With this configuration, i am able to use a PIR sensor and an Python program to controls the state of the displays.

It's a hardware solution, but works perfect. In my case perfect for two rasps and two display. Only one rasp with one display should be more easy. But this solution will works with many rasps and display you need. I would prefer a rasp with several hdmi outputs =;o)

P.S. Please NOTE, if you overlay one mirror glas over two displays, you will see a gray edge with normal TFT monitors where the display ends. Because this monitors are not displaying a perfect black value.

1
  • Perhaps you could format into sections/paragraphs so it is readable.
    – MatsK
    Commented Apr 22, 2018 at 13:27
1

I assume that in your /boot/config.txt

  hdmi_force_hotplug=1 

is set.

In that case, also on my Raspberry Pi 3B with Raspbian stretch, tvservice –s will always report state 0x12000a independent of the status of the monitor or if a cable is connected at all to the HDMI port.
As far as I understand, if hdmi_force_hotplug=1 is set, no check is done, if a monitor is connected or not, but HDMI is always applied.

Solution:

If you can live without the ability to boot the Raspberry Pi without monitor and plug it in later, you can simply remove the line

hdmi_force_hotplug=1

in /boot/config.txt.

Then bit0 (=1, if cable unplugged) and bit1 (=1, if cable plugged in) of the state output of tvservice –s will tell you whether a monitor is connected or not. For example, if I boot with a HDMI monitor attached, the state will be 0x12000a. As soon as I remove the monitor cable the state will go to 0x120009. You can find further details about the meaning of the different bits in the state variable here in the official Raspberry Pi forum.

0

I couldn't get tvservice to report anything other than no monitor (0x120009) no matter if HDMI was connected and working or not. (RPi 3 Raspbian stretch)

Tried cec-utils. Installed but was buggy and reported segmentation fault, as others have reported.

Finally used xrandr as in

        xrandr | grep disconnected > /directory/hdmi.txt

in a script this creates a file I can test to see if the display is disconnected

1
  • valid only if you are under X
    – zertyz
    Commented Jul 20, 2021 at 23:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.