How to turn off raspberry pi screen

Hi All,

I have a smart calendar powered by a raspberry pi. On top of the calendar is a Xiaomi motion sensor that controls the lights in that room. Is there anyone who can point me in the right direction of how to have the pi turn the screen of the calendar off after say 5 minutes of no motion detected? The pi in question is not running home assistant.

Thanks

custom python with mqtt?

Unfortunately my python knowledge is nil. I was considering putting in a sonoff / tasmota switch but thought there may be a neater way. It is likely to be out of my (very limited) area of knowledge though!

You can set up home assistant to run ssh command to your pi to keep it simple, but I would rather run it over MQTT for better flexibility.

Another command to add to the above solutions (these shouldn’t require root):

xset dpms force off

and

xset dpms force on

If you’re using ssh to run these, you might encounter the following error:

xset: unable to open display

In that case, run

export DISPLAY=:0 or

export DISPLAY=0

before the xset command.

That doesn’t actually turn off the display though. It just forces a black screen, right?

As far as I know, it’s a full turn-off. Not all screens can’t do it, but most can and the official Pi screen definitely does.

I also use this command with KDE connect to turn off my laptop screen via my phone when I’m not near it, very handy.

I thought it left the backlights on with the pi screen, but I don’t have one handy to test. I am sitting here with a NUC and a ELO touchscreen though

EDIT: definitely works well on the NUC and ELO.