|
@@ -15,6 +15,7 @@ import sys
|
|
|
import paho.mqtt.client as mqtt
|
|
|
import yaml
|
|
|
import json
|
|
|
+import statistics
|
|
|
#import math
|
|
|
#import numpy as np
|
|
|
#import httplib
|
|
@@ -692,6 +693,10 @@ try:
|
|
|
sum_out_sensors_hum_max = -50
|
|
|
count_used_out_sensors = 0
|
|
|
|
|
|
+ # median
|
|
|
+ out_sensors_temp_median_values = []
|
|
|
+ out_sensors_hum_median_values = []
|
|
|
+
|
|
|
for id in sensors_outside_sensors:
|
|
|
lupd = sensors_lastUpdate.get(id, None)
|
|
|
tdiff = 0
|
|
@@ -715,6 +720,10 @@ try:
|
|
|
if tmpval_t > sum_out_sensors_hum_max:
|
|
|
sum_out_sensors_hum_max = tmpval_h
|
|
|
|
|
|
+ # median
|
|
|
+ out_sensors_temp_median_values.append(tmpval_t)
|
|
|
+ out_sensors_hum_median_values.append(tmpval_h)
|
|
|
+
|
|
|
count_used_out_sensors += 1
|
|
|
|
|
|
lacrosse_json = None
|
|
@@ -723,24 +732,46 @@ try:
|
|
|
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))
|
|
|
|
|
|
- mqttc.publish(mqtt_topic_atemp, str(out_temp_avg), qos=0, retain=True)
|
|
|
- mqttc.publish(mqtt_topic_ahum, str(out_hum_avg), qos=0, retain=True)
|
|
|
+ # median
|
|
|
+ out_temp_median = statistics.median(out_sensors_temp_median_values)
|
|
|
+ out_hum_median = statistics.median(out_sensors_hum_median_values)
|
|
|
+
|
|
|
+ out_temp_publishvalue = out_temp_avg
|
|
|
+ out_hum_publishvalue = out_hum_avg
|
|
|
+ if(config['sensors'].get('outside_sensors_use_median')):
|
|
|
+ out_temp_publishvalue = out_temp_median
|
|
|
+ out_hum_publishvalue = out_hum_median
|
|
|
+
|
|
|
+ mqttc.publish(mqtt_topic_atemp, str(out_temp_publishvalue), qos=0, retain=True)
|
|
|
+ mqttc.publish(mqtt_topic_ahum, str(out_hum_publishvalue), qos=0, retain=True)
|
|
|
+ mqttc.publish(topic_prefix_outside_temphum + '/temperature', str(out_temp_publishvalue), qos=0, retain=True)
|
|
|
+ mqttc.publish(topic_prefix_outside_temphum + '/humidity', str(out_hum_publishvalue), qos=0, retain=True)
|
|
|
|
|
|
- mqttc.publish(topic_prefix_outside_temphum + '/temperature', str(out_temp_avg), qos=0, retain=True)
|
|
|
- mqttc.publish(topic_prefix_outside_temphum + '/humidity', str(out_hum_avg), qos=0, retain=True)
|
|
|
+ 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)
|
|
|
+ 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)
|
|
|
mqttc.publish(topic_prefix_outside_temphum + '/lastUpdate', strftime("%Y-%m-%d %H:%M:%S", localtime()), qos=0, retain=True)
|
|
|
|
|
|
- tmptext = str(out_temp_avg) + "° " + str(out_hum_avg) + "%"
|
|
|
+ tmptext = str(out_temp_publishvalue) + "° " + str(out_hum_publishvalue) + "%"
|
|
|
mqttc.publish(topic_prefix_outside_temphum + "/TempHumText", tmptext, qos=0, retain=False)
|
|
|
|
|
|
- lacrosse_json = "{\"temperature\":" + str(out_temp_avg) + ", \"humidity\":" + str(out_hum_avg) + "\", \"usedSensors\":" + str(count_used_out_sensors) + "}"
|
|
|
+ lacrosse_json = "{\"temperature\":" + str(out_temp_publishvalue) + \
|
|
|
+ ", \"humidity\":" + str(out_hum_publishvalue) + \
|
|
|
+ "\", \"usedSensors\":" + str(count_used_out_sensors) + "}"
|
|
|
|
|
|
min = 100
|
|
|
max = 100
|
|
|
if count_used_out_sensors > 1:
|
|
|
mqttc.publish(topic_prefix_outside_temphum + '/usedSensors', str(count_used_out_sensors), qos=0, retain=True)
|
|
|
|
|
|
- lacrosse_json = "{\"temperature\":" + str(out_temp_avg) + ", \"humidity\":" + str(out_hum_avg) + ", \"usedSensors\":" + str(count_used_out_sensors)
|
|
|
+ lacrosse_json = "{\"temperature\":" + str(out_hum_publishvalue) + \
|
|
|
+ ", \"humidity\":" + str(out_hum_publishvalue) + \
|
|
|
+ ", \"usedSensors\":" + str(count_used_out_sensors) + \
|
|
|
+ ", \"temp_average\":" + str(out_temp_avg) + \
|
|
|
+ ", \"hum_average\":" + str(out_hum_avg) + \
|
|
|
+ ", \"temp_median\":" + str(out_temp_median) + \
|
|
|
+ ", \"hum_median\":" + str(out_temp_median)
|
|
|
|
|
|
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)
|