room auto off implemented and used for ffe/floor

This commit is contained in:
Dirk Alders 2022-12-25 20:05:06 +01:00
parent 66f560ee3a
commit 4e4a6a2a01
3 changed files with 56 additions and 3 deletions

View File

@ -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"

View File

@ -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):

View File

@ -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)