在 08:30 WebIOPi raspberry pi 3 打开灯

Turn light On at 08:30 WebIOPi raspberry pi 3

集合 hour_on | hour_off,配置中有这些命令:

HOUR_ON  = 8  # Turn Light ON at 08:00
HOUR_OFF = 18 # Turn Light OFF at 18:00

没关系,但如果我将 HOUR_ON 设置为 08:30?

您必须修改您的示例程序以添加几分钟的功能。 有关 Python 日期操作的详细信息,请参阅 this page

This page 说明如何修改 loop 函数以添加 minutes 功能,

def loop():
    # Get the current time
    now = datetime.time(datetime.datetime.now().hour, datetime.datetime.now().minute)

    # Automatically switch on LED
    if ((now.hour == HOUR_ON.hour) and (now.minute == HOUR_ON.minute) and (now.second == 0)):
        if (GPIO.digitalRead(LIGHT) == GPIO.LOW):
            GPIO.digitalWrite(LIGHT, GPIO.HIGH)

    # Automatically switch off LED
    if ((now.hour == HOUR_OFF.hour) and (now.minute == HOUR_OFF.minute) and (now.second == 0)):
        if (GPIO.digitalRead(LIGHT) == GPIO.HIGH):
            GPIO.digitalWrite(LIGHT, GPIO.LOW)

    # Repeat every 1 second
    webiopi.sleep(1)