diff --git a/measurement.py b/measurement.py index 2a45ab5..d6e2c8b 100644 --- a/measurement.py +++ b/measurement.py @@ -39,7 +39,7 @@ def measure_all_sensors(debug, filtered_temperature, ds18b20Sensors, bme680Senso # if we have at leat one filtered value we can upload ds18b20_temperature = filtered_temperature[sensorIndex].pop() if sensor["ts_field"] and ds18b20_temperature is not None: - if 'offset' in sensor: + if 'offset' in sensor and sensor["offset"] is not None: ds18b20_temperature = ds18b20_temperature-float(sensor["offset"]) ds18b20_temperature = float("{0:.2f}".format(ds18b20_temperature)) # round to two decimals ts_fields.update({sensor["ts_field"]: ds18b20_temperature}) @@ -47,8 +47,9 @@ def measure_all_sensors(debug, filtered_temperature, ds18b20Sensors, bme680Senso # Case for filtered_temperature was not filled, use direct measured temperture in this case ds18b20_temperature = measure_temperature(sensor) if sensor["ts_field"] and ds18b20_temperature is not None: - if 'offset' in sensor: + if 'offset' in sensor and sensor["offset"] is not None: ds18b20_temperature = ds18b20_temperature-float(sensor["offset"]) + ds18b20_temperature = float("{0:.2f}".format(ds18b20_temperature)) # round to two decimals ts_fields.update({sensor["ts_field"]: ds18b20_temperature}) except Exception as e: error_log(e, "Unhandled Exception in measure_all_sensors / ds18b20Sensors") diff --git a/read_bme280.py b/read_bme280.py index 2d9d2d5..c76b08f 100644 --- a/read_bme280.py +++ b/read_bme280.py @@ -13,7 +13,7 @@ def measure_bme280(ts_sensor): # ThingSpeak fields # Create returned dict if ts-field is defined if 'ts_field_temperature' in ts_sensor and isinstance(temperature, (int, float)): - if 'offset' in ts_sensor and isinstance(ts_sensor["offset"], (int, float)): + if 'offset' in ts_sensor and ts_sensor["offset"] is not None: temperature = temperature-ts_sensor["offset"] fields[ts_sensor["ts_field_temperature"]] = round(temperature, 2) if 'ts_field_humidity' in ts_sensor and isinstance(humidity, (int, float)): diff --git a/read_dht.py b/read_dht.py index a2200ce..65de565 100644 --- a/read_dht.py +++ b/read_dht.py @@ -26,10 +26,10 @@ def measure_dht(ts_sensor): # Create returned dict if ts-field is defined if 'ts_field_temperature' in ts_sensor and temperature is not None: + if 'offset' in ts_sensor and ts_sensor["offset"] is not None: + temperature = temperature-float(ts_sensor["offset"]) # limit to 2 digits temperature = float("{0:.2f}".format(temperature)) - if 'offset' in ts_sensor: - temperature = temperature-float(ts_sensor["offset"]) fields[ts_sensor["ts_field_temperature"]] = temperature if 'ts_field_humidity' in ts_sensor and humidity is not None: # limit to 2 digits