Hyperpixel4 backlight sleep help required

Hi I’m using a hyperpixel4 with an Rpi4B under Buster.
When the pi is inactive for 10 mins, it blanks the display, this isn’t a real sleep, its more like a screen-saver.
However the Backlight stays on.
What i’d like, is some help trapping when Buster blanks and un blanks the screen, so that i can try to insert a hook to toggle the backlight control.
Another route might be for me to install Xsceensaver, and insert a hook there.
This is for a battery powered project, so i’d like to save battery where i can.

On my device using the square hyperpixel I use a simple shell script ran with sudo:
echo 1 > /sys/class/backlight/rpi_backlight/bl_power
and
echo 0 > /sys… to turn it back on.

On another device (using official display) I also have a Python program (correct term?) that switches the display on and off driven by motion using a Pi camera, but it essential does the same:
displayDev = open(’/sys/class/backlight/rpi_backlight/bl_power’, ‘w’)
displayDev.write(‘0’)
displayDev.close()

Hope this helps!

hi, thanks for that - everything is helpful :-)
are you using Buster ?
on my Pi4B with buster, i have the directory:
/sys/class/backlight/
but it is empty :-(
googling suggests this is because raspbarian doesn’t put anything there… the backlight power function comes from the specific display driver.

OK I made a bit more progress…
I found half a solution…

What I did in the end was, I installed xscreensaver

sudo apt-get install xscreensaver -y

then chose a plain black screen saver through the gui

in the xscreensaver manual https://www.jwz.org/xscreensaver/man3.html, there is a way to hook into the process:
xscreensaver-command -watch
this returns a line of text each time the screen saver status changes.

this little perl routine runs in the background and keeps an eye on the screen saver status:
if you hate perl, there is a bash version kicking around at
https://gist.github.com/rduplain/3852987

#!/usr/bin/perl
use warnings;
use strict;

my $blanked = 0;

open (LOG,'>',"screenwatch.log");
print LOG "started";

open (IN, "xscreensaver-command -watch |");

while (<IN>) {
    if (m/^(BLANK|LOCK)/) {
        if (!$blanked) {
            print LOG "backlight-off";
            $blanked = 1;
        }
    } elsif (m/^UNBLANK/) {
        print LOG "backlight-on";
        $blanked = 0;
    }
}

save it into a text file ~/xscreensaver-watch.pl
remember to set the execute bit…

chmod a+x ~/xscreensaver-watch.pl

test it with ./xscreensaver-watch.pl and it’ll write a little log file ~/screenwatch.log

… now where i’m stuck(ish) is:

  1. i need to add this to the x startup config … where that ?
  2. i want to turn the hyperpixel backlight off/on but the given commands don’t work for me.
    i also tried to control the backlight GPIO pin directly, but the OS said it was ‘busy’.

any help apreciated