From 4e4a6a2a01a26dc36e4e1aeb4448a8d73a0d17c4 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Sun, 25 Dec 2022 20:05:06 +0100 Subject: [PATCH] room auto off implemented and used for ffe/floor --- devices/__init__.py | 31 ++++++++++++++++++++++++++++++- function/first_floor_east.py | 6 ++++-- function/rooms.py | 22 ++++++++++++++++++++++ 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/devices/__init__.py b/devices/__init__.py index 50fbd3b..ec7d3c5 100644 --- a/devices/__init__.py +++ b/devices/__init__.py @@ -179,7 +179,7 @@ class base(dict): if self.warning_callback is not None: self.warning_callback(self, warn_txt) - def warning_text(self, data): + def warning_text(self): return "default warning text - replace parent warning_text function" def previous_value(self, key): @@ -336,6 +336,35 @@ class silvercrest_powerplug(base): self.set_output_0('toggle') +class silvercrest_motion_sensor(base): + KEY_BATTERY = "battery" + KEY_BATTERY_LOW = "battery_low" + KEY_LINKQUALITY = "linkquality" + KEY_OCCUPANCY = "occupancy" + KEY_UNMOUNTED = "tamper" + KEY_VOLTAGE = "voltage" + # + RX_KEYS = [KEY_BATTERY, KEY_BATTERY_LOW, KEY_LINKQUALITY, KEY_OCCUPANCY, KEY_UNMOUNTED, KEY_VOLTAGE] + + def __init__(self, mqtt_client, topic): + super().__init__(mqtt_client, topic) + + def warning_call_condition(self): + return self.get(self.KEY_BATTERY_LOW) + + def warning_text(self, data): + return "Battery low: level=%d" % self.get(self.KEY_BATTERY) + + # + # RX + # + + @property + def linkquality(self): + """rv: numeric value""" + return self.get(self.KEY_LINKQUALITY) + + class my_powerplug(base): KEY_OUTPUT_0 = "output/1" KEY_OUTPUT_1 = "output/2" diff --git a/function/first_floor_east.py b/function/first_floor_east.py index 23d402d..f93e84a 100644 --- a/function/first_floor_east.py +++ b/function/first_floor_east.py @@ -6,7 +6,7 @@ import config import devices import json import logging -from function.rooms import room_shelly, room_shelly_tradfri_light +from function.rooms import room_shelly, room_shelly_auto_off, room_shelly_tradfri_light from function.helpers import changed_value_indicator try: from config import APP_NAME as ROOT_LOGGER_NAME @@ -15,10 +15,12 @@ except ImportError: logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) -class first_floor_east_floor(room_shelly): +class first_floor_east_floor(room_shelly_auto_off): def __init__(self, mqtt_client): # http://shelly1l-3C6105E4E629 super().__init__(mqtt_client, "shellies/ffe/floor/main_light", "gui/ffe/floor/main_light/switch") + self.motion_sensor_silvercrest = devices.silvercrest_motion_sensor(mqtt_client, "zigbee/ffe/floor/motion_sensor") + self.motion_sensor_silvercrest.add_callback(devices.silvercrest_motion_sensor.KEY_OCCUPANCY, True, self.main_light_shelly.set_output_0_mcb) class first_floor_east_kitchen(room_shelly): diff --git a/function/rooms.py b/function/rooms.py index 211c46f..59bd08c 100644 --- a/function/rooms.py +++ b/function/rooms.py @@ -56,6 +56,28 @@ class room_shelly(room): self.last_flash_data = data +class room_shelly_auto_off(room_shelly): + def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, timer_value=30): + super().__init__(mqtt_client, topic_shelly, topic_gui_switch) + self.timer_value = timer_value + self.main_light_timer = None + # + self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.reload_timer, True) + # + cyclic_task = task.periodic(1, self.cyclic_task) + cyclic_task.run() + + def reload_timer(self, device, key, data): + self.main_light_timer = self.timer_value + + def cyclic_task(self, cyclic_task): + if self.main_light_timer is not None: + self.main_light_timer -= cyclic_task.cycle_time + if self.main_light_timer <= 0: + self.main_light_shelly.set_output_0(False) + self.main_light_timer = None + + class room_shelly_tradfri_light(room_shelly): def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_br_ct): super().__init__(mqtt_client, topic_shelly, topic_gui_switch)