Jeff has helped me build a script to schedule the link lights on the switches. I wanted to share in case someone else still wanted to be able to turn the LEDs off at night!
A few notes before we start.
-
The script below is set to enable the LEDs in the morning at 7:00am and disable the LEDs in the evening at 9:00PM. You can go through and adjust the times if needed, just remember to adjust them in every location. I am sure someone more clever with code than I can set a variable for the times and make it faster to change them.
-
If you make any changes to the script you need to either reboot the switch or use PS to find the running script, kill the task, and run the script again.
Step 1: create a new script - /cfg/timer.sh and paste in the code below.
#!/bin/sh
turn_on_lights() {
echo "Turning lights ON at $(date)"
diag "led set software-control all entity 1 state disable"
}
turn_off_lights() {
echo "Turning lights OFF at $(date)"
diag "led set software-control all entity 1 state enable"
}
LAST_ACTION=""
while true; do
# Get current time in HHMM format
TIME=$(date +%H%M)
# Check if it's 7:00 AM (0700)
if [ "$TIME" = "0700" ] && [ "$LAST_ACTION" != "ON_0700" ]; then
turn_on_lights
LAST_ACTION="ON_0700"
# Check if it's 09:00 PM (2100)
elif [ "$TIME" = "2100" ] && [ "$LAST_ACTION" != "OFF_2100" ]; then
turn_off_lights
LAST_ACTION="OFF_2100"
# Reset last action after the minute passes
elif [ "$TIME" != "0700" ] && [ "$TIME" != "2100" ]; then
LAST_ACTION=""
fi
# Sleep for 30 seconds before checking again
sleep 30
done
Step 2: Make the new script is executable with chmod +x /cfg/timer.sh
Step 3: Add the following to /cfg/rc.local. (if /cfg/rc.local does not exist, create it first). /cfg/timer.sh &
That’s it. Your link lights should automatically turn off at 9:00pm and on again at 7:00am. Keep in mind if the switch restarts any time in between, the LEDs will follow the rules you have set in the controller.