diff --git a/.gitmodules b/.gitmodules index fa2204f..4b92446 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "task"] path = task url = https://git.mount-mockery.de/pylib/task.git +[submodule "geo"] + path = geo + url = https://git.mount-mockery.de/pylib/geo.git diff --git a/function/helpers.py b/function/helpers.py index 4e93229..088c9d0 100644 --- a/function/helpers.py +++ b/function/helpers.py @@ -1,8 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # - +import config +import geo import inspect +import time class changed_value_indicator(dict): @@ -16,3 +18,15 @@ class changed_value_indicator(dict): rv = self.get(key) != value self[key] = value return rv + + +def now(): + return time.mktime(time.localtime()) + + +def sunrise_time(time_offs_min=30): + return time.mktime(geo.sun.sunrise(config.GEO_POSITION)) + time_offs_min * 60 + + +def sunset_time(time_offs_min=-30): + return time.mktime(geo.sun.sunset(config.GEO_POSITION)) + time_offs_min * 60 diff --git a/function/rooms.py b/function/rooms.py index 3d832be..4c38eac 100644 --- a/function/rooms.py +++ b/function/rooms.py @@ -3,6 +3,7 @@ # import devices +from function.helpers import now, sunset_time, sunrise_time import logging import task @@ -77,13 +78,14 @@ class room_shelly_motion_sensor(room_shelly): cyclic_task.run() def set_motion_detected(self, device, key, data): - if device == self.motion_sensor_silvercrest_1: - self.motion_detected_1 = data - elif device == self.motion_sensor_silvercrest_2: - self.motion_detected_2 = data - if data is True: - logger.info("%s: Motion detected - Switching on main light %s", device.topic, self.main_light_shelly.topic) - self.main_light_shelly.set_output_0(True) + if now() < sunrise_time(60) or now() > sunset_time(-60): + if device == self.motion_sensor_silvercrest_1: + self.motion_detected_1 = data + elif device == self.motion_sensor_silvercrest_2: + self.motion_detected_2 = data + if data is True: + logger.info("%s: Motion detected - Switching on main light %s", device.topic, self.main_light_shelly.topic) + self.main_light_shelly.set_output_0(True) def reload_timer(self, device, key, data): self.main_light_timer = self.timer_value diff --git a/geo b/geo new file mode 160000 index 0000000..11166bb --- /dev/null +++ b/geo @@ -0,0 +1 @@ +Subproject commit 11166bb27ad2335f7812fcb88c788397f5106751 diff --git a/smart_brain.py b/smart_brain.py index 71a2c05..bcbd3b2 100644 --- a/smart_brain.py +++ b/smart_brain.py @@ -12,7 +12,7 @@ if __name__ == "__main__": if config.DEBUG: report.appLoggingConfigure(None, None, ((config.APP_NAME, logging.DEBUG), ), fmt=report.SHORT_FMT, host='localhost', port=19996) else: - report.stdoutLoggingConfigure(((config.APP_NAME, logging.INFO), (config.APP_NAME+'.devices', logging.WARNING)), report.SHORT_FMT) + report.stdoutLoggingConfigure(((config.APP_NAME, logging.INFO)), report.SHORT_FMT) # mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER, password=config.MQTT_PASSWORD, name=config.APP_NAME)