Compare commits
3 Commits
95a9010240
...
b554be3d6b
Author | SHA1 | Date | |
---|---|---|---|
b554be3d6b | |||
34800bf5d9 | |||
a3e4b8839c |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
config.py
|
||||
database.db
|
||||
|
||||
# ---> Linux
|
||||
*~
|
||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -8,4 +8,4 @@
|
||||
"emmet.includeLanguages": {
|
||||
"django-html": "html"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -484,7 +484,7 @@ class tradfri_light(base):
|
||||
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_IGNORE_KEYS = ['update', 'color_mode']
|
||||
RX_IGNORE_KEYS = ['update', 'color_mode', 'color_temp_startup']
|
||||
RX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP]
|
||||
|
||||
def __init__(self, mqtt_client, topic):
|
||||
|
@ -4,7 +4,7 @@
|
||||
import devices
|
||||
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.first_floor_west import first_floor_west_julian, first_floor_west_living, first_floor_west_bath
|
||||
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_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 logging
|
||||
@ -32,8 +32,9 @@ class all_functions(object):
|
||||
self.gfw_dirk = ground_floor_west_dirk(self.mqtt_client)
|
||||
# first floor west
|
||||
self.ffw_julian = first_floor_west_julian(self.mqtt_client)
|
||||
self.ffw_living = first_floor_west_living(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_sleep = first_floor_west_sleep(self.mqtt_client)
|
||||
# first floor east
|
||||
self.ffe_floor = first_floor_east_floor(self.mqtt_client)
|
||||
self.ffe_kitchen = first_floor_east_kitchen(self.mqtt_client)
|
||||
|
54
function/db.py
Normal file
54
function/db.py
Normal file
@ -0,0 +1,54 @@
|
||||
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()
|
@ -100,6 +100,7 @@ class first_floor_east_sleep(room_shelly_tradfri_light):
|
||||
def all_off(self, device=None, key=None, data=None):
|
||||
super().all_off(device, key, data)
|
||||
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):
|
||||
|
@ -21,14 +21,21 @@ 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)
|
||||
|
||||
|
||||
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):
|
||||
def __init__(self, mqtt_client):
|
||||
# radiator valve
|
||||
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)
|
||||
|
||||
|
||||
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)
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
import config
|
||||
import devices
|
||||
from function.db import get_gui_radiator_data, set_gui_radiator_data
|
||||
from function.rooms import room_shelly
|
||||
import logging
|
||||
import task
|
||||
@ -140,16 +141,22 @@ class radiator_function(object):
|
||||
|
||||
def __init__(self, mqtt_client, topic_valve, topic_gui, default_temperature):
|
||||
self.default_temperature = default_temperature
|
||||
self.regular_temp_setpoint = self.default_temperature
|
||||
self.__away_mode__ = False
|
||||
self.__summer_mode__ = False
|
||||
#
|
||||
self.ct = task.periodic(1, self.cyclic_task)
|
||||
#
|
||||
self.boost_timer = None
|
||||
# device initialisation
|
||||
self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, topic_valve)
|
||||
self.gui_heating = devices.nodered_gui_radiator(mqtt_client, topic_gui)
|
||||
#
|
||||
self.heating_valve.set_heating_setpoint(self.default_temperature)
|
||||
# db-stored data initialisation
|
||||
db_data = get_gui_radiator_data(topic_gui)
|
||||
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_HEATING_SETPOINT, None, self.get_radiator_setpoint)
|
||||
#
|
||||
@ -158,9 +165,8 @@ 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_AWAY, None, self.away_mode)
|
||||
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SUMMER, None, self.summer_mode)
|
||||
#
|
||||
self.boost_timer = None
|
||||
#
|
||||
# cyclic task initialisation
|
||||
self.ct = task.periodic(1, self.cyclic_task)
|
||||
self.ct.run()
|
||||
|
||||
def cyclic_task(self, rt):
|
||||
@ -170,19 +176,23 @@ class radiator_function(object):
|
||||
self.boost_timer -= self.ct.cycle_time
|
||||
if self.boost_timer <= 0:
|
||||
self.cancel_boost()
|
||||
self.heating_valve.set_heating_setpoint(self.regular_temp_setpoint)
|
||||
self.heating_valve.set_heating_setpoint(self.__user_temperature_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):
|
||||
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.gui_heating.set_timer('-')
|
||||
|
||||
def update_states(self, away_mode=None, summer_mode=None):
|
||||
def update_states(self, away_mode=None, summer_mode=None, user_temperature_setpoint=None):
|
||||
if away_mode is not None:
|
||||
self.__away_mode__ = away_mode
|
||||
if summer_mode is not None:
|
||||
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_summer(self.__summer_mode__)
|
||||
self.gui_heating.set_enable(not self.__away_mode__ and not self.__summer_mode__)
|
||||
@ -191,10 +201,10 @@ class radiator_function(object):
|
||||
if value is True:
|
||||
self.cancel_boost()
|
||||
self.update_states(away_mode=value, summer_mode=False)
|
||||
self.heating_valve.set_heating_setpoint(self.default_temperature - self.AWAY_REDUCTION)
|
||||
self.heating_valve.set_heating_setpoint(self.__user_temperature_setpoint__ - self.AWAY_REDUCTION)
|
||||
else:
|
||||
self.update_states(away_mode=value)
|
||||
self.heating_valve.set_heating_setpoint(self.default_temperature)
|
||||
self.heating_valve.set_heating_setpoint(self.__user_temperature_setpoint__)
|
||||
|
||||
def summer_mode(self, device, key, value):
|
||||
if value is True:
|
||||
@ -203,7 +213,7 @@ class radiator_function(object):
|
||||
self.heating_valve.set_heating_setpoint(self.SUMMER_TEMPERATURE)
|
||||
else:
|
||||
self.update_states(summer_mode=value)
|
||||
self.heating_valve.set_heating_setpoint(self.default_temperature)
|
||||
self.heating_valve.set_heating_setpoint(self.__user_temperature_setpoint__)
|
||||
|
||||
def boost(self, device, key, data):
|
||||
if self.boost_timer is None:
|
||||
@ -220,12 +230,13 @@ class radiator_function(object):
|
||||
self.set_heating_setpoint(device, key, self.default_temperature)
|
||||
|
||||
def set_heating_setpoint(self, device, key, data):
|
||||
self.heating_valve.set_heating_setpoint(data)
|
||||
self.cancel_boost()
|
||||
self.update_states(away_mode=False, summer_mode=False)
|
||||
self.update_states(away_mode=False, summer_mode=False, user_temperature_setpoint=data)
|
||||
self.heating_valve.set_heating_setpoint(data)
|
||||
|
||||
def get_radiator_setpoint(self, device, key, 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
|
||||
self.update_states(user_temperature_setpoint=data)
|
||||
else:
|
||||
self.update_states()
|
||||
self.gui_heating.set_setpoint_temperature(data)
|
||||
|
@ -97,8 +97,7 @@ class room_shelly_motion_sensor(room_shelly):
|
||||
|
||||
def reset_timer(self, device=None, key=None, data=None):
|
||||
self.main_light_timer = None
|
||||
self.motion_detected_1 = False
|
||||
self.motion_detected_2 = False
|
||||
self.gui_main_light.set_timer('-')
|
||||
|
||||
def cyclic_task(self, cyclic_task):
|
||||
if self.main_light_timer is not None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user