If you are living in a place where daylight savings come into effect in spring, and goes back to standard time in autumn, then you are probably familiar with a few things that you need to do twice a year. These include things like adjusting the clock on your range/stove, or old clocks.
But that could also include things like restarting a program that does not handle timezone changes automatically.
Whatever the case may be, here is a script that allows you to run some of these repetitive tasks, or at a minimum, email you a list of things you need to change manually.
The trick is to detect timezone change from yesterday to today.
Copy the code below, and place it somewhere, e.g. /usr/local/bin/dst-change.sh.
TMP_BODY="/tmp/dst-change.txt"
# Change this host name
HA_HOST="hass"
# Change your email address
EMAIL="foo@example.com"
# Check if timezone offset has changed
TZ_CURR=`date +%Z`
TZ_YESTERDAY=`date -d 'yesterday' +%Z`
# Check if timezones are the same yesterday and today
if [ "$TZ_CURR" = "$TZ_YESTERDAY" ]; then
# Daylight savings has not changed, nothing to do
exit
fi
# Everything below this line is executed when a daylight savings change
# is detected
# Restart appdaemon on HomeAssistant
ssh $HA_HOST 'sudo systemctl restart appdaemon'
# Create the text of the email
cat > $TMP_BODY <<-EOF
Please adjust the clock on the following:
1. Stove
2. Water softener
3. ...
EOF
# Mail it
mail -s "DST change" $EMAIL < $TMP_BODY
# Cleanup
rm -f $TMP_BODYMake sure you make it executable:
chmod +x /usr/local/bin/dst-change.shThen in crontab, add the following, and adjust it to when your location switches every year.
In my case, the Eastern Daylight Savings to Eastern Standard Time happens in March and November on a Sunday. So I run the script on every Sunday of those months. Only when a change is detected would the commands run, and the email is sent.
# Check if daylight savings changed, and send a reminder
5 3 * 3 Sun /usr/local/bin/dst-clock-change.sh
5 1 * 11 Sun /usr/local/bin/dst-clock-change.sh
Most Comments
Most commented on articles ...