HyperPixel 4 - syncing backlight on/off with screen blanking?

I have a HyperPixel 4 display on a Raspberry Pi 3 B+ and am currently using xscreensaver with the blank only option to blank the screen after a period of time. This is working, but the backlight stays on.

I found that I can use something like echo “0” > /sys/class/backlight/rpi_backlight/brightness to turn off the backlight, but this will then stay off when the screen wakes up on touch.

Is there a way that the backlight can be turned off when the screen blanks and back on when it wakes up?

Edit:
I found a solution over at the Raspberry Pi forums

Basically, a script monitors the screensaver using xscreensaver-command and turns off the backlight when the screen blanks and turns it on when it unblanks.

Hey @gadgetchannel mind a step by step how to on the solution you found? ie how, where to place those scripts and how to enable them forever? :D

Thanks