Skip to content

Instantly share code, notes, and snippets.

@xZise
Created March 20, 2026 16:49
Show Gist options
  • Select an option

  • Save xZise/e2270308fcf683a52db977deaef4f3ac to your computer and use it in GitHub Desktop.

Select an option

Save xZise/e2270308fcf683a52db977deaef4f3ac to your computer and use it in GitHub Desktop.
Toggle LEDs in OpenWRT routers

leds.sh — OpenWRT LED Control Script

A simple shell script for OpenWRT-based routers to turn all LEDs on or off on a schedule, e.g. to avoid light pollution at night.

Compatibility

This script was written for and tested on a Fritz!Box 7530/Fritz!Box 4040 running OpenWRT. It should work on other OpenWRT devices as well, but LED names and behaviour may differ. In particular, the line

echo default-on > /sys/class/leds/red:info/trigger

references the red:info LED, which is specific to the Fritz!Box 7530. On other devices, this LED may not exist or may have a different name. Check your device's available LEDs with:

ls /sys/class/leds/

You can safely remove or adjust that line if you don't need a status LED to remain on when the others are switched off.

Usage

leds.sh on   # Restore normal LED behaviour by restarting the LED service
leds.sh off  # Turn off all LEDs (except the red info LED on the Fritz!Box 7530)

Scheduling with Cron

Place the script on your router (e.g. /root/leds.sh) and make it executable:

chmod +x /root/leds.sh

Then add a cron job via crontab -e, for example to turn the LEDs off at 23:55 and back on at 06:00:

55 23 * * * /root/leds.sh off
0 6  * * * /root/leds.sh on

How It Works

  • on — Runs /etc/init.d/led restart, which restores the default LED triggers as configured by OpenWRT.
  • off — Iterates over all entries in /sys/class/leds/ and sets their trigger to none, effectively turning them off. On the red:info LED is then set to default-on as a minimal status indicator.
#!/bin/sh
if [ "$1" == "on" ]; then
/etc/init.d/led restart
echo "Switch on"
elif [ "$1" == "off" ]; then
for d in /sys/class/leds/*/ ; do
echo none > ${d}trigger
done
echo default-on > /sys/class/leds/red:info/trigger
echo "Switch off"
else
echo "Unknown parameter"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment