In the event of a power outage, an analogue power socket timer switch will simply turn off. When then power returns, the unit is not aware of how long the power has been out for and the timer will continue from when the power cut.
If a digital timer is used, on power being restored, the time should be correct with your on/off schedule preserved.
When using a Linux system (Raspberry Pi) and Cron to set a scheduled task, if a power cut occurred within the time an action was supposed to initiate, this window will be missed as when the system power is restored the action event would have passed and won’t be initiated until the next scheduled time.
For the ARPIC or Linux system to act like a 7 day digital timer a script is used on start up to check the time.
If the time is within a schedule where an action should be initiated, this will be actioned on boot. i.e. power is restored at 9am, the script should of run from 7am to 9am – in this case the script will run on boot, where as if the action was set to run at 4pm, the system will not run action and the script will end.
#!/usr/bin/python # Program: ARPIC # Version: 1.0 # Command: This script runs on boot and checks the time, # if between 07:00 and 09:00 the front house lights turn ON, # outside this time the lights are turned OFF. # The Lights are called by Group. import RPi.GPIO as GPIO import datetime import os import time from time import strftime import sys print "**POWER** Starting timecheck script" try: # here you put your main loop or block of code time = datetime.datetime.now().time() if (time > datetime.time(7) and time < datetime.time(9)): os.system("cd /home/pi/scripts/ ; sh lights_fh-on.sh") print "lights should be ON" else: os.system("cd /home/pi/scripts/ ; sh lights_fh-off.sh") print "lights should be OFF" except KeyboardInterrupt: # here you put any code you want to run before the program # exits when you press CTRL+C print "** script quit **" except: # this catches ALL other exceptions including errors. # You won't get any error messages for debugging # so only use it once your code is working print "Other error or exception occurred!" print "**POWER** Exiting timecheck script" sys.exit