Hey guys,
I have updated the scripts below to reflect what works now for wayland. Have also added a crontab ready script to start MM.
Just a little note for for those who are struggling.
I have recently upgraded from my RPi 3B+ to RPi 5 4GB. MM has been running fine for a while now and all my modules are running sweet.
One thing I have been struggling with was getting the Pi to shut off the output at night and then on again in the morning. The old way, vcgencmd display_power 0 and vcgencmd display_power 1 does not work on the RPi5.
In order to get things working again, and after a lot of research I have managed to get this working now. Below are 2 scripts that I have which are called from crontab at specified times.
You have to ensure that both of the below scripts are executeable. To do this you need to run the following command. chmod +x mon.sh mof.sh from the command prompt.
mof.sh - Monitor Off. Works for X11 Compositor.
Create a file: nano mof.sh and add the below.
#!/bin/bash
export WAYLAND_DISPLAY=wayland-1
export XDG_RUNTIME_DIR=/run/user/1000
/usr/bin/wlr-randr --output HDMI-A-1 --off
Since update to 2.35.0 Wayland: The below is now valid for Wayland. Biggest change is that it is now wayland-0.
#!/bin/bash
export WAYLAND_DISPLAY=wayland-0
export XDG_RUNTIME_DIR=/run/user/1000
/usr/bin/wlr-randr --output HDMI-A-1 --off
Explanation
- Declare a variable for WAYLAND_DISPLAY
- Declare a variable for XDG_RUNTIME_DISPLAY (I had an issue with this and only found recently that I needed to declare this as well in the script)
- Execute the wlr-randr command to turn off the display
mon.sh - Monitor On. Works for X11 Compositor
Create a file: nano mon.sh and add the below to it.
#!/bin/bash
export WAYLAND_DISPLAY=wayland-1
export XDG_RUNTIME_DIR=/run/user/1000
/usr/bin/wlr-randr --output HDMI-A-1 --on --mode 1920x1080@60Hz --transform 270
And for 2.35.0 update:
#!/bin/bash
export WAYLAND_DISPLAY=wayland-0
export XDG_RUNTIME_DIR=/run/user/1000
/usr/bin/wlr-randr --output HDMI-A-1 --on --mode 1920x1080@60Hz --transform 270
Explanation
- Declare a variable for WAYLAND_DISPLAY
- Declare a variable for XDG_RUNTIME_DISPLAY (I had an issue with this and only found that I needed to declare this as well in the script)
- Execute the wlr-randr command to turn on the display
- lI have to supply options to this command as I needed to ensure that when the monitor is turned on, it has the same pixilation and rotation etc. This is achieved by passing
--mode 1929x1080@60Hz and to ensure it is flipped 90 degrees I pass the option --transform 270.
To obtain your current screen settings you run wlr-randr from the command prompt and you will be shown the current settings for your mirror. You can then use those values and substitute them for the values above if yours is different. This will also confirm if your monitor is HDMI-A-1 or if it is called something else.
Crontab
To instantiate a crontab you do crontab -e from the command line.
Add the following entries at the bottom of the file.
00 06 * * * /home/pi/mon.sh >> /home/pi/mon.log 2>&1
00 21 * * * /home/pi/mof.sh >> /home/pi/mof.log 2>&1
From the above, it will turn the output on at 6am and turn it off at 9pm.
One added bonus script that could save others. I use this to start MM from the cron. This works for wayland compositor.
#!/bin/bash
set -e
sleep 5
export PATH=/usr/local/bin:/usr/bin:/bin
export WAYLAND_DISPLAY=wayland-0
export XDG_RUNTIME_DIR=/run/user/1000
cd /home/pi/MagicMirror
exec /usr/bin/npm run start:wayland
Hope this helps somebody.