Let’s have an AC/DC singalong…
Tried tvservice
Tried cec-client
Tried dtparam
Tried vcenvcmd
I tell you folks, it’s harder than it looks
About 6 years ago I created a family digital photo frame. It was a Pi 3 hooked up to a computer monitor and contained thousands of family photos, plus inspirational images and quotes. The operation was pretty simple:
- Every hour, generate 120 images. These are a combination of picking photos in random order and placing them on abstract backgrounds (via ImageMagick) and pre-created inspirational images, quotes, and other full-screen photos.
- Feed this list to fbi (framebuffer interface) with instructions to show each with a 30-second pause. At the top of each hour, kill fbi and restart with a new list.
- At midnight, turn the display off (since we’re asleep) and then at 6am turn it back on
Amazingly, the Pi3 with the same memory card worked continuously for all those years. Occasionally it would glitch and would need a power cycle but it was quite resilient, considering that every hour it was doing a lot of compute and I/O work to generate all those images, year after year.
Version 2.0
Recently, I’ve wanted to expand this system. I did a countdown to vacation last year where every hour there were a couple images with photos of our destination and a “___ days and counting” message (ImageMagick really is amazing). I’ve had thoughts to include sports scores/standings, weather, stock market info, etc.
However, the previous system was written entirely in PERL and is starting to show its age. I wanted to redo it to be more modular and thought I’d use Python for the next go. The RPi 3 is 32-bit and only supports Raspbian (a reskinned Debian) Jessie. To get to a current, Python 3-supporting OS, I’d need to upgrade.
So I bought an R Pi 5 (4GB)…and that’s when the fun began. All the image generation and display stuff worked fine but turning the monitor off at night proved to be an adventure.
tvservice, You Are Missed
I was using the tvservice command to flip the monitor on and off (more correctly, the HDMI output. Once it was off, the monitor sensed there was no input and went into power saving mode.)
However, this command no longer exists in Bookworm. After some googling, I discovered cec-client, but quickly determined that wasn’t what I wanted.
Next up was vcgencmd. the man page has:
display_power 0|1|-1
display_power 0|1|-1 display
Show current display power state, or set the display power state. vc‐
gencmd display_power 0 will turn off power to the current display. vc‐
gencmd display_power 1 will turn on power to the display. If no parameter
is set, this will display the current power state. The final parameter is
an optional display ID, as returned by tvservice -l or from the table be‐
low, which allows a specific display to be turned on or off.
Perfect! Except:
# vcgencmd commands
commands="commands, set_logging, bootloader_config, bootloader_version, cache_flush, codec_enabled, get_mem, get_rsts, measure_clock, measure_temp, measure_volts, get_hvs_asserts, get_config, get_throttled, pmicrd, pmicwr, read_ring_osc, version, readmr, otp_dump, pmic_read_adc, power_monitor"
# vcgencmd display_power 0
vc_gencmd_read_response returned -1
error=1 error_msg="Command not registered"
OK, then. So that’s a dead end. What else is there?
Oh, there’s dtparam:
# dtparam -h hdmi
hdmi Set to "off" to disable the HDMI interface
(default "on")
Except:
# dtparam hdmi=off
* Unknown parameter 'hdmi'
OK, so we’ve determined that the R Pi project could use a little more QA.
The Solution
I was not using X Window at all for this project. Rather, I just booted auto-login to the console and started fbi. The solution actually is to auto-login to the X Window desktop. You can still run fbi (it overrides whatever X Window is doing).
Then when it’s time to turn off the monitor, first kill fbi and wait a few seconds until you’re back at X (in a script, I use sleep 10). Then:
xrandr --display :0 --output HDMI-1 --off
I don’t think there’s a way to “go under X” to shut off the HDMI port directly.
I think in 2.0 I’m going to ditch fbi and use something like feh to do the slideshow entirely in X.
So future googlers, when you’re trying to figure out how to turn off your HDMI monitor on your Raspberry Pi, this article is for you. At least until everything changes in OS 13.
Related Posts:
- Early Black Friday Offer: VersaWeb has a Dedi Deal in Las Vegas, Dallas, and Miami! - November 23, 2024
- LowEndBoxTV: Are All Hetzner Locations Alike?No!And Piotr Has the Proof: “This is Clearly Not the Same Processor” - November 22, 2024
- One Week From Tomorrow…THE WORLD WILL LOSE THEIR MINDS!Lines Are Already Forming! - November 21, 2024
Thanks for posting this.
I have almost 80 Raspberry Pis in production as library PAC kiosk/terminals. I’m in the process of moving them off of Raspbian 10 (Buster) to Debian 12 (Bookworm) and this is one of the things I’ve run into in the process.
I’ve been using vcgenmd to turn the monitors off at night and as you noted above, that no longer works. Now I can use:
“xrandr –display :0 –output HDMI-1 –off”
to turn them off in the crontab and use:
“xrandr –display :0 –output HDMI-1 –auto”
To turn them on (or simply have them reboot) in the morning.
Note that I used “–auto” to turn them on, because “–on” apparently isn’t a thing.
Any way to turn them off if I dont log into Desktop GUI? I am running CLI mode, with X server running too. But I get:
xrandr –display :0 –output HDMI-1 –off
Can’t open display :0
That sounds like an X authority problem. Take a look at some of the solutions starting about halfway down the following linked page. Although these were mentioned to deal with a different problem, there’s a good chance that they would work in your situation too:
https://unix.stackexchange.com/questions/209746/how-to-resolve-no-protocol-specified-for-su-user/417233#417233