-
-def eventPresent(somebody_present=False):
- for id in uwscfg.slug_ids_present.split(" "):
- switchPower(id,somebody_present)
+
+def haveDaylight():
+ dawn_per_month = {1:8, 2:7, 3:6, 4:6, 5:5, 6:5, 7:5, 8:6, 9:7, 10:8, 11:8, 12:8}
+ dusk_per_month = {1:16, 2:17, 3:18, 4:20, 5:21, 6:21, 7:21, 8:20, 9:19, 10:18, 11:16, 12:16}
+ hour = datetime.datetime.now().hour
+ month = datetime.datetime.now().month
+ return (hour >= dawn_per_month[month] and hour < dusk_per_month[month])
+
+######### EVENTS ###############
+
+def eventPresent():
+ if haveDaylight():
+ present_ids=uwscfg.slug_ids_present_day
+ else:
+ present_ids=uwscfg.slug_ids_present_night
+ logging.info("event: someone present, switching on: "+present_ids)
+ for id in present_ids.split(" "):
+ switchPower(id,True)
+
+def eventNobodyHere():
+ present_ids=uwscfg.slug_ids_nonpresent_off
+ logging.info("event: noone here, switching off: "+present_ids)
+ for id in present_ids.split(" "):
+ switchPower(id,False)
+ switchPower(id,False)