If you want to check the status of your display, you can now use the
wlr-randr
command.
Tested with Raspberry Pi OS Bookworm Wayland on a Raspberry Pi 4 (Nov 2024).
The output will be similar to
HDMI-A-1 "HJW HDMI TO USB 0x00000001 (HDMI-A-1)"
Physical size: 700x390 mm
Enabled: no
Modes:
1920x1080 px, 60.000000 Hz (preferred)
giving you a clear feedback with “Enabled:” if the monitor is on or off.
You will also see many other display modes/resolutions and you can grab the information that you like from the output file.
I wrote a Python test script parsing the output and checking the display status.
#!/usr/bin/python3
import subprocess
def is_display_enabled():
try:
# Run the wlr-randr command and capture its output
command = "wlr-randr"
output = subprocess.check_output(command, shell=True).decode('utf-8')
# Check if any display has "Enabled: yes" in the output
for line in output.splitlines():
if 'Enabled:' in line:
enabled_status = line.split(':')[1].strip()
if enabled_status.lower() == 'yes':
return True
return False # If no display is enabled
except subprocess.CalledProcessError:
# Handle any errors that may occur
return False
if is_display_enabled():
print("A display is on.")
else:
print("All displays are off.")
I am using it to let Home Assistant know if my display is on or off.
Was this article helpful?
Thank you for your support and motivation.
Related Articles
- How to automatically remove duplicate images from your Pictures folder (2024 Edition)
- How to only show portrait photos on your Raspberry Pi photo frame
- Celebrate birthdays and anniversaries with auto-themed photos on your digital frame
- How I added smooth crossfading image transitions to my Raspberry Pi digital picture frame (OS Buster Edition)