Compare commits

..

No commits in common. "b554be3d6b7f5f0f8a45c8ba5b1d6b67ac4674f1" and "95a9010240c28690baf3ff83cdf33dd1ba1e24d5" have entirely different histories.

9 changed files with 34 additions and 108 deletions

1
.gitignore vendored
View File

@ -1,5 +1,4 @@
config.py config.py
database.db
# ---> Linux # ---> Linux
*~ *~

View File

@ -8,4 +8,4 @@
"emmet.includeLanguages": { "emmet.includeLanguages": {
"django-html": "html" "django-html": "html"
} }
} }

View File

@ -484,7 +484,7 @@ class tradfri_light(base):
TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP, KEY_BRIGHTNESS_FADE] TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP, KEY_BRIGHTNESS_FADE]
# #
RX_KEYS = [KEY_LINKQUALITY, KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP] RX_KEYS = [KEY_LINKQUALITY, KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP]
RX_IGNORE_KEYS = ['update', 'color_mode', 'color_temp_startup'] RX_IGNORE_KEYS = ['update', 'color_mode']
RX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP] RX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP]
def __init__(self, mqtt_client, topic): def __init__(self, mqtt_client, topic):

View File

@ -4,7 +4,7 @@
import devices import devices
from function.stairway import stairway from function.stairway import stairway
from function.ground_floor_west import ground_floor_west_floor, ground_floor_west_marion, ground_floor_west_dirk from function.ground_floor_west import ground_floor_west_floor, ground_floor_west_marion, ground_floor_west_dirk
from function.first_floor_west import first_floor_west_julian, first_floor_west_living, first_floor_west_bath, first_floor_west_sleep from function.first_floor_west import first_floor_west_julian, first_floor_west_living, first_floor_west_bath
from function.first_floor_east import first_floor_east_floor, first_floor_east_kitchen, first_floor_east_dining, first_floor_east_sleep, first_floor_east_living from function.first_floor_east import first_floor_east_floor, first_floor_east_kitchen, first_floor_east_dining, first_floor_east_sleep, first_floor_east_living
import inspect import inspect
import logging import logging
@ -32,9 +32,8 @@ class all_functions(object):
self.gfw_dirk = ground_floor_west_dirk(self.mqtt_client) self.gfw_dirk = ground_floor_west_dirk(self.mqtt_client)
# first floor west # first floor west
self.ffw_julian = first_floor_west_julian(self.mqtt_client) self.ffw_julian = first_floor_west_julian(self.mqtt_client)
self.ffw_bath = first_floor_west_bath(self.mqtt_client)
self.ffw_living = first_floor_west_living(self.mqtt_client) self.ffw_living = first_floor_west_living(self.mqtt_client)
self.ffw_sleep = first_floor_west_sleep(self.mqtt_client) self.ffw_bath = first_floor_west_bath(self.mqtt_client)
# first floor east # first floor east
self.ffe_floor = first_floor_east_floor(self.mqtt_client) self.ffe_floor = first_floor_east_floor(self.mqtt_client)
self.ffe_kitchen = first_floor_east_kitchen(self.mqtt_client) self.ffe_kitchen = first_floor_east_kitchen(self.mqtt_client)

View File

@ -1,54 +0,0 @@
import os
import sqlite3
db_file = os.path.join(os.path.dirname(__file__), '..', 'database.db')
def get_gui_radiator_data(topic):
return __storage__().get_gui_radiator_data(topic)
def set_gui_radiator_data(topic, away_mode, summer_mode, user_temperatur_setpoint):
return __storage__().store_gui_radiator_data(topic, away_mode, summer_mode, user_temperatur_setpoint)
class __storage__(object):
def __init__(self):
self.conn = sqlite3.connect(db_file)
self.c = self.conn.cursor()
with self.conn:
self.c.execute("""CREATE TABLE IF NOT EXISTS gui_radiator (
topic text PRIMARY KEY,
away_mode integer,
summer_mode integer,
user_temperatur_setpoint real
)""")
def store_gui_radiator_data(self, topic, away_mode, summer_mode, user_temperatur_setpoint):
data = [topic, away_mode, summer_mode, user_temperatur_setpoint]
try:
with self.conn:
self.c.execute(
'INSERT INTO gui_radiator VALUES (?, ?, ?, ?)', data)
except sqlite3.IntegrityError:
data = [away_mode, summer_mode, user_temperatur_setpoint]
db_data = self.get_gui_radiator_data(topic)
if db_data != data:
with self.conn:
self.c.execute(
'UPDATE gui_radiator SET away_mode = ?, summer_mode = ?, user_temperatur_setpoint = ? WHERE topic = ?', data + [topic])
def get_gui_radiator_data(self, topic):
""" returns a list [away_mode, summer_mode, user_temperatur_setpoint] or [None, None, None]"""
self.c.execute("SELECT * FROM gui_radiator WHERE topic=?", (topic, ))
data = self.c.fetchone()
if data is not None:
data = list(data)
data[1] = data[1] == 1
data[2] = data[2] == 1
return data[1:]
else:
return [None, None, None]
def __del__(self):
self.conn.close()

View File

@ -100,7 +100,6 @@ class first_floor_east_sleep(room_shelly_tradfri_light):
def all_off(self, device=None, key=None, data=None): def all_off(self, device=None, key=None, data=None):
super().all_off(device, key, data) super().all_off(device, key, data)
self.bed_light_di_tradfri.set_output_0(False) self.bed_light_di_tradfri.set_output_0(False)
self.bed_light_ma_powerplug.set_output_0(False)
class first_floor_east_living(room_shelly_tradfri_light): class first_floor_east_living(room_shelly_tradfri_light):

View File

@ -21,21 +21,14 @@ class first_floor_west_julian(room_shelly_tradfri_light):
super().__init__(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_GUI, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE) super().__init__(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_GUI, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE)
class first_floor_west_living(room_shelly):
# http://shelly1l-84CCA8ACE6A1
def __init__(self, mqtt_client):
super().__init__(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_GUI)
class first_floor_west_bath(object): class first_floor_west_bath(object):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
# radiator valve # radiator valve
self.radiator_function = radiator_function(mqtt_client, config.TOPIC_FFW_BATH_RADIATOR_VALVE_ZIGBEE, self.radiator_function = radiator_function(mqtt_client, config.TOPIC_FFW_BATH_RADIATOR_VALVE_ZIGBEE,
config.TOPIC_FFW_BATH_RADIATOR_VALVE_GUI, config.DEFAULT_TEMPERATURE_FFW_BATH) config.TOPIC_FFW_BATH_RADIATOR_VALVE_GUI, config.DEFAULT_TEMPERATURE_FFW_BATH)
class first_floor_west_living(room_shelly_tradfri_light):
# http://shelly1l-84CCA8ACE6A1
def __init__(self, mqtt_client):
super().__init__(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY,
config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_GUI, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_ZIGBEE)
class first_floor_west_sleep(room_shelly_tradfri_light):
# http://shelly1-3494546A51F2
def __init__(self, mqtt_client):
super().__init__(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_SHELLY, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_GUI, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_ZIGBEE)

View File

@ -4,7 +4,6 @@
import config import config
import devices import devices
from function.db import get_gui_radiator_data, set_gui_radiator_data
from function.rooms import room_shelly from function.rooms import room_shelly
import logging import logging
import task import task
@ -141,22 +140,16 @@ class radiator_function(object):
def __init__(self, mqtt_client, topic_valve, topic_gui, default_temperature): def __init__(self, mqtt_client, topic_valve, topic_gui, default_temperature):
self.default_temperature = default_temperature self.default_temperature = default_temperature
self.boost_timer = None self.regular_temp_setpoint = self.default_temperature
# device initialisation self.__away_mode__ = False
self.__summer_mode__ = False
#
self.ct = task.periodic(1, self.cyclic_task)
#
self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, topic_valve) self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, topic_valve)
self.gui_heating = devices.nodered_gui_radiator(mqtt_client, topic_gui) self.gui_heating = devices.nodered_gui_radiator(mqtt_client, topic_gui)
# db-stored data initialisation #
db_data = get_gui_radiator_data(topic_gui) self.heating_valve.set_heating_setpoint(self.default_temperature)
self.__away_mode__ = db_data[0] or False
self.__summer_mode__ = db_data[1] or False
self.__user_temperature_setpoint__ = db_data[2] or default_temperature
if self.__away_mode__:
self.away_mode(None, None, True)
elif self.__summer_mode__:
self.summer_mode(None, None, True)
else:
self.set_heating_setpoint(None, None, self.__user_temperature_setpoint__)
# callback initialisation
self.heating_valve.add_callback(devices.brennenstuhl_heatingvalve.KEY_TEMPERATURE, None, self.gui_heating.set_temperature_mcb) self.heating_valve.add_callback(devices.brennenstuhl_heatingvalve.KEY_TEMPERATURE, None, self.gui_heating.set_temperature_mcb)
self.heating_valve.add_callback(devices.brennenstuhl_heatingvalve.KEY_HEATING_SETPOINT, None, self.get_radiator_setpoint) self.heating_valve.add_callback(devices.brennenstuhl_heatingvalve.KEY_HEATING_SETPOINT, None, self.get_radiator_setpoint)
# #
@ -165,8 +158,9 @@ class radiator_function(object):
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SETPOINT_TO_DEFAULT, None, self.setpoint_to_default) self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SETPOINT_TO_DEFAULT, None, self.setpoint_to_default)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_AWAY, None, self.away_mode) self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_AWAY, None, self.away_mode)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SUMMER, None, self.summer_mode) self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SUMMER, None, self.summer_mode)
# cyclic task initialisation #
self.ct = task.periodic(1, self.cyclic_task) self.boost_timer = None
#
self.ct.run() self.ct.run()
def cyclic_task(self, rt): def cyclic_task(self, rt):
@ -176,23 +170,19 @@ class radiator_function(object):
self.boost_timer -= self.ct.cycle_time self.boost_timer -= self.ct.cycle_time
if self.boost_timer <= 0: if self.boost_timer <= 0:
self.cancel_boost() self.cancel_boost()
self.heating_valve.set_heating_setpoint(self.__user_temperature_setpoint__) self.heating_valve.set_heating_setpoint(self.regular_temp_setpoint)
self.heating_valve.logger.info('Timer expired. returning to regular temperature setpoint %.1f°C.', self.__user_temperature_setpoint__)
def cancel_boost(self, device=None, key=None, data=None): def cancel_boost(self, device=None, key=None, data=None):
if self.boost_timer is not None: if self.boost_timer is not None:
self.heating_valve.logger.info('Timer expired. returning to regular temperature setpoint %.1f°C.', self.regular_temp_setpoint)
self.boost_timer = None self.boost_timer = None
self.gui_heating.set_timer('-') self.gui_heating.set_timer('-')
def update_states(self, away_mode=None, summer_mode=None, user_temperature_setpoint=None): def update_states(self, away_mode=None, summer_mode=None):
if away_mode is not None: if away_mode is not None:
self.__away_mode__ = away_mode self.__away_mode__ = away_mode
if summer_mode is not None: if summer_mode is not None:
self.__summer_mode__ = summer_mode self.__summer_mode__ = summer_mode
if user_temperature_setpoint is not None:
self.__user_temperature_setpoint__ = user_temperature_setpoint
set_gui_radiator_data(self.gui_heating.topic, self.__away_mode__, self.__summer_mode__, self.__user_temperature_setpoint__)
#
self.gui_heating.set_away(self.__away_mode__) self.gui_heating.set_away(self.__away_mode__)
self.gui_heating.set_summer(self.__summer_mode__) self.gui_heating.set_summer(self.__summer_mode__)
self.gui_heating.set_enable(not self.__away_mode__ and not self.__summer_mode__) self.gui_heating.set_enable(not self.__away_mode__ and not self.__summer_mode__)
@ -201,10 +191,10 @@ class radiator_function(object):
if value is True: if value is True:
self.cancel_boost() self.cancel_boost()
self.update_states(away_mode=value, summer_mode=False) self.update_states(away_mode=value, summer_mode=False)
self.heating_valve.set_heating_setpoint(self.__user_temperature_setpoint__ - self.AWAY_REDUCTION) self.heating_valve.set_heating_setpoint(self.default_temperature - self.AWAY_REDUCTION)
else: else:
self.update_states(away_mode=value) self.update_states(away_mode=value)
self.heating_valve.set_heating_setpoint(self.__user_temperature_setpoint__) self.heating_valve.set_heating_setpoint(self.default_temperature)
def summer_mode(self, device, key, value): def summer_mode(self, device, key, value):
if value is True: if value is True:
@ -213,7 +203,7 @@ class radiator_function(object):
self.heating_valve.set_heating_setpoint(self.SUMMER_TEMPERATURE) self.heating_valve.set_heating_setpoint(self.SUMMER_TEMPERATURE)
else: else:
self.update_states(summer_mode=value) self.update_states(summer_mode=value)
self.heating_valve.set_heating_setpoint(self.__user_temperature_setpoint__) self.heating_valve.set_heating_setpoint(self.default_temperature)
def boost(self, device, key, data): def boost(self, device, key, data):
if self.boost_timer is None: if self.boost_timer is None:
@ -230,13 +220,12 @@ class radiator_function(object):
self.set_heating_setpoint(device, key, self.default_temperature) self.set_heating_setpoint(device, key, self.default_temperature)
def set_heating_setpoint(self, device, key, data): def set_heating_setpoint(self, device, key, data):
self.cancel_boost()
self.update_states(away_mode=False, summer_mode=False, user_temperature_setpoint=data)
self.heating_valve.set_heating_setpoint(data) self.heating_valve.set_heating_setpoint(data)
self.cancel_boost()
self.update_states(away_mode=False, summer_mode=False)
def get_radiator_setpoint(self, device, key, data): def get_radiator_setpoint(self, device, key, data):
if self.boost_timer is None and not self.__away_mode__ and not self.__summer_mode__:
self.update_states(user_temperature_setpoint=data)
else:
self.update_states()
self.gui_heating.set_setpoint_temperature(data) self.gui_heating.set_setpoint_temperature(data)
self.update_states()
if self.boost_timer is None and not self.__away_mode__ and not self.__summer_mode__:
self.regular_temp_setpoint = data

View File

@ -97,7 +97,8 @@ class room_shelly_motion_sensor(room_shelly):
def reset_timer(self, device=None, key=None, data=None): def reset_timer(self, device=None, key=None, data=None):
self.main_light_timer = None self.main_light_timer = None
self.gui_main_light.set_timer('-') self.motion_detected_1 = False
self.motion_detected_2 = False
def cyclic_task(self, cyclic_task): def cyclic_task(self, cyclic_task):
if self.main_light_timer is not None: if self.main_light_timer is not None: