In the first instance, the switch may not recognise the current state of the screen, when the switch is toggled once it will behave normally from then on.
For mine, I had to do use these commands, specific to my screen’s GPIO driver, but working without Xorg:
Turn off: sh -c "echo 1 > /sys/class/backlight/fb_ili9320/bl_power"
Turn on: sh -c "echo 0 > /sys/class/backlight/fb_ili9320/bl_power"
Read current status: exit $(cat /sys/class/backlight/fb_ili9320/bl_power)
(The first two need root access)
Note that you can simplify your commands: you don’t need to export the DISPLAY variable, but you can directly declare it in your xset call: export DISPLAY=:0 && xset dpms force on can be replaced by DISPLAY=:0 xset dpms force on.
These commands do work remote (SSH), however i’m looking for a solution in a (local) Python script on my RPi.
I have a script running that toggles the screen ON / OFF by the state of a GPIO pin that is connected to a sensor.
The thing is, i can’t get around this error: xset: unable to open display ":0"