The new way to turn your connected HDMI monitor on and off on a Raspberry Pi (Bookworm Wayland)

I recently received an email from a reader telling me that there was a problem.

The long-serving command vcgencmd display_power 1/0 wouldn’t work with the latest Raspberry Pi operating system update.

I have written a post here to explain several ways to automatically turn your Raspberry Pi digital picture frame on and off at fixed times or simply with a Terminal command.

Tested with Raspberry Pi OS Bookworm on a Raspberry Pi 4 (Nov 2024).

Death by consensus

It turns out that the vcgencmd command had been retired and moved to the graveyard of commands that we used a lot but, for some inexplicable reason, had to die a cruel death because some code maintainers decided it was time.

In Nov 2024, the Raspberry Pi Foundation announced the move to a new windowing technology called Wayland and the compositor called labwc.

This again changed all the commands but at least it is working now again.

A new hope

Provided you are running a Raspberry Pi 3/4/5 with the OS Bookworm, you can use the following Terminal command to turn your connected HDMI monitor (the left output of the two) off:

wlr-randr --output HDMI-A-1 --off

To turn it on, type:

So in the case of an HD display, you would write:

wlr-randr --output HDMI-A-1 --on

Here is what the Python script for turning the monitor off would look like:

#!/usr/bin/python3
# coding: utf8 #

import subprocess  # for command execution

def turn_off_monitor():
    try:
        command = "wlr-randr --output HDMI-A-1 --off"
        subprocess.call(command, shell=True)
        print("Monitor HDMI-A-1 turned off successfully.")
    except Exception as e:
        print(f"An error occurred: {e}")

turn_off_monitor()

And for turning it on:

#!/usr/bin/python3
# coding: utf8 #

import subprocess  # for command execution

def turn_on_monitor():
    try:
        command = "wlr-randr --output HDMI-A-1 --on"
        subprocess.call(command, shell=True)
        print("Monitor HDMI-A-1 turned on successfully.")
    except Exception as e:
        print(f"An error occurred: {e}")

turn_on_monitor()

The missing display status

The vcgencmd returned a “0” or “1” depending on the monitor being off or on.

With Wayland type

wlr-randr

and it will return a value like

Enabled: yes (or no)

depending on the display status.

Was this article helpful?


Thank you for your support and motivation.


Scroll to Top