Skip to content

Instantly share code, notes, and snippets.

@xabolcs
Created March 16, 2025 19:16
Show Gist options
  • Save xabolcs/066cb4e65e1ed05108cd668578acd093 to your computer and use it in GitHub Desktop.
Save xabolcs/066cb4e65e1ed05108cd668578acd093 to your computer and use it in GitHub Desktop.
OpenWrt night light for Xiaomi AX3200
#!/bin/ash
#set -x
SELF=`basename $0 .sh`
function log() {
logger -t $SELF -s "$@"
}
board_name=`ubus call system board | jsonfilter -e '@.board_name'`
current_time="$(date +'%s')"
if [ -z ${1} ]; then
lower_bound="$(date -d '04:00' +'%s')"
else
lower_bound="$(date -d $1 +'%s')"
fi
if [ -z ${2} ]; then
upper_bound="$(date -d '21:00' +'%s')"
else
upper_bound="$(date -d $2 +'%s')"
fi
ACTIVITY_LED=
STATUS_LED=
case "${board_name}" in
xiaomi,redmi-router-ax6s)
ACTIVITY_LED='/sys/devices/platform/leds/leds/blue:net'
STATUS_LED='/sys/devices/platform/leds/leds/blue:power'
;;
esac
if [ -z ${ACTIVITY_LED} ]; then
log No activity led, nothing to do
exit 0
fi
if [ "${current_time}" -ge "${lower_bound}" -a "${current_time}" -lt "${upper_bound}" ]; then
log setting day light
service led start
if hash pingcheck; then
service pingcheck restart
fi
exit 0
fi
log setting night light
# none status
echo none > $ACTIVITY_LED/trigger
# low freq heartbeat
echo timer > $STATUS_LED/trigger
echo 9900 > $STATUS_LED/delay_off
echo 100 > $STATUS_LED/delay_on
@xabolcs
Copy link
Author

xabolcs commented Mar 16, 2025

Usage: add it to crontab 😉

# crontab -l
2 6,19 * * * /root/night-light.sh 06:00 19:00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment