Stop the deshimidificator when the in device is obsolete.
This commit is contained in:
23
plugin.py
23
plugin.py
@@ -34,7 +34,7 @@ import urllib.parse as parse
|
|||||||
import urllib.request as request
|
import urllib.request as request
|
||||||
import base64
|
import base64
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
DEFAULT_POOLING = 30 #multiple of 15 sec
|
DEFAULT_POOLING = 30 #multiple of 15 sec
|
||||||
DEFAULT_DURATION = 30
|
DEFAULT_DURATION = 30
|
||||||
@@ -129,8 +129,7 @@ class BasePlugin:
|
|||||||
self.planning.append((start_end[0], start_end[1]))
|
self.planning.append((start_end[0], start_end[1]))
|
||||||
if len(self.planning) != 7:
|
if len(self.planning) != 7:
|
||||||
raise Exception("Incorrect planning...")
|
raise Exception("Incorrect planning...")
|
||||||
|
|
||||||
|
|
||||||
def onHeartbeat(self):
|
def onHeartbeat(self):
|
||||||
if self.pooling_current_step == self.pooling_steps:
|
if self.pooling_current_step == self.pooling_steps:
|
||||||
#Now
|
#Now
|
||||||
@@ -138,8 +137,8 @@ class BasePlugin:
|
|||||||
weekday = datetime.today().weekday()
|
weekday = datetime.today().weekday()
|
||||||
|
|
||||||
# Get device values
|
# Get device values
|
||||||
n_in, t_in, h_in, dp_in = get_temp_devide_info(self.in_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 = get_temp_devide_info(self.out_id)
|
n_out, t_out, h_out, dp_out, lu_out = get_temp_devide_info(self.out_id)
|
||||||
# Get switch values
|
# Get switch values
|
||||||
n_sw, s_sw = get_switch_device_info(self.switch_id)
|
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))
|
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:
|
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
|
#We keep the time
|
||||||
self.last_time = now
|
self.last_time = now
|
||||||
self.delay_in_progress = True
|
self.delay_in_progress = True
|
||||||
@@ -159,7 +158,7 @@ class BasePlugin:
|
|||||||
Domoticz.Debug("Start delay={}".format(now))
|
Domoticz.Debug("Start delay={}".format(now))
|
||||||
|
|
||||||
# If % huminidy > MAX ==> ON
|
# 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
|
self.mode = True #On
|
||||||
#We also keep the time, but only if in the authorized time range
|
#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]):
|
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))
|
res = DomoticzAPI("type=devices&rid={0}".format(idx))
|
||||||
name = res['result'][0]['Name']
|
name = res['result'][0]['Name']
|
||||||
temp = res['result'][0]['Temp']
|
temp = res['result'][0]['Temp']
|
||||||
|
lastUpdate = res['result'][0]['LastUpdate']
|
||||||
try:
|
try:
|
||||||
hum = res['result'][0]['Humidity']
|
hum = res['result'][0]['Humidity']
|
||||||
except:
|
except:
|
||||||
@@ -220,8 +220,8 @@ def get_temp_devide_info(idx):
|
|||||||
dewpoint = res['result'][0]['DewPoint']
|
dewpoint = res['result'][0]['DewPoint']
|
||||||
except:
|
except:
|
||||||
dewpoint = -100
|
dewpoint = -100
|
||||||
Domoticz.Debug("Device #{}: {} / T={}°C / H={}% / DP={}°C".format(idx, name, temp, hum, dewpoint))
|
Domoticz.Debug("Device #{}: {} / T={}°C / H={}% / DP={}°C ({})".format(idx, name, temp, hum, dewpoint, lastUpdate))
|
||||||
return name, float(temp), float(hum), float(dewpoint)
|
return name, float(temp), float(hum), float(dewpoint), str(lastUpdate)
|
||||||
|
|
||||||
def get_switch_device_info(idx):
|
def get_switch_device_info(idx):
|
||||||
res = DomoticzAPI("type=devices&rid={0}".format(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))
|
Domoticz.Status("Switch #{} is now '{}'.".format(idx, cmd))
|
||||||
return
|
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)
|
h_in_delta = float(h_in) - min(histo_hum)
|
||||||
res = eval(exp)
|
res = eval(exp)
|
||||||
Domoticz.Debug("Check rule: {} ==> {}".format(exp, res))
|
Domoticz.Debug("Check rule: {} ==> {}".format(exp, res))
|
||||||
|
|||||||
Reference in New Issue
Block a user