esp8266-scheduler/main.py

33 lines
686 B
Python
Raw Permalink Normal View History

2019-05-20 23:17:58 +02:00
import time
2019-05-24 21:20:58 +02:00
print("main.py")
state = False
state_prev = True
2019-05-20 23:17:58 +02:00
while True:
2019-05-24 21:20:58 +02:00
dt = rtc.datetime()
print("dt: ", dt)
day = dt[3]
print("day: ", day)
config_day = config[day]
print("config[day]: ", config_day)
print("state: ", state)
2019-05-24 21:20:58 +02:00
for p in [1, 2]:
# On
entry = config_day[p]["on"]
if entry["h"] == dt[4] and entry["m"] == dt[5]:
state = True
# Off
entry = config_day[p]["off"]
if entry["h"] == dt[4] and entry["m"] == dt[5]:
state = False
2019-05-20 23:17:58 +02:00
2019-05-24 21:20:58 +02:00
if state != state_prev:
state_prev = state
if state:
print("turn on", entry)
pin_led.value(0)
else:
print("turn off", entry)
pin_led.value(1)
time.sleep(10)