|
@@ -895,24 +895,24 @@ try:
|
|
|
if (int(time.time()) - outSens_lastRun) > int(config['sensors'].get('publish_interval_outside', 60)):
|
|
|
outSens_lastRun = int(time.time())
|
|
|
|
|
|
+ count_used_out_sensors = 0
|
|
|
sum_out_sensors_temp = 0
|
|
|
+ sum_out_sensors_hum = 0
|
|
|
+
|
|
|
+ # "declare" variables with invalid high values - will be overwritten later or keep unused
|
|
|
sum_out_sensors_temp_min = 100
|
|
|
sum_out_sensors_temp_max = -50
|
|
|
- sum_out_sensors_hum = 0
|
|
|
sum_out_sensors_hum_min = 100
|
|
|
sum_out_sensors_hum_max = -50
|
|
|
- count_used_out_sensors = 0
|
|
|
|
|
|
- # "declare" variables with invalid high values - will be overwritten later
|
|
|
out_temp_publishvalue = 200
|
|
|
out_hum_publishvalue = 200
|
|
|
out_dewpoint = 200
|
|
|
out_abshum = 200
|
|
|
|
|
|
- # median
|
|
|
- if(config['sensors'].getboolean('outside_sensors_use_median')):
|
|
|
- out_sensors_temp_median_values = []
|
|
|
- out_sensors_hum_median_values = []
|
|
|
+ # arrays for median calculation
|
|
|
+ out_sensors_temp_median_values = []
|
|
|
+ out_sensors_hum_median_values = []
|
|
|
|
|
|
for id in sensors_outside_sensors:
|
|
|
lupd = sensors_lastUpdate.get(id, None)
|
|
@@ -924,18 +924,19 @@ try:
|
|
|
tmpval_t = sensors_lastAvgValue_temp.get(id, None)
|
|
|
tmpval_h = sensors_lastAvgValue_hum.get(id, None)
|
|
|
if tmpval_t is not None and tmpval_h is not None:
|
|
|
+ # sum - used for average
|
|
|
sum_out_sensors_temp = sum_out_sensors_temp + tmpval_t
|
|
|
sum_out_sensors_hum = sum_out_sensors_hum + tmpval_h
|
|
|
|
|
|
+ # memorize values from sensor with lowest reading
|
|
|
if tmpval_t < sum_out_sensors_temp_min:
|
|
|
sum_out_sensors_temp_min = tmpval_t
|
|
|
- if tmpval_t < sum_out_sensors_hum_min:
|
|
|
sum_out_sensors_hum_min = tmpval_h
|
|
|
|
|
|
+ # memorize values from sensor with highest reading
|
|
|
if tmpval_t > sum_out_sensors_temp_max:
|
|
|
sum_out_sensors_temp_max = tmpval_t
|
|
|
- if tmpval_t > sum_out_sensors_hum_max:
|
|
|
- sum_out_sensors_hum_max = tmpval_h
|
|
|
+ sum_out_sensors_hum_max = tmpval_h
|
|
|
|
|
|
# median
|
|
|
if(config['sensors'].getboolean('outside_sensors_use_median')):
|
|
@@ -949,18 +950,33 @@ try:
|
|
|
if count_used_out_sensors > 0:
|
|
|
out_temp_avg = round((sum_out_sensors_temp / count_used_out_sensors), 1)
|
|
|
out_hum_avg = int(round((sum_out_sensors_hum / count_used_out_sensors), 0))
|
|
|
-
|
|
|
- if(config['sensors'].getboolean('outside_sensors_use_median')):
|
|
|
- # median
|
|
|
+
|
|
|
+
|
|
|
+ # calc MEDIAN if there are more than 2 outside sensors
|
|
|
+ out_temp_median = 0
|
|
|
+ out_hum_median = 0
|
|
|
+ if count_used_out_sensors > 2:
|
|
|
out_temp_median = round(statistics.median(out_sensors_temp_median_values), 1)
|
|
|
out_hum_median = int(round(statistics.median(out_sensors_hum_median_values), 0))
|
|
|
- out_temp_publishvalue = out_temp_median
|
|
|
- out_hum_publishvalue = out_hum_median
|
|
|
+
|
|
|
+
|
|
|
+ # use MINIMUM if outside_sensors_force_minimum_value is enabled
|
|
|
+ if(config['sensors'].getboolean('outside_sensors_force_minimum_value')):
|
|
|
+ if sum_out_sensors_temp_min < 100:
|
|
|
+ out_temp_publishvalue = sum_out_sensors_temp_min
|
|
|
+ if sum_out_sensors_hum_min < 100:
|
|
|
+ out_hum_publishvalue = sum_out_sensors_hum_min
|
|
|
|
|
|
+ # use MEDIAN if outside_sensors_use_median is enabled and there are more than 2 sensors
|
|
|
+ elif(config['sensors'].getboolean('outside_sensors_use_median')) and count_used_out_sensors > 2:
|
|
|
+ out_temp_publishvalue = out_temp_median
|
|
|
+ out_hum_publishvalue = out_hum_median
|
|
|
+ # otherwise user AVERAGE
|
|
|
else:
|
|
|
out_temp_publishvalue = out_temp_avg
|
|
|
out_hum_publishvalue = out_hum_avg
|
|
|
|
|
|
+
|
|
|
# calc dewpoint
|
|
|
if config['sensors'].getboolean('calculate_dewpoint', False):
|
|
|
out_dewpoint = round(dewpoint(out_temp_avg, out_hum_avg), 1)
|
|
@@ -981,15 +997,19 @@ try:
|
|
|
if config['sensors'].getboolean('calculate_absolute_humidity', False):
|
|
|
mqttc.publish(topic_prefix_outside_temphum + '/absoluteHumidity', str(out_abshum), qos=0, retain=True)
|
|
|
|
|
|
+ # publish AVERAGE
|
|
|
mqttc.publish(topic_prefix_outside_temphum + '/temp_average', str(out_temp_avg), qos=0, retain=True)
|
|
|
mqttc.publish(topic_prefix_outside_temphum + '/hum_average', str(out_hum_avg), qos=0, retain=True)
|
|
|
|
|
|
- if(config['sensors'].getboolean('outside_sensors_use_median')):
|
|
|
+ # publish MEDIAN
|
|
|
+ if count_used_out_sensors > 2:
|
|
|
mqttc.publish(topic_prefix_outside_temphum + '/temp_median', str(out_temp_median), qos=0, retain=True)
|
|
|
mqttc.publish(topic_prefix_outside_temphum + '/hum_median', str(out_hum_median), qos=0, retain=True)
|
|
|
-
|
|
|
+
|
|
|
+ # publish last update
|
|
|
mqttc.publish(topic_prefix_outside_temphum + '/lastUpdate', strftime("%Y-%m-%d %H:%M:%S", localtime()), qos=0, retain=True)
|
|
|
-
|
|
|
+
|
|
|
+ # publish TempHumText
|
|
|
tmptext = str(out_temp_publishvalue) + "° " + str(out_hum_publishvalue) + "%"
|
|
|
mqttc.publish(topic_prefix_outside_temphum + "/TempHumText", tmptext, qos=0, retain=False)
|
|
|
|
|
@@ -1004,19 +1024,25 @@ try:
|
|
|
|
|
|
lacrosse_json = lacrosse_json + \
|
|
|
", \"temp_average\":" + str(out_temp_avg) + \
|
|
|
- ", \"hum_average\":" + str(out_hum_avg) + \
|
|
|
- ", \"temp_median\":" + str(out_temp_median) + \
|
|
|
- ", \"hum_median\":" + str(out_temp_median)
|
|
|
+ ", \"hum_average\":" + str(out_hum_avg)
|
|
|
+
|
|
|
+ if count_used_out_sensors > 2:
|
|
|
+ lacrosse_json = lacrosse_json + \
|
|
|
+ ", \"temp_median\":" + str(out_temp_median) + \
|
|
|
+ ", \"hum_median\":" + str(out_temp_median)
|
|
|
|
|
|
+ # publish MIN
|
|
|
if sum_out_sensors_temp_min < 100:
|
|
|
mqttc.publish(topic_prefix_outside_temphum + '/temp_min', str(sum_out_sensors_temp_min), qos=0, retain=False)
|
|
|
lacrosse_json = lacrosse_json + ", \"temp_min\":" + str(sum_out_sensors_temp_min)
|
|
|
- if sum_out_sensors_temp_max > -50:
|
|
|
- mqttc.publish(topic_prefix_outside_temphum + '/temp_max', str(sum_out_sensors_temp_max), qos=0, retain=False)
|
|
|
- lacrosse_json = lacrosse_json + ", \"temp_max\":" + str(sum_out_sensors_temp_max)
|
|
|
if sum_out_sensors_hum_min < 100:
|
|
|
mqttc.publish(topic_prefix_outside_temphum + '/hum_min', str(sum_out_sensors_hum_min), qos=0, retain=False)
|
|
|
lacrosse_json = lacrosse_json + ", \"hum_min\":" + str(sum_out_sensors_hum_min)
|
|
|
+
|
|
|
+ # publish MAX
|
|
|
+ if sum_out_sensors_temp_max > -50:
|
|
|
+ mqttc.publish(topic_prefix_outside_temphum + '/temp_max', str(sum_out_sensors_temp_max), qos=0, retain=False)
|
|
|
+ lacrosse_json = lacrosse_json + ", \"temp_max\":" + str(sum_out_sensors_temp_max)
|
|
|
if sum_out_sensors_hum_max > -50:
|
|
|
mqttc.publish(topic_prefix_outside_temphum + '/hum_max', str(sum_out_sensors_hum_max), qos=0, retain=False)
|
|
|
lacrosse_json = lacrosse_json + ", \"hum_max\":" + str(sum_out_sensors_hum_max)
|