Skip to content

Turn Raspberry screen on or off

Control the screen power state of a Raspberry Pi using the vcgencmd command or wlr-randr for Wayland.

Try it out before by running wlr-randr --output <display> --off to turn off the screen and wlr-randr --output <display> --on to turn it back on.

Run kmsprint to show all connected displays.

Set XDG_RUNTIME_DIR=/run/user/<UID> (find UID by running loginctl) and WAYLAND_DISPLAY=<identifier> (find out by running ls /run/user/111/ | grep wayland).

shell:
switch:
- platform: shell
name: 'Screen'
id: screen
command_on: 'wlr-randr --output HDMI-A-1 --on'
command_off: 'wlr-randr --output HDMI-A-1 --off'
command_state: |-
if wlr-randr --output HDMI-A-1 | grep -q "Enabled: yes"; then
echo true
else
echo false
fi

Try it out before by running vcgencmd display_power 0 to turn off the screen and vcgencmd display_power 1 to turn it back on.

Be sure to have dtoverlay=vc4-fkms-v3d activated.

shell:
switch:
- platform: shell
name: 'Screen'
id: screen
command_on: 'vcgencmd display_power 1'
command_off: 'vcgencmd display_power 0'
command_state: |-
if vcgencmd display_power | grep -q "display_power=1"; then
echo true
else
echo false
fi