Turn Raspberry screen on or off¶
Control the screen power state of a Raspberry Pi using the vcgencmd command or wlr-randr for Wayland.
Info
To see which one you are using run loginctl show-session 1 | grep "Desktop" It will display the following for each:
| Output | Technology |
|---|---|
Desktop=lightdm-xsession |
X11 |
Desktop=LXDE-pi-x |
X11 |
Desktop=LXDE-pi-wayfire |
Wayland wayfire |
Desktop=LXDE-pi-labwc |
Wayland labwc |
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
kmsprintto show all connected displays.Set
XDG_RUNTIME_DIR=/run/user/<UID>(find UID by runningloginctl) andWAYLAND_DISPLAY=<identifier>(find out by runningls /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
X11¶
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-v3dactivated.