Browse Source

## 2024-12-28
* combined outside sensors: add option outside_sensors_force_minimum_value to force usage of the lowest sensor reading from all combined outside sensors rather than average oder median
* combined outside sensors: fixed handling auf minimum and maximum humidity (use humidity from sensor with lowest temperature reading instead of the lowest humidity reading)
* combined outside sensors: always calculate median, but only if more than 2 sensors are present
* combined outside sensors: only use median even if configured if more than 2 sensors are present, otherwise average (if outside_sensors_force_minimum_value is false)
* add some more comments to source file and ini file

FloKra 3 months ago
parent
commit
74f9ac9d7b
3 changed files with 79 additions and 26 deletions
  1. 7 0
      CHANGELOG.md
  2. 22 2
      jeelinklog/jeelinklog.ini
  3. 50 24
      jeelinklog/jeelinklog.py

+ 7 - 0
CHANGELOG.md

@@ -1,5 +1,12 @@
 # JeeLinkLogMQTT - change log
 
+## 2024-12-28
+* combined outside sensors: add option outside_sensors_force_minimum_value to force usage of the lowest sensor reading from all combined outside sensors rather than average oder median
+* combined outside sensors: fixed handling auf minimum and maximum humidity (use humidity from sensor with lowest temperature reading instead of the lowest humidity reading)
+* combined outside sensors: always calculate median, but only if more than 2 sensors are present
+* combined outside sensors: only use median even if configured if more than 2 sensors are present, otherwise average (if outside_sensors_force_minimum_value is false)
+* add some more comments to source file and ini file
+
 ## 2024-03-29
 * add option to speficy JeeLink initialisation command (support different sensor baud rates concurrently by set JeeLink to toggle mode, i.E. when using TX29 AND TX35 sensors)
 * add config option (Jeelink) initTimeout

+ 22 - 2
jeelinklog/jeelinklog.ini

@@ -58,8 +58,10 @@ publish_unknown_new_sensors = True
 # average sensor values - average over that many received readings
 average_value_steps = 5
 
+# discard measurements that are off more than this
 max_off_value = 2.0
 
+# ignore off values after this timeout and proceed with them
 ignore_off_value_timeout = 60
 
 # interval in s to report data via MQTT
@@ -68,19 +70,37 @@ publish_interval = 60
 # interval in s to store data in InfluxDB
 store_interval = 300
 
+# interval in s to report data via MQTT for combined outside sensor
 publish_interval_outside = 120
+
+# interval in s to store data in InfluxDB for combined outside sensor
 store_interval_outside = 300
 
+# maximum age of sensor data in s - if the newest sensor data is older than that the sensor is considered "offline"
 data_maxage = 600
 
-outside_sensors_use_median = True
-# otherwise average is used
 
+
+# calculate dewpoint and abs. humidity (applies to all sensors)
 calculate_dewpoint = True
 calculate_absolute_humidity = True
+# and write this also to InfluxDB
 write_dewpoint_to_influxdb = True
 write_abshum_to_influxdb = True
 
+
+
+# combined outside sensors handling
+
+# Use median rather than average value. 
+# Only useful if more than 2 outside sensors are used. 
+outside_sensors_use_median = True
+
+# Use minimum value instead of average or median. 
+# Overrules "outside_sensors_use_median" setting. 
+# Best if one or more sensors could be exposed to direct sunlight or other heat sources for some time of the day. 
+outside_sensors_force_minimum_value = False
+
 # for calculated (averaged from multiple sensors)
 influxdb_instance_combined_outside_sensors = wetter
 influxdb_sensorname_combined_outside_sensors = Outside

+ 50 - 24
jeelinklog/jeelinklog.py

@@ -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)