Browse Source

* DHT sensor reading - retry if failed (does not fix issue)
* improved temperature sensor timeout handling
* updated Adafruit DHT22 sensor lib to 1.3.7 - that seems to have finally fixed the sensor reading issue
* renamed "misc" to "scheduler" as it contains only timing/scheduling functions
* added README_DE.md

FloKra 4 years ago
parent
commit
3eb0ee4b47

+ 5 - 2
CHANGELOG.md

@@ -1,6 +1,9 @@
 # WiFiThermostat - Changelog
 # WiFiThermostat - Changelog
 ## 0.3.3
 ## 0.3.3
-* try fixing DHT sensor reading errors by adding some short delay before/after
+* DHT sensor reading - retry if failed (does not fix issue)
+* improved temperature sensor timeout handling
+* updated Adafruit DHT22 sensor lib to 1.3.7 - that seems to have finally fixed the sensor reading issue
+* renamed "misc" to "scheduler" as it contains only timing/scheduling functions
 
 
 ## 0.3.2
 ## 0.3.2
 * fixed/improved: HTTP authentication handling
 * fixed/improved: HTTP authentication handling
@@ -56,7 +59,7 @@
 * added http control api with token
 * added http control api with token
 * added mqttReconnect http call
 * added mqttReconnect http call
 * bugfixes
 * bugfixes
-* some documentation
+* some documentation
 
 
 Important: for now compiled using Arduino 1.8.5 with ESP8266-Arduino core 2.4.0-rc2, as WiFi (re)connection does not work properly in release 2.4.0 (spent many hours on that)!!
 Important: for now compiled using Arduino 1.8.5 with ESP8266-Arduino core 2.4.0-rc2, as WiFi (re)connection does not work properly in release 2.4.0 (spent many hours on that)!!
 
 

+ 32 - 0
HARDWARE_DE.md

@@ -0,0 +1,32 @@
+## Hardware
+
+### Bedien- bzw. Steuerungseinheit
+Anschluss anstelle des bestehenden Raumthermostat, versorgt von der Versorgungs-/Schalteinheit. 
+
+__Achtung: kein direkter Anschluss ohne Versorgungseinheit!! Die maximale Versorgungsspannung beträgt ca. 9V.__
+
+ - Anschlüsse: 
+   - Versorgung (5V)
+   - Masse
+   - Schaltsignal (Massegeschaltet)
+   
+
+* bestehend aus: 
+  - kompaktes Gehäuse zur Wandmontage
+  - LCD Display (Standard 1602 LCD mit I²C-Schnittstelle, 2x 16 Zeichen) zur Anzeige der aktuellen und eingestellten Temperatur, Betriebsmodus und Netzwerkverbindung
+  - 3 Tasten zur direkten Steuerung (Plus, Minus, Mode)
+  - Temperature/Luftfeuchte-Sensor Typ DHT22
+  - PCB mit ESP8266 MCU (Wemos D1 mini Modul), Schalttransistor zur Ansteuerung des Relais
+
+### Versorgungs-/Schalteinheit
+* bestehend aus:
+  - Netzteil zur Fernspeisung des Thermostat
+  - Schaltrelais zur eigentlichen Ansteuerung der Heizung
+
+* Wird beim Heizgerät sowie an die Leizungen zum Thermostat angeschlossen
+  - Anschlüsse:
+    - Versorgung (230V L + N)
+    - Relais für Heizung - Anschluss an die Leitungen des originalen Thermostat zum Heizgerät (geeignet für 5 VDC - 230 VAC Schaltspannung, für Elektroheizungen mit hoher Stromaufnahme muss ein zusätzliches Entlastungsrelais verbaut werden)
+
+
+[Hauptseite](./README_DE.md)

+ 57 - 0
LIBRARIES.md

@@ -0,0 +1,57 @@
+## Libraries
+
+### ESP8266 core for Arduino 2.4.0 beta2 (as 2.4 release has connection bugs)
+* ESP8266WiFi.h
+* WiFiClient.h
+* ESP8266WebServer.h
+* ESP8266mDNS.h
+* ESP8266HTTPUpdateServer.h
+* DNSServer.h
+* FS.h (SPIFFS)
+* Wire.h (I2C library)
+
+https://github.com/esp8266/Arduino
+
+### ArduinoJson 5.13.0
+from library manager
+
+### Adafruit DHT-sensor-library (DHT.h)
+Used unmodified for reading the DHT22 sensor. 
+
+https://github.com/adafruit/DHT-sensor-library
+
+### Adafruit Sensor 1.0.2
+Not really used, but has to be installed when using Adafruit DHT-sensor-library (even if I dont use the DHT_U.h version included in this lib, but gives compile error if not installed).
+
+https://github.com/adafruit/Adafruit_Sensor
+
+### r-downing PersWiFiManager 3.0.1
+AP with captive portal for initial (WiFi-) configuration. 
+Used with modification - added #define WIFI_HTM_PROGMEM to PersWiFiManager.cpp (turns off SPIFFS usage and stores HTML page to PROGMEM)
+
+https://github.com/r-downing/PersWiFiManager
+
+### knolleary PubSubClient 2.7
+MQTT client for Arduino. Used with the following modified DEFINEs in PubSubClient.h: 
+* MQTT_MAX_PACKET_SIZE: increased to 512, needed for receiving/parsing domoticz/out topic
+
+https://github.com/knolleary/pubsubclient
+
+https://pubsubclient.knolleary.net/
+
+### LiquidCrystal I2C (commit e3701fb, Mar 9 2017)
+
+https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library
+
+### r89m Button + PushButton
+Button handling library with callbacks on press, release, hold, hold-repeat.
+PushButton.h extends Button.h.
+
+https://github.com/r89m/PushButton
+
+https://github.com/r89m/Button
+
+### Bounce2
+used by r89m Button/PushButton.
+
+https://github.com/thomasfredericks/Bounce2

+ 5 - 2
README.md

@@ -1,9 +1,12 @@
 # WiFiThermostat
 # WiFiThermostat
 
 
-ESP8266 based, WiFi connected set-point thermostat designed as replacement for electric room thermostats used for most domestic heating systems. 
+ESP8266 based, WiFi connected thermostat designed as replacement for electronic room thermostats used for most domestic heating systems. 
+
+[Deutsche version](./README_DE.md)
 
 
 ## Features
 ## Features
-* current temperature/humidity measurement using DHT22 sensor with value smoothing
+* current temperature/humidity measurement using a digital DHT22 type sensor
+* smoothing of measured values, filtering of 
 * thermostat with configurable hysteresis and 3 modes with different set-point temperatures (normal, 2x reduction)
 * thermostat with configurable hysteresis and 3 modes with different set-point temperatures (normal, 2x reduction)
 * control unit with LCD and 3 pushbuttons
 * control unit with LCD and 3 pushbuttons
 * power unit with power supply and relais for heating control
 * power unit with power supply and relais for heating control

+ 87 - 0
README_DE.md

@@ -0,0 +1,87 @@
+# WiFiThermostat
+
+WLAN-angebundener Raumthermostat für elektrisch gesteuerte Heizungen basierend auf dem ESP8266 Microcontroller
+
+[English version](./README.md)
+
+## Vorüberlegungen
+Ich war auf der Suche nach WLAN-fähigem Ersatz für einen bestehenden Raumthermostat, um die Heizungssteuerung zukünftig in ein Home Automation System einbinden zu können. 
+
+Ziel war dabei ein offenes System, keine Abhängigkeit von Cloud-Diensten und ein hoher Automatisierungsgrad, den "normale" Thermostate nicht bieten können. Zeitsteuerungen, wie sie viele am Markt erhältliche Lösungen bieten erscheinen nur bedingt sinnvoll, da fixe Heizzeiten zumindest in meinem Fall nicht den tatsächlichen Bedarf abdecken können. Die Steuerung sollte also möglichst - neben definierten Zeitfenstern - die Anwesenheit in der Wohnung mit einbeziehen, sowie eine Fernsteuerung via Internet ermöglichen. Prinzipiell nicht allzu schwierig zu lösen mit diversen Home Automation Servern, vor allem da ich so etwas sowieso schon experimentell im Einsatz hatte. 
+
+Zum damaligen Zeitpunkt gab es am Markt nur einige wenige Produkte der Kategorie "Smart Thermostat" mit welchen das prinzipiell lösbar war. Sogar welche mit Anwesenheitserkennung via Android-App (und Hersteller-Cloud). Zum Teil sehr ansehnliche Geräte, aber alle hatten Probleme die mich letztlich vom Kauf absehen ließen: 
+- die meisten verbreiteten Lösungen bestehen aus einer Zentraleinheit und per Funk angebundenen Heizkörperventilen
+  - für meinen Bedarf nicht geeignet, da eigene Gastherme in der Wohnung und alte, mit Thermostatventilen inkompatible Heizkörper
+- weitere Funk-basierte Lösungen
+  - neben der Bedieneinheit für den Raumthermostat auch noch ein proprietäres LAN-Funk-Gateway und ein Relais-Modul notwendig
+- Abhängigkeit von Cloud-Diensten des Herstellers (designed für die Bedienung via Smartphone-App, für netzwerktechnisch unbedarfte User... oder doch Daten sammeln...?)
+  - für mich das absolute No-Go für solche Geräte. Das MUSS ganz einfach funktionieren auch wenn das Internet oder das WLAN länger ausfällt. Zumindest inwieweit ein Offline-Notbetrieb möglich ist ist meist in den Unterlagen gar nicht ersichtlich. 
+  - was passiert, wenn der Hersteller die Dienste für sein nicht mehr lukratives altes Produkt einstellt oder Pleite geht? 
+- keine offenen Schnittstellen, bzw. keine, die lokal aus dem Netzwerk ansprechbar und ohne Cloud-Service nutzbar waren, oder auch einfach nicht (ausreichend) dokumentiert
+- Verfügbarkeit (nicht alle Produkte werden überall vertrieben bzw. offiziell unterstützt, Grauimport wäre zwar möglich aber im Garantiefall ungut)
+- zu teuer, zu "hip", zu komplex Umgesetzt für die eigentlich einfache Aufgabe
+
+Nach einiger Zeit - und da auch in der Open Source Welt nichts 100% passendes oder nur experimentelle Ansätze zu finden waren - stand für mich irgendwann fest: entweder selbst machen oder gar nicht. 
+
+### Klar war...
+* für die Aufgabe würde ein einfacher, leistungsschwacher, WLAN-fähiger Microcontroller wie der ESP8266, mit dem ich bereits seit einiger Zeit experimentiert hatte, vollkommen ausreichen
+* ich brauche und möchte keine Touch-Bedienung, Vollfarb-Display usw. - günstige Standardkomponenten wie ein 1602 LCD character display und normale Taster reicht
+* keine eingebauten Timer/Uhr nötig, da die Steuerung über den Home Automation Server sowieso "intelligenter" als fix konfigurierte Timer ist oder dies zumindest mehr als abdecken kann
+
+## Entwicklungsziele
+* so einfach wie möglich, so kompliziert wie nötig
+* Standalone-Betrieb bei Ausfall der Infrastruktur muss möglich sein
+* Betriebssicherheit hat oberste Priorität
+* Aufbau aus leicht verfügbaren Standardkomponenten (tatsächlich hatte ich für den Prototypen abgesehen vom Gehäuse alle Teile in meinem Bastel-Kastel)
+* offene Schnittstellen, kein "Cloudzwang"
+
+## Voraussetzungen und Kompatibilität
+* kann alle Raumthermostate ersetzen, die eine Heizung per Schaltkontakt (230V oder 24V) direkt ansteuern
+* Bus- oder Funkangebundene Thermostate/Heizungssteuerungen werden nicht unterstützt
+* Verkabelung - 3 direkte Leitungen vom Heizgerät zum Thermostat müssen vorhanden und getrennt von der restlichen Elektroinstallation sein
+
+## Funktionsüberblick
+* Messung der aktuellen Raumtemperatur und Luftfeuchtigkeit mit einem DHT22-Sensor
+* Glättung der Messwerte, Ausfilterung nicht plausibler Werte (falls solche auftreten)
+* Thermostat mit konfigurierbarer Hysterese und 3 Modi (Normalbetrieb, Nachtabsenkung, Langzeit-Absenkung)
+* Steuerungseinheit mit LCD Display und Tasten zur direkten Bedienung
+* separate Versorgungs- und Bedieneinheit
+* Fernsteuerung aller Funktionen über WLAN (MQTT-Protokoll, Web-Interface)
+* problemloser Standalone-Betrieb auch ohne Netzwerkverbindung
+* Einrichtung/Konfiguration via Web-Interface
+* offene Schnittstellen (MQTT, Web-API)
+* aktuelle Einstellung kann automatisch abgespeichert werden und übersteht so auch Stromausfälle
+* Telemetrie der Messdaten und Statusinformationen via WLAN (MQTT-Protokoll)
+* Konfiguration bestimmter Parameter (Absenktemperaturen usw.) auch via MQTT
+* Anschluss eines Bewegungsmelder-Moduls möglich, welcher automatisch die Displaybeleuchtung aktivieren kann (ansonsten nur zur Meldung an einen Home-Automation-Server wie Home Assistant vorgesehen, Status wird über MQTT gesendet)
+* initiale Einrichtung via WLAN im AP-Modus mit captive portal
+* Anzeige der Außentemperatur am Display (wenn diese über MQTT angeliefert wird)
+* Betriebssicherheit: 
+  - falsche/unplausible Messwerte vom Temperatursensor werden ignoriert - Heizungssteuerung erfolgt nur wenn ein aktueller und plausibler Messwert vorliegt
+  - automatische Neuverbindung wenn die Verbindung getrennt wird
+  - automatischer Neustart wenn über einen längeren Zeitraum WLAN oder der MQTT-Server nicht verbunden werden kann
+  - automatischer Neustart falls die Software nicht mehr reagiert (ESP8266 eingebauter WDT Timer)
+  - Betriebsfähigkeit bleibt immer weitestgehend erhalten (Ausgenommen Funktionen die Netzwerk benötigen wenn keine Verbindung besteht bzw. ein zyklische kurze Ausfälle im Fall eines notwendigen Neustarts (konfigurierbar))
+* Vorgesehen für Steuerung durch folgende Home Automation Systeme (via MQTT-Protokoll oder HTTP API):
+    - Home Assistant
+      - primäre Zielplattform
+	  - Funktionen:
+        - Änderung der Soll-Temperatur
+        - Änderung des Modus (Normalbetrieb, Nachtabsenkung...) 
+        - Anzeige von aktueller Temperatur/Luftfeuchtigkeit, Status der Heizung
+        - Automatische Aktualisierung bei Änderungen lokal am Bedienteil oder via Web-Interface
+    - Domoticz
+	  - frühere Zielplattform
+        - seit Anfang 2018 nicht mehr weiterentwickelt
+      - Funktionsumfang wie Home Assistant
+    - OpenHAB
+      - ungetestet, sollte aber über die Befehle für Home Assistant funktionieren
+
+
+ 
+ 
+ 
+ 
+[Hardware](./HARDWARE_DE.md)
+
+[Software](./SOFTWARE_DE.md)

+ 63 - 0
SOFTWARE_DE.md

@@ -0,0 +1,63 @@
+# Software
+
+## Libraries
+
+### ESP8266 core for Arduino 2.4.0 beta2 (as 2.4 release has connection bugs)
+* ESP8266WiFi.h
+* WiFiClient.h
+* ESP8266WebServer.h
+* ESP8266mDNS.h
+* ESP8266HTTPUpdateServer.h
+* DNSServer.h
+* FS.h (SPIFFS)
+* Wire.h (I2C library)
+
+https://github.com/esp8266/Arduino
+
+### ArduinoJson 5.13.0
+from library manager
+
+### Adafruit DHT-sensor-library (DHT.h)
+Used unmodified for reading the DHT22 sensor. 
+
+https://github.com/adafruit/DHT-sensor-library
+
+### Adafruit Sensor 1.0.2
+Not really used, but has to be installed when using Adafruit DHT-sensor-library (even if I dont use the DHT_U.h version included in this lib, but gives compile error if not installed).
+
+https://github.com/adafruit/Adafruit_Sensor
+
+### r-downing PersWiFiManager 3.0.1
+AP with captive portal for initial (WiFi-) configuration. 
+Used with modification - added #define WIFI_HTM_PROGMEM to PersWiFiManager.cpp (turns off SPIFFS usage and stores HTML page to PROGMEM)
+
+https://github.com/r-downing/PersWiFiManager
+
+### knolleary PubSubClient 2.7
+MQTT client for Arduino. Used with the following modified DEFINEs in PubSubClient.h: 
+* MQTT_MAX_PACKET_SIZE: increased to 512, needed for receiving/parsing domoticz/out topic
+
+https://github.com/knolleary/pubsubclient
+
+https://pubsubclient.knolleary.net/
+
+### LiquidCrystal I2C (commit e3701fb, Mar 9 2017)
+
+https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library
+
+### r89m Button + PushButton
+Button handling library with callbacks on press, release, hold, hold-repeat.
+PushButton.h extends Button.h.
+
+https://github.com/r89m/PushButton
+
+https://github.com/r89m/Button
+
+### Bounce2
+used by r89m Button/PushButton.
+
+https://github.com/thomasfredericks/Bounce2
+
+
+
+[Hauptseite](./README_DE.md)

BIN
bin/WiFiThermostat.ino.d1_mini.20191031_v0.3.3.bin


+ 0 - 0
libraries/DHT.zip → libraries/DHT-sensor-library-1.3.0.zip


BIN
libraries/DHT-sensor-library-1.3.7.zip


+ 5 - 5
src/WiFiThermostat/Display.ino

@@ -185,7 +185,7 @@ void updateDisplay() {
 
 
     if (togglingTempHumAIDisplay) {
     if (togglingTempHumAIDisplay) {
 
 
-      if ( ((now - outTempHumLastUpdate) < 300000) && outTempHumLastUpdate != 0 && whichTempToDisplay == 1 && ((now - lastDisplayToggle) > (displayInterval * 1000)) ) {
+      if ( ((now - outTempHumLastUpdate) < maxMeasurementAge) && outTempHumLastUpdate != 0 && whichTempToDisplay == 1 && ((now - lastDisplayToggle) > (displayInterval * 1000)) ) {
         // outside temp has been updated < 5 min ago, last displayed temp was INSIDE and display interval is overdue
         // outside temp has been updated < 5 min ago, last displayed temp was INSIDE and display interval is overdue
         whichTempToDisplay = 2; // 1= I, 2= A
         whichTempToDisplay = 2; // 1= I, 2= A
         lastDisplayToggle = now;
         lastDisplayToggle = now;
@@ -198,7 +198,7 @@ void updateDisplay() {
       lastDisplayUpdate = now;
       lastDisplayUpdate = now;
 
 
       if (whichTempToDisplay == 2) { //2 = outside temp/hum received via MQTT
       if (whichTempToDisplay == 2) { //2 = outside temp/hum received via MQTT
-        if ( outTempHumLastUpdate != 0 && (now - outTempHumLastUpdate) < 120000 ) {
+        if ( outTempHumLastUpdate != 0 && (now - outTempHumLastUpdate) < maxMeasurementAge ) {
           showTemp = true;
           showTemp = true;
           dtostrf(outTemp, 5, 1, ch_temp);
           dtostrf(outTemp, 5, 1, ch_temp);
           sprintf(ch_hum, "%2i", outHum);
           sprintf(ch_hum, "%2i", outHum);
@@ -206,7 +206,7 @@ void updateDisplay() {
         }
         }
       }
       }
       else {
       else {
-        if ( lastTempUpdate != 0 && (now - lastTempUpdate) < 120000 ) {
+        if ( lastTempUpdate != 0 && (now - lastTempUpdate) < maxMeasurementAge ) {
           showTemp = true;
           showTemp = true;
           dtostrf(currTemp, 5, 1, ch_temp);
           dtostrf(currTemp, 5, 1, ch_temp);
           sprintf(ch_hum, "%2i", currHum);
           sprintf(ch_hum, "%2i", currHum);
@@ -255,7 +255,7 @@ void updateDisplay() {
       lcd.setCursor(0, 0);
       lcd.setCursor(0, 0);
       lcd.print(itemplab);
       lcd.print(itemplab);
 
 
-      if ( lastTempUpdate != 0 && (now - lastTempUpdate) < 120000 ) {
+      if ( lastTempUpdate != 0 && (now - lastTempUpdate) < maxMeasurementAge ) {
         dtostrf(currTemp, 5, 1, ch_temp);
         dtostrf(currTemp, 5, 1, ch_temp);
         lcd.print(ch_temp);
         lcd.print(ch_temp);
       }
       }
@@ -265,7 +265,7 @@ void updateDisplay() {
       lcd.write((uint8_t)3); // °C symbol
       lcd.write((uint8_t)3); // °C symbol
       lcd.print(" ");
       lcd.print(" ");
 
 
-      if ( outTempHumLastUpdate != 0 && (now - outTempHumLastUpdate) < 120000 ) {
+      if ( outTempHumLastUpdate != 0 && (now - outTempHumLastUpdate) < maxMeasurementAge ) {
 
 
         lcd.print(" ");
         lcd.print(" ");
         lcd.print(otemplab);
         lcd.print(otemplab);

+ 2 - 0
src/WiFiThermostat/WiFiThermostat.ino

@@ -200,6 +200,8 @@ char offMessage[15];
 char itemplab[2];
 char itemplab[2];
 char otemplab[2];
 char otemplab[2];
 
 
+int maxMeasurementAge = 300000;
+
 //set values
 //set values
 float setTemp = DEFAULT_SETTEMP;
 float setTemp = DEFAULT_SETTEMP;
 float currSetTemp = DEFAULT_SETTEMP;
 float currSetTemp = DEFAULT_SETTEMP;

+ 0 - 0
src/WiFiThermostat/misc.ino → src/WiFiThermostat/scheduler.ino


+ 42 - 13
src/WiFiThermostat/thermostat.ino

@@ -1,11 +1,39 @@
+float tmpHum, tmpTemp;
+int DHTreadRetries = 2;
+//int DHTreadDelay = 20;
+
+void readDHTsensorTemp() {
+  //delay(DHTreadDelay);
+  tmpTemp = dht.readTemperature();  // Read temperature as Celsius (the default)
+}
+void readDHTsensorHum() {
+  //delay(DHTreadDelay);
+  tmpHum = dht.readHumidity();
+}
+
 void measureTempHum() {
 void measureTempHum() {
-  delay(1);
-  float tmpHum = round(dht.readHumidity()) + humCorrVal;
-  delay(1);
-  float tmpTemp = dht.readTemperature() + tempCorrVal;  // Read temperature as Celsius (the default)
-  delay(1);
   
   
-  int tmpHumInt = tmpHum;
+  for(int i=0; i < DHTreadRetries; i++) {
+    readDHTsensorTemp();
+    if(!isnan(tmpTemp)) {
+      sendStatus("DHT reading Temp OK");
+      i=DHTreadRetries;
+    }
+    //else {
+    //  sendStatus("DHT reading Temp failed - retrying..");
+    //}
+  }
+
+  for(int i=0; i < DHTreadRetries; i++) {
+    readDHTsensorHum();
+    if(!isnan(tmpHum)) {
+      sendStatus("DHT reading Hum OK");
+      i=DHTreadRetries;
+    }
+    //else {
+    //  sendStatus("DHT reading Hum failed - retrying..");
+    //}
+  }
 
 
   // Check if any reads failed
   // Check if any reads failed
   if (isnan(tmpHum) || isnan(tmpTemp)) {
   if (isnan(tmpHum) || isnan(tmpTemp)) {
@@ -13,6 +41,9 @@ void measureTempHum() {
     sendStatus("Error: Failed to read from DHT sensor!");
     sendStatus("Error: Failed to read from DHT sensor!");
   }
   }
   else {
   else {
+    tmpTemp = tmpTemp + tempCorrVal;
+    tmpHum = round(tmpHum) + humCorrVal;
+    int tmpHumInt = tmpHum;
     if (tmpTemp < 50.0 && tmpTemp > -20.0) {
     if (tmpTemp < 50.0 && tmpTemp > -20.0) {
       // measurement is in range
       // measurement is in range
       currTemp_raw = tmpTemp;
       currTemp_raw = tmpTemp;
@@ -26,7 +57,7 @@ void measureTempHum() {
         currHum = (currHum * 9 + tmpHumInt) / 10; // filter
         currHum = (currHum * 9 + tmpHumInt) / 10; // filter
         lastTempUpdate = millis();
         lastTempUpdate = millis();
       }
       }
-      else if ( lastTempUpdate == 0 || (millis() - lastTempUpdate) > 300000 ) {
+      else if ( lastTempUpdate == 0 || (millis() - lastTempUpdate) > maxMeasurementAge ) {
         // this is the first measurement or the last one is older than 5m - then accept this measurement
         // this is the first measurement or the last one is older than 5m - then accept this measurement
         currTemp = tmpTemp + tempCorrVal;
         currTemp = tmpTemp + tempCorrVal;
         currHum = tmpHumInt + humCorrVal;
         currHum = tmpHumInt + humCorrVal;
@@ -41,8 +72,6 @@ void measureTempHum() {
       //      Serial.print(lastTempUpdateDelta / 1000);
       //      Serial.print(lastTempUpdateDelta / 1000);
       //      Serial.println("s ago");
       //      Serial.println("s ago");
       //#endif
       //#endif
-
-
     }
     }
   }
   }
 }
 }
@@ -87,7 +116,7 @@ void thermostat() {
   //char tmp_topic_out[50];
   //char tmp_topic_out[50];
   //sprintf(tmp_topic_out, "%s/%s", mqtt_topic_out, "heating");
   //sprintf(tmp_topic_out, "%s/%s", mqtt_topic_out, "heating");
 
 
-  if ( lastTempUpdate != 0 && (millis() - lastTempUpdate) <= 120000 ) {
+  if ( lastTempUpdate != 0 && (millis() - lastTempUpdate) <= maxMeasurementAge ) {
     // thermostat - only active if measured temperature is < 2 min old
     // thermostat - only active if measured temperature is < 2 min old
 
 
 #ifdef DEBUG_VERBOSE
 #ifdef DEBUG_VERBOSE
@@ -136,10 +165,10 @@ void thermostat() {
       turnHeatingOn = false;
       turnHeatingOn = false;
       heatingLastOffMillis = millis();
       heatingLastOffMillis = millis();
     }
     }
-
+    
     if ( lastTempUpdate != 0 ) sendStatus("switch heating OFF, temp reading not yet available");
     if ( lastTempUpdate != 0 ) sendStatus("switch heating OFF, temp reading not yet available");
-    else if ( (millis() - lastTempUpdate) > 120000 ) sendStatus("switch heating OFF, last temp reading too old");
-
+    else if ( (millis() - lastTempUpdate) > maxMeasurementAge ) sendStatus("switch heating OFF, last temp reading too old");
+    
     //mqttclient.publish(tmp_topic_out, "off");
     //mqttclient.publish(tmp_topic_out, "off");
     publishCurrentThermostatValues();
     publishCurrentThermostatValues();
     sendToDomoticz_Heating();
     sendToDomoticz_Heating();