diff --git a/plugin.py b/plugin.py index 6acdcf2..37becc4 100755 --- a/plugin.py +++ b/plugin.py @@ -34,7 +34,7 @@ import urllib.parse as parse import urllib.request as request import base64 import time -from datetime import datetime +from datetime import datetime, timedelta DEFAULT_POOLING = 30 #multiple of 15 sec DEFAULT_DURATION = 30 @@ -129,8 +129,7 @@ class BasePlugin: self.planning.append((start_end[0], start_end[1])) if len(self.planning) != 7: raise Exception("Incorrect planning...") - - + def onHeartbeat(self): if self.pooling_current_step == self.pooling_steps: #Now @@ -138,8 +137,8 @@ class BasePlugin: weekday = datetime.today().weekday() # Get device values - n_in, t_in, h_in, dp_in = get_temp_devide_info(self.in_id) - n_out, t_out, h_out, dp_out = get_temp_devide_info(self.out_id) + n_in, t_in, h_in, dp_in, lu_in = get_temp_devide_info(self.in_id) + n_out, t_out, h_out, dp_out, lu_out = get_temp_devide_info(self.out_id) # Get switch values n_sw, s_sw = get_switch_device_info(self.switch_id) @@ -150,7 +149,7 @@ class BasePlugin: Domoticz.Debug("Last 3 minutes of indoor humidity: " + str(self.histo_hum)) if self.delay_in_progress == False and self.mode == False and s_sw == True: - #Some one manually swtch on the device + #Someone manually switched on the device #We keep the time self.last_time = now self.delay_in_progress = True @@ -159,7 +158,7 @@ class BasePlugin: Domoticz.Debug("Start delay={}".format(now)) # If % huminidy > MAX ==> ON - if check_rule(self.rule, t_in, h_in, dp_in, t_out, h_out, dp_out, self.histo_hum): + if check_rule(self.rule, t_in, h_in, dp_in, lu_in, t_out, h_out, dp_out, lu_out, self.histo_hum): self.mode = True #On #We also keep the time, but only if in the authorized time range if is_between(time.strftime("%H:%M", time.localtime(now)), self.planning[weekday]): @@ -212,6 +211,7 @@ def get_temp_devide_info(idx): res = DomoticzAPI("type=devices&rid={0}".format(idx)) name = res['result'][0]['Name'] temp = res['result'][0]['Temp'] + lastUpdate = res['result'][0]['LastUpdate'] try: hum = res['result'][0]['Humidity'] except: @@ -220,8 +220,8 @@ def get_temp_devide_info(idx): dewpoint = res['result'][0]['DewPoint'] except: dewpoint = -100 - Domoticz.Debug("Device #{}: {} / T={}°C / H={}% / DP={}°C".format(idx, name, temp, hum, dewpoint)) - return name, float(temp), float(hum), float(dewpoint) + Domoticz.Debug("Device #{}: {} / T={}°C / H={}% / DP={}°C ({})".format(idx, name, temp, hum, dewpoint, lastUpdate)) + return name, float(temp), float(hum), float(dewpoint), str(lastUpdate) def get_switch_device_info(idx): res = DomoticzAPI("type=devices&rid={0}".format(idx)) @@ -238,7 +238,10 @@ def switch_on_off(idx, mode=0): Domoticz.Status("Switch #{} is now '{}'.".format(idx, cmd)) return -def check_rule(exp, t_in, h_in, dp_in, t_out, h_out, dp_out, histo_hum): +def check_rule(exp, t_in, h_in, dp_in, lu_in, t_out, h_out, dp_out, lu_out, histo_hum): + if lu_in<(datetime.now()-timedelta(minutes=DEFAULT_DURATION)).strftime("%Y-%m-%d %H:%M:%S"): + Domoticz.Status("Device In seems obsolete ({})".format(lu_in)) + return False h_in_delta = float(h_in) - min(histo_hum) res = eval(exp) Domoticz.Debug("Check rule: {} ==> {}".format(exp, res))