Read the statement by Michael Teeuw here.
Having trouble with screen on and off? Here are some tips that could help
-
Hey guys,
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
andvcgencmd 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.
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
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
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
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 isHDMI-A-1
or if it is called something else.Crontab
To instantiate a crontab you docrontab -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.
Hope this helps somebody.
-
@mumblebaj Thank you for this tutorial.
I have been able to modify the MMM-Remote-Control config to use these commands for monitor on and off, and the command “/usr/bin/wlr-randr --output HDMI-A-1 --off” works in ssh terminal, however the log file shows the error “failed to connect to display” when running this as a cron job.
Would you have any insight as to what I could do? What would I need to provide in order for you to assist?
I am on Wayland desktop
-
@reviewsfornerds Hi. Apologies for the late reply. Was away for the weekend.
Can you share your script that you are calling? Also the output of
wlr-randr
. -
@reviewsfornerds said in Having trouble with screen on and off? Here are some tips that could help:
the log file shows the error “failed to connect to display”
yes, the command wants to know WHICH ‘display’ you want to control
and normally would get that from the environment variables of the terminal window you are running the command inBUT
the module is running it in the background, with NO window, no env variable… oops…
IN addition, ‘specifying’ the window info may not work as the environment running the wlr_randr command was NOT started UNDER the window manager
how to fix THAT is beyond my knowledge… as each of these depends on different stuff…
(and you put it in cron, and cron runs as ROOT, not the local user you would be if you had a terminal window… even more fun) -
Thank you for the tutorial, it solved my issues of sending the screen to sleep at night. For whatever reasons, I had to use wayland-0 and HDMI-A-2 on my installation.
-
@captsi HDMI-A-2 is probably because you plugged into 2. Glad it helped you though.
-
@captsi said in Having trouble with screen on and off? Here are some tips that could help:
I had to use wayland-0 and HDMI-A-2
wayland is the software screen interface,
HDMI- is the hardware screen interface