At night my study lights up like a Christmas tree.
I wanted a script to turn the PWR LED off but the commands have changed over time.
How can I turn the PWR LED off?
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It only takes a minute to sign up.
Sign up to join this communityThere are many other answers and different methods of controlling the PWR LED.
I developed the following (which I intend to use with cron
to control lights on a timer) but can be run from command line (for a user with sudo
privileges).
This has been tested on many Pi (from Pi B+ to Pi4) running Stretch and Bullseye
#!/bin/bash
# script to turn PWR LED ON/OFF
# PWRLED or PWRLED OFF turns LED off
# PWRLED anything turns LED ON
# 2023-05-06
ONOFF="$1"
if [ "${ONOFF}" = "" ]; then
ONOFF="0"
else
if [ "${ONOFF}" = "OFF" ]; then
ONOFF="0"
else
ONOFF="255"
fi
fi
if [ -e /sys/devices/platform/leds/leds/PWR ]; then
echo $ONOFF | sudo tee /sys/devices/platform/leds/leds/PWR/brightness > /dev/null
else # for older OS without leds/PWR
echo $ONOFF | sudo tee /sys/devices/platform/leds/leds/led1/brightness > /dev/null
fi