Commit 5412a91b authored by Peter-Bernd Otte's avatar Peter-Bernd Otte

Added maxBrightness feature

parent 8d99e244
......@@ -17,6 +17,7 @@ testraum/testrelais:
inverseSwitchOnTopics: homie/enocean/test/schalter6
prolongateStateTopics: homie/enocean/test/schalter5
luxThreshold: 200 #below this threshold, lights get switched on. Default=100
maxBrightness: 0.8
testraum/testrelais2:
MQTTRelaisTopic: homie/fsr-ww/3
......
......@@ -128,6 +128,15 @@ for section in cfg:
luxThreshold = cfg[section]["luxThreshold"]
if type(luxThreshold) is not int: luxThreshold = 100
logger.debug("luxThreshold used: "+str(luxThreshold))
maxBrightness=1.0
if "maxBrightness" in cfg[section]:
maxBrightness = cfg[section]["maxBrightness"]
if type(maxBrightness) not in (float, int):
logger.warning("maxBrightness "+str(maxBrightness)+" not a number. Default value 1.0 will be used.")
maxBrightness=1
if maxBrightness>1 or maxBrightness<0:
logger.warning("maxBrightness "+str(maxBrightness)+" not in range 0..1. Default value 1.0 will be used.")
maxBrightness=1
defaultTopics = cfg[section]["defaultTopics"] if "defaultTopics" in cfg[section] and isinstance(cfg[section]["defaultTopics"],(list, str)) else []
toggleTopics = cfg[section]["toggleTopics"] if "toggleTopics" in cfg[section] and isinstance(cfg[section]["toggleTopics"],(list, str)) else []
......@@ -152,7 +161,8 @@ for section in cfg:
switchOffTopics=switchOffTopics,
defaultTopics=defaultTopics, inverseSwitchOnTopics=inverseSwitchOnTopics,
prolongateStateTopics=prolongateStateTopics,
defaultSwitchOffTime=defaultSwitchOffTime, debug=debugItem, relaisType=relaisType, luxThreshold=luxThreshold))
defaultSwitchOffTime=defaultSwitchOffTime, debug=debugItem, relaisType=relaisType, luxThreshold=luxThreshold,
maxBrightness=maxBrightness))
logger.info("Adding successfully.")
......
......@@ -22,11 +22,13 @@ class rLightDesire(Enum):
class relais:
def __init__(self, MQTTClient, MQTTName, MQTTRelaisTopic, defaultTopics=None, toggleTopics=None, dimmTopics=None,
switchOffTopics=None,
inverseSwitchOnTopics=None, prolongateStateTopics=None, defaultSwitchOffTime=None, debug=False, relaisType="relais", luxThreshold=100):
inverseSwitchOnTopics=None, prolongateStateTopics=None, defaultSwitchOffTime=None, debug=False,
relaisType="relais", luxThreshold=100, maxBrightness=1.0):
self.MQTTname = MQTTName #string
self.type = relaisType # possible: "relais" and "dimmer"
self.debug = debug
self.luxThreshold = luxThreshold #below this threshold in lux the PIR switches on
self.maxBrightness = maxBrightness #maximal brightness of the dimmer / relais
self.MQTTClient = MQTTClient #object
self.MQTTRelaisTopic = MQTTRelaisTopic #string
......@@ -64,11 +66,19 @@ class relais:
if self.timeLastStateConfirm is None: self.timeLastStateConfirm = time.time()
self.state = rStates.confirmed if self.vFeedback == self.v else rStates.switching
self.publishCurrentStatus(reason="relais feedback")
if self.debug: print(self.MQTTname,"Feedback Ende.")
self.printCurrentState()
if self.vFeedback > self.maxBrightness:
if self.debug: print(self.MQTTname, "Feedback brightness above maxBrightness. This will be reduced to", self.maxBrightness)
self.setV(self.maxBrightness, reason="Feedback above maxBrightness")
if self.debug: print(self.MQTTname,"Feedback Ende.")
def setV(self, v, t=None, reason=None):
if self.debug: print(self.MQTTname, "New Value set to:", v, "Old Value:", self.v)
if v > self.maxBrightness:
if self.debug: print(self.MQTTname, "While trying to set brightness to:", v, ", maxBrightness limited this to", self.maxBrightness)
v = self.maxBrightness
reason = "maxBrightness reached" if reason is None else reason+" and maxBrightness reached"
if t is None: t = time.time()
if len(self.lockingPIRs) == 0 or v == 0: self.lightdesire = rLightDesire.stable
if self.v != v: # a change of output state
......@@ -92,7 +102,7 @@ class relais:
if msg['v'] > 0 and self.luxThreshold > lux:
self.lockingPIRs.add(topic)
self.lightdesire = rLightDesire.lockedDueToPIR
self.setV(1, reason="PIR motion")
self.setV(self.maxBrightness, reason="PIR motion")
else:
self.lockingPIRs.discard(topic)
if len(self.lockingPIRs) == 0:
......@@ -103,11 +113,11 @@ class relais:
self.lockingPIRs)
elif msg['type'] in ('FRW', 'FHF', 'FSM60B', 'FTK', 'FTKE'): # smoke, window handle, waterleak, magnet, handle bar
if msg['v'] > 0:
self.setV(1, reason="defaultTopics "+msg['type'])
self.setV(self.maxBrightness, reason="defaultTopics "+msg['type'])
#else: #if these lines are active, eg the default status msg of smoke sensor will switch off a light
# self.setV(0, reason="defaultTopics "+msg['type'])
elif msg['type'] == "PTM215": # switches
if msg['v'] > 0: self.setV(1, reason="PTM215 pressed down, switch on") # Switch on, if key pressed down
if msg['v'] > 0: self.setV(self.maxBrightness, reason="PTM215 pressed down, switch on") # Switch on, if key pressed down
else:
print(self.MQTTname, "Error: Type not supported for defaultTopics.")
for x in self.prolongateStateTopics: # topics will only prolong the relais state
......@@ -140,7 +150,7 @@ class relais:
if msg['type'] == "PTM215": # switches
if msg['v'] > 0: # on key pressed down
if self.v == 0:
self.setV(1, reason="PTM215 pressed down, toggle") # Toggle
self.setV(self.maxBrightness, reason="PTM215 pressed down, toggle") # Toggle
else:
self.setV(0, reason="PTM215 pressed down, toggle")
else:
......@@ -151,7 +161,7 @@ class relais:
if msg['type'] == "PTM215": # switches
if msg['v'] > 0: # on key pressed down
if self.v == 0:
self.setV(1, reason="PTM215 pressed down, dimm up") # Toggle
self.setV(self.maxBrightness, reason="PTM215 pressed down, dimm up") # Toggle
else:
self.setV(0, reason="PTM215 pressed down, dimm down")
else:
......@@ -167,7 +177,7 @@ class relais:
if topic == x:
if self.debug: print(self.MQTTname, "inverseSwitchOnTopics:", topic, "msg:", msg)
if msg['type'] in ('FRW', 'FHF', 'FSM60B', 'FTK', 'FTKE'):
if msg['v'] == 0: self.setV(1, reason="inverseSwitchOnTopics "+msg['type']) # Switch on
if msg['v'] == 0: self.setV(self.maxBrightness, reason="inverseSwitchOnTopics "+msg['type']) # Switch on
else:
print(self.MQTTname, "Error: Type not supported for inverseSwitchOnTopics.")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment