es fehlen nicht nur Einrückungen ...
So abgeändert kommt keine Fehlermeldung bei mir. Das #print "Start"# habe ich nur eingefügt um eine Ausgabe an der Konsole zu haben, kannst wieder rauslöschen.
# Raspberry Pi custom light timer
#!/usr/bin/python
# import GPIO module
import RPi.GPIO as GPIO
# set up GPIO pins as outputs
# This convention is for the "P1" header pin convention
# where the pins start with P1 in the upper left
# and go to P26 in the lower right, with odds in the
# left column and evens in the right column.
# So, pins P1-11 and P1-12 correspond to GPIO17 and
# GPIO18 respectively.
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
# import date and time modules
import datetime
#import time
# Enter the times you want the lights to turn on and off for
# each day of the week. Default is for lights to turn on at
# 6:00pm and off at 10:30pm on weekdays, on at 5:00pm and off
# at 11:30pm on weekends. Note that this is using a 24-hour clock.
Mon1On = datetime.time(hour=8,minute=10,second=0)
Mon1Off = datetime.time(hour=8,minute=30,second=0)
Mon2On = datetime.time(hour=12,minute=10,second=0)
Mon2Off = datetime.time(hour=12,minute=30,second=0)
Mon3On = datetime.time(hour=18,minute=10,second=0)
Mon3Off = datetime.time(hour=18,minute=30,second=0)
Tue1On = datetime.time(hour=8,minute=10,second=0)
Tue1Off = datetime.time(hour=8,minute=30,second=0)
Tue2On = datetime.time(hour=12,minute=10,second=0)
Tue2Off = datetime.time(hour=12,minute=30,second=0)
Tue3On = datetime.time(hour=18,minute=10,second=0)
Tue3Off = datetime.time(hour=18,minute=30,second=0)
Wed1On = datetime.time(hour=8,minute=10,second=0)
Wed1Off = datetime.time(hour=8,minute=30,second=0)
Wed2On = datetime.time(hour=12,minute=10,second=0)
Wed2Off = datetime.time(hour=12,minute=30,second=0)
Wed3On = datetime.time(hour=18,minute=10,second=0)
Wed3Off = datetime.time(hour=18,minute=30,second=0)
Thu1On = datetime.time(hour=8,minute=10,second=0)
Thu1Off = datetime.time(hour=8,minute=30,second=0)
Thu2On = datetime.time(hour=12,minute=10,second=0)
Thu2Off = datetime.time(hour=12,minute=30,second=0)
Thu3On = datetime.time(hour=18,minute=10,second=0)
Thu3Off = datetime.time(hour=18,minute=30,second=0)
Fri1On = datetime.time(hour=8,minute=10,second=0)
Fri1Off = datetime.time(hour=8,minute=30,second=0)
Fri2On = datetime.time(hour=12,minute=10,second=0)
Fri2Off = datetime.time(hour=12,minute=30,second=0)
Fri3On = datetime.time(hour=18,minute=10,second=0)
Fri3Off = datetime.time(hour=18,minute=30,second=0)
Sat1On = datetime.time(hour=8,minute=10,second=0)
Sat1Off = datetime.time(hour=8,minute=30,second=0)
Sat2On = datetime.time(hour=12,minute=10,second=0)
Sat2Off = datetime.time(hour=12,minute=30,second=0)
Sat3On = datetime.time(hour=18,minute=10,second=0)
Sat3Off = datetime.time(hour=18,minute=30,second=0)
Sun1On = datetime.time(hour=23,minute=49,second=0)
Sun1Off = datetime.time(hour=23,minute=50,second=0)
Sun2On = datetime.time(hour=23,minute=51,second=0)
Sun2Off = datetime.time(hour=23,minute=52,second=0)
Sun3On = datetime.time(hour=23,minute=53,second=0)
Sun3Off = datetime.time(hour=23,minute=54,second=0)
# Store these times in an array for easy access later.
OnTime = [Mon1On, Mon2On, Mon3On, Tue1On, Tue2On, Tue3On, Wed1On, Wed2On, Wed3On, Thu1On, Thu2On, Thu3On, Fri1On, Fri2On, Fri3On, Sat1On, Sat2On, Sat3On, Sun1On, Sun2On, Sun3On]
OffTime = [Mon1Off, Mon2Off, Mon3Off, Tue1Off, Tue2Off, Tue3Off, Wed1Off, Wed2Off, Wed3Off, Thu1Off, Thu2Off, Thu3Off, Fri1Off, Fri2Off, Fri3Off, Sat1Off, Sat2Off, Sat3Off, Sun1Off, Sun2Off, Sun3Off]
# Set a "wait time" in seconds. This ensures that the program pauses
# briefly after it turns the lights on or off. Otherwise, since the
# loop will execute more than once a second, it will try to keep
# turning the lights on when they are already on (or off when they are
# already off.
waitTime = 3
print "Start"
# Start the loop that will run until you stop the program or turn
# off your Raspberry Pi.
while True:
# get the current time in hours, minutes and seconds
currTime = datetime.datetime.now()
# get the current day of the week (0=Monday, 1=Tuesday, 2=Wednesday...)
currDay = datetime.datetime.now().weekday()
#Check to see if it's time to turn the lights on
if (currTime.hour - OnTime[currDay].hour == 0 and currTime.minute - OnTime[currDay].minute == 0 and currTime.second - OnTime[currDay].second == 0):
# set the GPIO pin to HIGH, equivalent of
# pressing the ON button on the remote
GPIO.output(17, GPIO.LOW)
# wait for a very short period of time then set
# the value to LOW, the equivalent of releasing the
# ON button
# time.sleep(.5)
# GPIO.output(17, GPIO.HIGH)
# wait for a few seconds so the loop doesn't come
# back through and press the "on" button again
# while the lights ae already on
# time.sleep(waitTime)
#check to see if it's time to turn the lights off
elif (currTime.hour - OffTime[currDay].hour == 0 and currTime.minute - OffTime[currDay].minute == 0 and currTime.second - OffTime[currDay].second == 0):
# set the GPIO pin to HIGH, equivalent of
# pressing the OFF button on the remote
GPIO.output(17, GPIO.HIGH)
# wait for a very short period of time then set
# the value to LOW, the equivalent of releasing the
# OFF button
# time.sleep(.5)
# GPIO.output(18, GPIO.LOW)
# wait for a few seconds so the loop doesn't come
# back through and press the "off" button again
# while the lights ae already off
# time.sleep(waitTime)
Display More