sunrise and sunset depending motion sensor action for room_shelly_motion_sensor implemented
This commit is contained in:
parent
bc1c30cd3f
commit
73d6606902
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
1
geo
Submodule
1
geo
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 11166bb27ad2335f7812fcb88c788397f5106751
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user