1

Main Question: Can my raspberry pi (powered on it's own) determine if power is being supplied to the monitor (powered by a wall plug)?

I'm trying to determine the power state of the display that is connected to my Raspberry Pi 4.

The following was tried with force_hdmi_hotplug=1 inside /boot/config.txt

By default, I've had this option on inside /boot/config.txt because a while ago I was testing this and without force_hdmi_hotplug=1, reconnecting the hdmi cable would not actually turn on the display (the raspberry pi would stay in VGA mode or something).

I have tried using tvservice, but it has not led to any good results. Using tvservice -M (monitor), I found the following results:

  • Disconnecting the display via the HDMI cable from the raspberry pi will yield no events being detected
  • Reconnecting the display via the HDMI cable from the raspberry pi will yield no events being detected

Using tvservice -s (status), I found the following results:

  • state 0xa [HDMI] when connected
  • state 0xa [HDMI] when disconnected

The following was tried with force_hdmi_hotplug=1 NOT INSIDE (disabled) /boot/config.txt

tvservice -M

  • Disconnected the display via the HDMI cable from the raspberry pi will yeild HDMI cable is unplugged.
  • Reconnecting the display via the HDMI cable from the raspberry pi will yield HDMI is attached

tvservice -s

  • Disconnected the display via the HDMI cable from the raspberry pi will yeild state 0x9
  • Disconnected the display via the HDMI cable from the raspberry pi will yeild state 0xa

However, disconnecting the monitor power cable with the HDMI still plugged in will yield the following two events simultaneously:

  • HDMI is unplugged
  • HDMI is attached

tvservice -s will still yield state 0xa and even using xrandr will say that a display is connected. xrandr -display :0 --listmonitors will still list a monitor.

Is what I'm looking for even possible?

Devin
  • 11
  • 1
  • 3

2 Answers2

1

I was struggling with this also. You can toggle power to the hdmi display by using

vcgencmd display_power 1  # on
vcgencmd display_power 0  # off

and you can query the power status by just using

vcgencmd display_power   # will return 1 or 0

Cheers

0

I was also trying to solve the issue, but none of the mentioned method worked for me, but found a solution. Despite my TV doesn't support HDMI CEC interface, running the command 'cec-client -r' printed different results on 'power status' event when the TV was OFF (printed: standby) or ON (printed: some invalid response error).

A python library 'python-cec' is also available, where the device.is_on() function results False when the TV is OFF, and raises an Error when it's ON.