Read the statement by Michael Teeuw here.
Setting up auto display off during the night.
-
It seems that in recent months the commands used to control HDMI out on the Raspberry Pi have changed. Most guides I’ve found online do not work anymore.
I just want to turn my display off at 8pm and turn it back on at 8am.
So I set up a cron job;20 14 * * * pm2 stop mm 21 14 * * * WAYLAND_DISPLAY="wayland-1" wlr-randr --output HDMI-A-1 --off 22 14 * * * WAYLAND_DISPLAY="wayland-1" wlr-randr --output HDMI-A-1 --on 23 14 * * * wlr-randr --output HDMI-A-1 transform 270 24 14 * * * pm2 start mm
The timing is one minute apart for testing.
Line 1 stops magic mirror.
Line 2 should turn the display off.
Line 3 turns it back on.
Line 4 correct the screen orientation to portrait (it is not saved).
Line 5 restarts the software.That command on line 2 works when manually typed into the terminal, but the cron job cannot execute it for some reason. Here is the error log I collected for lines 2-4;
error: XDG_RUNTIME_DIR is invalid or not set in the environment. failed to connect to display
As far as I have researched, the cron job is not in the same environment as me (the user), so it cannot execute this command. How to I make the cron job write as if I am typing the command into the terminal?
-
looks like
XDG_RUNTIME_DIR
is unset, so you can check what value contains this variable in your user environment by executingecho $XDG_RUNTIME_DIR
in the terminal and then changeWAYLAND_DISPLAY="wayland-1" wlr-randr --output HDMI-A-1 --off
to
XDG_RUNTIME_DIR="value-from-above" WAYLAND_DISPLAY="wayland-1" wlr-randr --output HDMI-A-1 --off