Created
March 16, 2025 19:16
-
-
Save xabolcs/066cb4e65e1ed05108cd668578acd093 to your computer and use it in GitHub Desktop.
OpenWrt night light for Xiaomi AX3200
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: add it to crontab 😉