Nach IDE Update Arduino Uno Datenbereich überschreitet den verfügbaren Platz auf der Platine

Nach dem IDE Update kann ich meinen sketch nicht mehr auf den UNO übertragen.
Vor dem Update lag der Speicher bei ca. 30% und der dynamische ca. 60%.
nach dem Update bei 90% und 180%.
Wenn ich einen WIFI R4 nutze liegt der Speicher bei 34% und 32%.

Ich habe auch schon IDE 1.8.19 installiert. IDE 2.3.3 neu aufgesetzt. Das Problem ist aber geblieben.
Was ist hier los?

Zeig mal den Sketch.

// -- Zeit
  #include <Wire.h>                               // Lib zur I2C-Kommunikation
  #include <RTClib.h>                             // Lib für die Real Time Clock
  #include <EEPROM.h>                             // Lib für das interne EEPROM
  char daysOfTheWeek[7][12] = { "Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag" };
  RTC_DS3231 RTC;
  int Stunden, Minuten, Tag, Monat, Jahr;         // Zeitvariablen für Taster
  int Ein_Stunde, Ein_Minute;                     // Einschaltzeit
  int Aus_Stunde, Aus_Minute;                     // Ausschaltzeit
  int Ein_Tag;                                    // Einschalttag für Legionellen
  int Uhr_d, Uhr_h, Uhr_m, Uhr_s;                 // Variablen für Uhrzeit
  int Datum_Tag, Datum_Monat, Datum_Jahr;         // Variablen für Datum
  int Datum_Tag_set, Datum_Monat_set, Datum_Jahr_set;               // Variable Zeiteingabe Nextion
  int Uhr_h_set, Uhr_m_set, Uhr_s_set;
  int Sommer;                                     // Sommerzeit true/false

// -- Nextion
  String dfd = "";
  String endChar = String(char(0xff)) + String(char(0xff)) + String(char(0xff));
  byte nexend[3] = {255, 255, 255};
  #include <SoftwareSerial.h>
  SoftwareSerial nextion(3, 2); // RX, TX

// -- Temperatursensoren
  #include <OneWire.h>                            // Lib für OneWire
  #include <DallasTemperature.h>                  // Lib für DS18B20
  #define ONE_WIRE_BUS 4                          // Sensor an PIN (4)
  OneWire oneWire(ONE_WIRE_BUS);                  
  DallasTemperature sensors(&oneWire);
  DeviceAddress Thermometer;
  int deviceCount = 0;

// -- Ausgänge
  #define nextion_power   12          // Power ein für Nexton an PIN 12             Relais K1
  #define OUT_A           6           // Pumpe Speicherladung an PIN 6              Relais K7 auf K11
  #define OUT_B           9           // Zuheizung elektro an PIN 9                 Relais K4 auf K14
  #define OUT_C           10          // Zuheizung Gas an PIN 10                    Relais K3 auf K15
  #define OUT_D           10          // 3 Wegeventil an PIN 10                     Relais K3 auf K15
  #define OUT_E           8           // Pumpe Speicherumladung an PIN 8            Relais K5 auf K13
  const byte Z_P =        7;          // Pumpe Zirkulation Brauchwasser an PIN 7    Relais K6 auf K12
  #define T_P             5           // Pumpe Brauchwasserladung an PIN 5          Relais K8 auf K10
  #define rest            13          // reset Nextion Button an PIN 13

// - int
  // -- int button
    int pagestate =                   0;
    int btn_state_T_P =               0;
    int btn_state_Z_P =               0;
    int btn_state_legio =             0;
    int btn_state_hand_PLP =          0;
    int btn_state_hand_BWLP =         0;
    int btn_state_hand_ZPBW =         0;
    int btn_state_hand_ZPSU =         0;
    int btn_state_hand_WV =           0;
    int last_status_zuheizung = EEPROM.read(17);
    int last_status_legionellen = EEPROM.read(30);
    int btn_state_zuheizung_gas =     last_status_zuheizung;
    int btn_state_zuheizung_aus =     last_status_zuheizung;
    int btn_state_zuheizung_elektro = last_status_zuheizung;
    int zeit_stellen;

  // -- millis
    const unsigned long TIME_INTERVAL = 10000;   // Zeit Zeitanzeige
    unsigned long previousMillis;
    const unsigned long TIME_INTERVAL2 = 8000; // Zeit Sensoren auslesen
    unsigned long previousMillis2;

  // -- int Temperatursensoren
    int aussentemp;                         // Aussentemperatur
    int H0_S;                               // Kesseltemperatur
    int HDW_o;                              // Brauchwasserspeichertemperatur oben
    int HDW_u;                              // Brauchwasserspeichertemperatur unten
    int P1o_S;                              // Pufferspeicher 1 Temperatur oben
    int P1m_S;                              // Pufferspeicher 1 Temperatur mitte
    int P1u_S;                              // Pufferspeicher 1 Temperatur unten
    int P2o_S;                              // Pufferspeicher 2 Temperatur oben
    int P2m_S;                              // Pufferspeicher 2 Temperatur mitte
    int P2u_S;                              // Pufferspeicher 2 Temperatur unten
    int P3o_S;                              // Pufferspeicher 3 Temperatur oben
    int P3m_S;                              // Pufferspeicher 3 Temperatur mitte
    int P3u_S;                              // Pufferspeicher 3 Temperatur unten

  // -- int Systemvariablen
    int Puffermindesttemp;
    int Pufferumladetemp;
    int Ladepumpestarttemp;
    int Ladepumpestoptemp;
    int hyst_Ladepumpe;
    int Kesselabkuehltemperatur;
    int Kesseltempkorrektur;
    int Puffertempkorrektur;
    int WBW_Temp_max;
    int WBW_Temp_min;
    int Legionellentemp_min;
    int hyst_WBW;
    
  

void Zirkulationspumpe() // -- Zeit Zirkulationspumpe
    {
    static uint32_t previousMillis3 = 0;  
    if (btn_state_Z_P == 0) {
    btn_state_Z_P == 0;
    previousMillis3 = millis();         
    }
    if (millis() - previousMillis3 > (300 * 1000UL) && btn_state_Z_P == 1){ // (300 * 1000UL)
    btn_state_Z_P = 0;
    btn_state_hand_ZPBW = 0;
    Serial.print("btn_state_Z_P ");
    Serial.print(btn_state_Z_P);
    Serial.println(" Zirkulationspumpe Brauchwasser aus");
    }}
void NextionRefresh() // -- reset Nextion
    {
    if (!digitalRead(rest)) {
    nextion.print("rest");
    nextion.write(nexend, 3);
    Serial.println("Nextion reset");
    delay(1000);
    pagestate = 0;
    }
    }



void setup() {
  Serial.begin(19200); 
  nextion.begin(19200);
  Wire.begin();

  // -- RTC
    RTC.begin();                          // Uhr starten
    //RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));  // Zeit vom PC einlesen, Wenn Uhrzeit neu gesetzt werden soll, sonst auskommentieren !!!
    //RTC.adjust(DateTime(2023, 10, 8, 21, 21, 30));
    if (! RTC.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();}
  // -- EEPROM
     // EEPROM.write(5, 40), EEPROM.write(6, 55), EEPROM.write(7, 65), EEPROM.write(8, 63), EEPROM.write(9, 2), EEPROM.write(10, 90), EEPROM.write(11, 1),EEPROM.write(12, 0), EEPROM.write(13, 60), EEPROM.write(14, 40), EEPROM.write(15, 70), EEPROM.write(16, 5);

      Ein_Tag =                   EEPROM.read(0);      // Einschalttag auslesen
      Ein_Stunde =                EEPROM.read(1);      // Einschaltzeit Stunde einlesen
      Ein_Minute =                EEPROM.read(2);      // Einschaltzeit Minute einlesen
      Puffermindesttemp =         EEPROM.read(5);      // Pufferspeichermindesttemperatur 40°C
      Pufferumladetemp =          EEPROM.read(6);      // Pufferspeicherumladungstemperatur 55°C
      Ladepumpestarttemp =        EEPROM.read(7);      // Einschalttemperatur Speicherladepumpe 65 °C
      Ladepumpestoptemp =         EEPROM.read(8);      // Ausschalttemperatur Speicherladepumpe 63°C
      hyst_Ladepumpe =            EEPROM.read(9);      // Hysterese Pufferladepumpe 2 °
      Kesselabkuehltemperatur =   EEPROM.read(10);     // Kesselabkuehltemperatur 90°C
      Kesseltempkorrektur =       EEPROM.read(11);     // Temperaturkorrektur Sensor Kessel 1°C
      Puffertempkorrektur =       EEPROM.read(12);     // Temperaturkorrektur Sensoren Pufferspeicher 0°C
      WBW_Temp_max =              EEPROM.read(13);     // Brauchwassermaximaltemperatur 60°C
      WBW_Temp_min =              EEPROM.read(14);     // Brauchwassermidensttemperatur 40°C
      Legionellentemp_min =       EEPROM.read(15);     // Legionellentemperatur 70°C
      hyst_WBW =                  EEPROM.read(16);     // Hysterese Brauchwasser 5°C
      last_status_zuheizung =     EEPROM.read(17);     // status Zuheizung - 1 elektro aktiviert - 2 Gas aktiviert - 3 keine aktiviert
      last_status_legionellen =   EEPROM.read(30);     // status letzte Legionellenbehandlung - 1 wird ausgeführt - 2 abgeschlossen - 3 abgebrochen - 4 nicht bekannt
      
  // -- Temperatursensoren im BUS lokalisieren
      sensors.begin();                        // Sensoren starten
      Serial.println("Suche Sensoren...");
      Serial.print("gefunden ");
      deviceCount = sensors.getDeviceCount();
      Serial.print(deviceCount, DEC);
      Serial.println(" Sensoren.");
      Serial.println("");
      Serial.println("schreibe Adressen...");
      for (int i = 0;  i < deviceCount;  i++)
      {
      Serial.print("Sensor ");
      Serial.print(i+1);
      Serial.print(" : ");
      sensors.getAddress(Thermometer, i);
      printAddress(Thermometer);}  
 
 
  // -- pinMode
    pinMode(nextion_power, OUTPUT);
    digitalWrite(nextion_power, HIGH);
    pinMode(OUT_A, OUTPUT);
    digitalWrite(OUT_A, LOW);
    pinMode(OUT_B, OUTPUT);
    digitalWrite(OUT_B, HIGH);
    pinMode(OUT_C, OUTPUT);
    digitalWrite(OUT_C, HIGH);
    pinMode(OUT_D, OUTPUT);
    digitalWrite(OUT_D, HIGH);
    pinMode(OUT_E, OUTPUT);
    digitalWrite(OUT_E, HIGH);
    pinMode(T_P, OUTPUT);
    digitalWrite(T_P, HIGH);
    pinMode(Z_P, OUTPUT);
    digitalWrite(Z_P, HIGH);
    pinMode(rest, INPUT_PULLUP);


  // -- Start Nextion und LOOP
    tempssensoren();
    delay(5000);
    digitalWrite(OUT_A, HIGH);
    delay(2000);
    Serial.println("Start");
    digitalWrite(nextion_power, LOW); // Nextion einschalten
    delay(2000);
    }

void loop() {

  Zirkulationspumpe();
  tempssensoren();
  NextionRefresh();
  Uhrzeit();

    DateTime now = RTC.now();
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
  // -- EEPROM einlesen
  
      Ein_Tag =                   EEPROM.read(0);      // Einschalttag auslesen
      Ein_Stunde =                EEPROM.read(1);      // Einschaltzeit Stunde einlesen
      Ein_Minute =                EEPROM.read(2);      // Einschaltzeit Minute einlesen
      Puffermindesttemp =         EEPROM.read(5);      // Pufferspeichermindesttemperatur 40°C
      Pufferumladetemp =          EEPROM.read(6);      // Pufferspeicherumladungstemperatur 55°C
      Ladepumpestarttemp =        EEPROM.read(7);      // Einschalttemperatur Speicherladepumpe 68 °C
      Ladepumpestoptemp =         EEPROM.read(8);      // Ausschalttemperatur Speicherladepumpe 65°C
      hyst_Ladepumpe =            EEPROM.read(9);      // Hysterese Pufferladepumpe 2 °
      Kesselabkuehltemperatur =   EEPROM.read(10);     // Kesselabkuehltemperatur 90°C
      Kesseltempkorrektur =       EEPROM.read(11);     // Temperaturkorrektur Sensor Kessel 1°C
      Puffertempkorrektur =       EEPROM.read(12);     // Temperaturkorrektur Sensoren Pufferspeicher 0°C
      WBW_Temp_max =              EEPROM.read(13);     // Brauchwassermaximaltemperatur 60°C
      WBW_Temp_min =              EEPROM.read(14);     // Brauchwassermidensttemperatur 40°C
      Legionellentemp_min =       EEPROM.read(15);     // Legionellentemperatur 70°C
      hyst_WBW =                  EEPROM.read(16);     // Hysterese Brauchwasser 5°C
      last_status_zuheizung =     EEPROM.read(17);     // status Zuheizung - 1 elektro aktiviert - 2 Gas aktiviert - 3 keine aktiviert
      last_status_legionellen =   EEPROM.read(30);     // status letzte Legionellenbehandlung - 1 wird ausgeführt - 2 abgeschlossen - 3 abgebrochen - 4 konnte nicht gestartet werden
      Serial.println("EEPROM eingelesen");


  // -- Nextion Input
      if (nextion.available() > 0){
      dfd += char (nextion.read());}
      if (dfd.endsWith(endChar)){
      Serial.print(dfd);
      Serial.println(" Fehler");
      dfd = "";
      }

  // -- Nextion pagestate
      if (dfd == "page 0"){
        pagestate = 0;
        previousMillis2 = millis();
        nextion.print("page 0" + endChar);
        Serial.print("pagestate ");
        Serial.println(pagestate);
        dfd = "";}
      if (dfd == "page 1"){
        pagestate = 1;
        previousMillis2 = millis();
        nextion.print("page 1" + endChar);
        Serial.print("pagestate ");
        Serial.println(pagestate);
        dfd = "";}
      if (dfd == "page 2"){
        pagestate = 2;
        previousMillis2 = millis();
        nextion.print("page 2" + endChar);
        Serial.print("pagestate ");
        Serial.println(pagestate);
        dfd = "";
          DateTime now = RTC.now();
          nextion.print("n0.val=");
          nextion.print(now.day());
          nextion.write(nexend, 3);
            nextion.print("n1.val=");
            nextion.print(now.month());
            nextion.write(nexend, 3);
              nextion.print("n2.val=");
              nextion.print(now.year());
              nextion.write(nexend, 3);
                nextion.print("n3.val=");
                nextion.print(now.hour());
                nextion.write(nexend, 3);
                  nextion.print("n4.val=");
                  nextion.print(now.minute());
                  nextion.write(nexend, 3);
                    nextion.print("n5.val=");
                    nextion.print(now.second());
                    nextion.write(nexend, 3);
        }
      if (dfd == "page 3"){
        pagestate = 3;
        previousMillis2 = millis();
        nextion.print("page 3" + endChar);
        Serial.print("pagestate ");
        Serial.println(pagestate);
        dfd = "";} 
      if (dfd == "page 4"){
        pagestate = 4;
        previousMillis2 = millis();
        nextion.print("page 4" + endChar);
        Serial.print("pagestate ");
        Serial.println(pagestate);
        dfd = "";}
      if (dfd == "page 5"){
        pagestate = 5;
        previousMillis2 = millis();
        nextion.print("page 5" + endChar);
        Serial.print("pagestate ");
        Serial.println(pagestate);
        dfd = "";}
      if (dfd == "page 6"){
        pagestate = 6;
        previousMillis2 = millis();
        nextion.print("page 6" + endChar);
        Serial.print("pagestate ");
        Serial.println(pagestate);
        dfd = "";}
      if (dfd == "page 7"){
        pagestate = 7;
        previousMillis2 = millis();
        nextion.print("page 7" + endChar);
        dfd = "";
        Serial.print("pagestate ");
        Serial.println(pagestate);
        nextion.print("n0.val=");
        nextion.print(EEPROM.read(5));
        nextion.write(nexend, 3);
          nextion.print("n1.val=");
          nextion.print(EEPROM.read(6));
          nextion.write(nexend, 3);
            nextion.print("n2.val=");
            nextion.print(EEPROM.read(7));
            nextion.write(nexend, 3);
              nextion.print("n3.val=");
              nextion.print(EEPROM.read(8));
              nextion.write(nexend, 3);
                nextion.print("n4.val=");
                nextion.print(EEPROM.read(9));
                nextion.write(nexend, 3);
                  nextion.print("n5.val=");
                  nextion.print(EEPROM.read(10));
                  nextion.write(nexend, 3);
                    nextion.print("n6.val=");
                    nextion.print(EEPROM.read(11));
                    nextion.write(nexend, 3);
                      nextion.print("n7.val=");
                      nextion.print(EEPROM.read(12));
                      nextion.write(nexend, 3);
                        nextion.print("n8.val=");
                        nextion.print(EEPROM.read(13));
                        nextion.write(nexend, 3);
                          nextion.print("n9.val=");
                          nextion.print(EEPROM.read(14));
                          nextion.write(nexend, 3);
                            nextion.print("n10.val=");
                            nextion.print(EEPROM.read(15));
                            nextion.write(nexend, 3);
                              nextion.print("n11.val=");
                              nextion.print(EEPROM.read(16));
                              nextion.write(nexend, 3);
        }
      if (dfd == "page 8"){
        pagestate = 8;
        previousMillis2 = millis();
        nextion.print("page 8" + endChar);
        Serial.print("pagestate ");
        Serial.println(pagestate);
        dfd = "";
          nextion.print("select0.val=");
          nextion.print(EEPROM.read(0));
          nextion.write(nexend, 3);
            nextion.print("select1.val=");
            nextion.print(EEPROM.read(1));
            nextion.write(nexend, 3);
              nextion.print("select2.val=");
              nextion.print(EEPROM.read(2));
              nextion.write(nexend, 3);
        }
      if (dfd == "page 9"){
        pagestate = 9;
        previousMillis2 = millis();
        nextion.print("page 9" + endChar);
        Serial.print("pagestate ");
        Serial.println(pagestate);
        dfd = "";}
  // -- Nextion page update
    // -- page 0 Hauptseite
        if ((dfd == "") && (pagestate == 0))        {
        //Serial.println("Seite 0 wird aktualisiert");
          if ((P1m_S < Puffermindesttemp) && (millis()%(2000+2000)<2000)){
            nextion.print("null.zerot18.txt=\"");
            nextion.print("BITTE ANLEGEN");
            nextion.write('"');
            nextion.write(nexend, 3);
            }
              else if(P1m_S < Puffermindesttemp){
              nextion.print("null.zerot18.txt=\"");          
              nextion.print(" ");
              nextion.write('"');
              nextion.write(nexend, 3);  
              }

            if ((digitalRead(OUT_A) == 0) && (millis()%(1000+1000)<1000)){ // wenn Pufferspeicherladepumpe ein
              nextion.print("null.zerot4.pco=2016" + endChar);}
              else if (digitalRead(OUT_A) == 0){
              nextion.print("null.zerot4.pco=0" + endChar);
              }
            if (digitalRead(OUT_A) == 1){ // wenn Pufferspeicherladepumpe aus
              nextion.print("null.zerot4.pco=63488" + endChar);
              }

          if ((digitalRead(OUT_B) == 0) || (digitalRead(OUT_C) == 0)){
            //nextion.print("null.zerot19.pco=1024" + endChar);
            nextion.print("null.zerot19.txt=\"");
            nextion.print("Zuheizung aktiv");
            nextion.write('"');
            nextion.write(nexend, 3);
            }

          if (((digitalRead(OUT_B) == 1) && (digitalRead(OUT_C) == 1)) && ((last_status_zuheizung == 1) || (last_status_zuheizung == 2))){
            nextion.print("null.zerot19.pco=64512" + endChar);
            nextion.print("null.zerot19.txt=\"");
            nextion.print("Zuheizung bereit");
            nextion.write('"');
            nextion.write(nexend, 3);
            }
          if ((last_status_zuheizung == 0) && (millis()%(2000+2000)<2000)){
            nextion.print("null.zerot19.pco=63488" + endChar);
            nextion.print("null.zerot19.txt=\"");          
            nextion.print("ACHTUNG KEIN FROSTSCHUTZ");
            nextion.write('"');
            nextion.write(nexend, 3);
            }
              else if(last_status_zuheizung == 0){
              nextion.print("null.zerot19.txt=\"");          
              nextion.print(" ");
              nextion.write('"');
              nextion.write(nexend, 3);  
              }
          if (last_status_zuheizung == 1){
            nextion.print("null.zerot17.txt=\"");
            nextion.print("Zuheizung elektro ausgewaehlt");
            nextion.write('"');
            nextion.write(nexend, 3);
            }

          if (last_status_zuheizung == 2){
            nextion.print("null.zerot17.txt=\"");
            nextion.print("Zuheizung Gas ausgewaehlt");
            nextion.write('"');
            nextion.write(nexend, 3);
            }

          if (last_status_zuheizung == 0){
            nextion.print("null.zerot17.txt=\"");
            nextion.print("keine Zuheizung ausgewaehlt");
            nextion.write('"');
            nextion.write(nexend, 3);
            }    

          if (digitalRead(OUT_C) == 0){
            nextion.print("null.zerot38.pco=2016" + endChar);}
            if (digitalRead(OUT_C) == 1){
            nextion.print("null.zerot38.pco=63488" + endChar);}

          if (digitalRead(OUT_D) == 0){
            nextion.print("null.zerot7.pco=2016" + endChar);}
            if (digitalRead(OUT_D) == 1){
            nextion.print("null.zerot7.pco=63488" + endChar);}

          if ((digitalRead(Z_P) == 0) && (millis()%(1000+1000)<1000)){
            nextion.print("null.zerot6.pco=2016" + endChar);}
              else if (digitalRead(Z_P) == 0){
              nextion.print("null.zerot6.pco=0" + endChar);
              }
            if (digitalRead(Z_P) == 1){
              nextion.print("null.zerot6.pco=63488" + endChar);}
              
          if ((digitalRead(T_P) == 0) && (millis()%(1000+1000)<1000)){
            nextion.print("null.zerot5.pco=2016" + endChar);}
            else if (digitalRead(T_P) == 0){
            nextion.print("null.zerot5.pco=0" + endChar);
            }
            if (digitalRead(T_P) == 1){
              nextion.print("null.zerot5.pco=63488" + endChar);}

          if ((digitalRead(OUT_E) == 0) && (millis()%(1000+1000)<1000)){
            nextion.print("null.zerot14.pco=2016" + endChar);}
              else if (digitalRead(OUT_E) == 0){
              nextion.print("null.zerot14.pco=0" + endChar);
              }
            if (digitalRead(OUT_E) == 1){
            nextion.print("null.zerot14.pco=63488" + endChar);}

      // -- Temperaturanzeige
        if ((aussentemp) < (-100)){
        nextion.print("null.zerot11.txt=\"");
        nextion.print("--");
        nextion.write('"');
        nextion.write(nexend, 3);}
        else {
        nextion.print("null.zerot11.txt=\"");
        nextion.print(aussentemp);
        nextion.write('"');
        nextion.write(nexend, 3);}
        if ((H0_S) < (-100)){
        nextion.print("null.H0.txt=\"");
        nextion.print("--");
        nextion.write('"');
        nextion.write(nexend, 3);}
        else {
        nextion.print("null.H0.txt=\"");
        nextion.print(H0_S + Kesseltempkorrektur);
        nextion.write('"');
        nextion.write(nexend, 3);}
        if ((HDW_o) < (-100)){
        nextion.print("null.HDWo.txt=\"");
        nextion.print("--");
        nextion.write('"');
        nextion.write(nexend, 3);}
        else {
        nextion.print("null.HDWo.txt=\"");
        nextion.print(HDW_o);
        nextion.write('"');
        nextion.write(nexend, 3);}
        if ((HDW_u) < (-100)){
        nextion.print("null.HDWu.txt=\"");
        nextion.print("--");
        nextion.write('"');
        nextion.write(nexend, 3);}
        else {
        nextion.print("null.HDWu.txt=\"");
        nextion.print(HDW_u);
        nextion.write('"');
        nextion.write(nexend, 3);}
        if ((P1o_S) < (-100)){
        nextion.print("null.P1o.txt=\"");
        nextion.print("--");
        nextion.write('"');
        nextion.write(nexend, 3);}
        else {
        nextion.print("null.P1o.txt=\"");
        nextion.print(P1o_S);
        nextion.write('"');
        nextion.write(nexend, 3);}
        if ((P1m_S) < (-100)){
        nextion.print("null.P1m.txt=\"");
        nextion.print("--");
        nextion.write('"');
        nextion.write(nexend, 3);}
        else {
        nextion.print("null.P1m.txt=\"");
        nextion.print(P1m_S);
        nextion.write('"');
        nextion.write(nexend, 3);}
        if ((P1u_S) < (-100)){
        nextion.print("null.P1u.txt=\"");
        nextion.print("--");
        nextion.write('"');
        nextion.write(nexend, 3);}
        else {
        nextion.print("null.P1u.txt=\"");
        nextion.print(P1u_S);
        nextion.write('"');
        nextion.write(nexend, 3);}
        if ((P2o_S) < (-100)){
        nextion.print("null.P2o.txt=\"");
        nextion.print("--");
        nextion.write('"');
        nextion.write(nexend, 3);}
        else {
        nextion.print("null.P2o.txt=\"");
        nextion.print(P2o_S);
        nextion.write('"');
        nextion.write(nexend, 3);}
        if ((P2m_S) < (-100)){
        nextion.print("null.P2m.txt=\"");
        nextion.print("--");
        nextion.write('"');
        nextion.write(nexend, 3);}
        else {
        nextion.print("null.P2m.txt=\"");
        nextion.print(P2m_S);
        nextion.write('"');
        nextion.write(nexend, 3);}
        if ((P2u_S) < (-100)){
        nextion.print("null.P2u.txt=\"");
        nextion.print("--");
        nextion.write('"');
        nextion.write(nexend, 3);}
        else {
        nextion.print("null.P2u.txt=\"");
        nextion.print(P2u_S);
        nextion.write('"');
        nextion.write(nexend, 3);}
        if ((P3o_S) < (-100)){
        nextion.print("null.P3o.txt=\"");
        nextion.print("--");
        nextion.write('"');
        nextion.write(nexend, 3);}
        else {
        nextion.print("null.P3o.txt=\"");
        nextion.print(P3o_S);
        nextion.write('"');
        nextion.write(nexend, 3);}
        if ((P3m_S) < (-100)){
        nextion.print("null.P3m.txt=\"");
        nextion.print("--");
        nextion.write('"');
        nextion.write(nexend, 3);}
        else {
        nextion.print("null.P3m.txt=\"");
        nextion.print(P3m_S);
        nextion.write('"');
        nextion.write(nexend, 3);}
        if ((P3u_S) < (-100)){
        nextion.print("null.P3u.txt=\"");
        nextion.print("--");
        nextion.write('"');
        nextion.write(nexend, 3);}
        else {
        nextion.print("null.P3u.txt=\"");
        nextion.print(P3u_S);
        nextion.write('"');
        nextion.write(nexend, 3);}      

      if (millis() - previousMillis >= TIME_INTERVAL){
      DateTime now = RTC.now();

      nextion.print("null.zerot9.txt=\"");
      nextion.print(daysOfTheWeek[now.dayOfTheWeek()]);
      nextion.print(" ");
      if (now.day() < 10){
      nextion.print("0");}
      nextion.print(now.day(), DEC);
      nextion.print(".");
      if (now.month() < 10) {
      nextion.print("0");}
      nextion.print(now.month(), DEC);
      nextion.print(".");
      nextion.print(now.year(), DEC);
      nextion.write('"');
      nextion.write(nexend, 3);
      Uhr_h = int(now.hour());             // Stunden ermitteln
      if (Sommer == false) {                // bei Winterzeit
      Uhr_h = int(now.hour() - 1);}       // 1 Stunde addieren
      Uhr_m = int(now.minute());  
      nextion.print("null.zerozeit.txt=\"");
      if (Uhr_h < 10) {
      nextion.print("0");}
      nextion.print(Uhr_h);                    // Stunden anzeigen
      nextion.print(":");
      if (Uhr_m < 10) {
      nextion.print("0");}
      nextion.print(Uhr_m);
      nextion.write('"');
      nextion.write(nexend, 3);
     previousMillis = millis();
  
      Sommer = Sommerzeit();
        }
      
        }
    // -- page 2 Uhrzeit
        if (pagestate == 2){
        //Serial.println("Seite 2 wird aktualisiert");
        
        if (dfd.substring((dfd.length() - 1), dfd.length()) == "?"){
        String command = dfd.substring(5, 9);
        String value = dfd.substring(9, dfd.length() - 1);
        Serial.println(command + " : " + value);
        dfd = "";

        if (command == "DATT") {
        Datum_Tag_set = value.toInt();
        //Serial.print("Tag: ");
        Serial.print(Datum_Tag_set);
        Serial.print(".");
        dfd ="";
        }
        if (command == "DATM") {
        Datum_Monat_set = value.toInt();
        //Serial.print("Monat: ");
        Serial.print(Datum_Monat_set);
        Serial.print(".");
        dfd ="";
        }
        if (command == "DATJ") {
        Datum_Jahr_set = value.toInt();
        //Serial.print("Jahr: ");
        Serial.print(Datum_Jahr_set);
        Serial.print(" - ");
        dfd ="";
        }
        if (command == "ZEIS") {
        Uhr_h_set = value.toInt();
        //Serial.print("Stunde: ");
        Serial.print(Uhr_h_set);
        Serial.print(":");
        dfd ="";
        }
        if (command == "ZEIM") {
        Uhr_m_set = value.toInt();
        //Serial.print("Stunde: ");
        Serial.print(Uhr_m_set);
        Serial.print(":");
        dfd ="";
        }
        if (command == "ZEIX") {
        Uhr_s_set = value.toInt();
        //Serial.print("Sekunde: ");
        Serial.println(Uhr_s_set);
        dfd ="";
        }
        RTC.adjust(DateTime(Datum_Jahr_set, Datum_Monat_set, Datum_Tag_set, Uhr_h_set, Uhr_m_set, Uhr_s_set));
        Serial.println("Uhrzeit eingestellt");       
        }        
        }
        
    // -- page 3 Zuheizung
        if (pagestate == 3){
        //Serial.println("Seite 3 wird aktualisiert");
        if (last_status_zuheizung == 1){
        nextion.print("zuheizung.t3.txt=\"");
        nextion.print("Zuheizung elektro ausgewaehlt");
        nextion.write('"');
        nextion.write(nexend, 3);
        }
        else {
        nextion.print("zuheizung.t3.txt=\"");
        nextion.print("Zuheizung elektro aktivieren");
        nextion.write('"');
        nextion.write(nexend, 3);
        }
        if (last_status_zuheizung == 2){
        nextion.print("zuheizung.t1.txt=\"");
        nextion.print("Zuheizung Gasherme ausgewaehlt");
        nextion.write('"');
        nextion.write(nexend, 3);
        }
        else {
        nextion.print("zuheizung.t1.txt=\"");
        nextion.print("Zuheizung Gastherme aktivieren");
        nextion.write('"');
        nextion.write(nexend, 3);
        }
      }  
    // -- page 4 Handbetrieb
        if (pagestate == 4){
        //Serial.println("Seite 4 wird aktualisiert");
        if (btn_state_hand_PLP == 1){
          nextion.print("hand.t0.pco=2016" + endChar);}
        else {nextion.print("hand.t0.pco=63488" + endChar);}
        if (btn_state_hand_BWLP == 1){
          nextion.print("hand.t1.pco=2016" + endChar);}
        else {nextion.print("hand.t1.pco=63488" + endChar);}
        if ((btn_state_hand_ZPBW == 1) || (btn_state_Z_P == 1)){
          nextion.print("hand.t2.pco=2016" + endChar);}
        else {nextion.print("hand.t2.pco=63488" + endChar);}
        if (btn_state_hand_ZPSU == 1){
          nextion.print("hand.t3.pco=2016" + endChar);}
        else {nextion.print("hand.t3.pco=63488" + endChar);}
        if (btn_state_hand_WV == 1){
          nextion.print("hand.t4.pco=2016" + endChar);}
        else {nextion.print("hand.t4.pco=63488" + endChar);}
      }
    // -- page 5 Brauchwasser
        if (pagestate == 5){
          //Serial.println("Seite 5 wird aktualisiert");
        if (btn_state_T_P == 1){ // wenn T_P aktiviert
          nextion.print("warmwasser.t0.txt=\"");
          nextion.print("Brauchwasserladung aktiviert");
          nextion.write('"');
          nextion.write(nexend, 3);}
            else {
            nextion.print("warmwasser.t0.txt=\"");
            nextion.print("1 x manuelle Brauchwasserladung");
            nextion.write('"');
            nextion.write(nexend, 3);
            }
        if (btn_state_Z_P == 1){
          nextion.print("warmwasser.t1.txt=\"");
          nextion.print("Zirkulation aktiviert");
          nextion.write('"');
          nextion.write(nexend, 3);}
            else {
            nextion.print("warmwasser.t1.txt=\"");
            nextion.print("Zirkulationspumpe  5 min. aktivieren");
            nextion.write('"');
            nextion.write(nexend, 3);
            }
        if (last_status_legionellen == 1){
            nextion.print("warmwasser.t3.txt=\"");
            nextion.print("Legionellenbehandlung wurde aktiviert");
            nextion.write('"');
            nextion.write(nexend, 3);}
        if (last_status_legionellen == 2){
             nextion.print("warmwasser.t3.txt=\"");
            nextion.print("Legionellenbehandlung abgeschlossen");
            nextion.write('"');
            nextion.write(nexend, 3);} 
        if (last_status_legionellen == 3){
            nextion.print("warmwasser.t3.txt=\"");
            nextion.print("konnte nicht gestartet werden Puffertemp zu gering");
            nextion.write('"');
            nextion.write(nexend, 3);}
        if (last_status_legionellen == 4){
            nextion.print("warmwasser.t3.txt=\"");
            nextion.print("Legionellenbehandlung abgebrochen");
            nextion.write('"');
            nextion.write(nexend, 3);}    
      }
    // -- page 6 temps
        if (pagestate == 6){
          //Serial.println("Seite 6 wird aktualisiert");
          nextion.print("temps.H1_S.txt=\"");
          nextion.print(aussentemp);
          nextion.write('"');
          nextion.write(nexend, 3);
          nextion.print("temps.H0_S.txt=\"");
          nextion.print(H0_S);
          nextion.write('"');
          nextion.write(nexend, 3);
          nextion.print("temps.HDW_o.txt=\"");
          nextion.print(HDW_o);
          nextion.write('"');
          nextion.write(nexend, 3);
          nextion.print("temps.HDW_u.txt=\"");
          nextion.print(HDW_u);
          nextion.write('"');
          nextion.write(nexend, 3);
          nextion.print("temps.P1o_S.txt=\"");
          nextion.print(P1o_S);
          nextion.write('"');
          nextion.write(nexend, 3);
          nextion.print("temps.P1m_S.txt=\"");
          nextion.print(P1m_S);
          nextion.write('"');
          nextion.write(nexend, 3);
          nextion.print("temps.P1u_S.txt=\"");
          nextion.print(P1u_S);
          nextion.write('"');
          nextion.write(nexend, 3);
          nextion.print("temps.P2o_S.txt=\"");
          nextion.print(P2o_S);
          nextion.write('"');
          nextion.write(nexend, 3);
          nextion.print("temps.P2m_S.txt=\"");
          nextion.print(P2m_S);
          nextion.write('"');
          nextion.write(nexend, 3);
          nextion.print("temps.P2u_S.txt=\"");
          nextion.print(P2u_S);
          nextion.write('"');
          nextion.write(nexend, 3);
          nextion.print("temps.P3o_S.txt=\"");
          nextion.print(P3o_S);
          nextion.write('"');
          nextion.write(nexend, 3);
          nextion.print("temps.P3m_S.txt=\"");
          nextion.print(P3m_S);
          nextion.write('"');
          nextion.write(nexend, 3);
          nextion.print("temps.P3u_S.txt=\"");
          nextion.print(P3u_S);
          nextion.write('"');
          nextion.write(nexend, 3);
        }
    // -- page 7 systemwerte
        if (pagestate == 7){
          //Serial.println("Seite 7 wird aktualisiert");

        if (dfd.substring((dfd.length() - 1), dfd.length()) == "?") {
          String command = dfd.substring(5, 9);
          String value = dfd.substring(9, dfd.length() - 1);
          Serial.println(command + " : " + value);
          dfd = "";

        if (command == "TEMA") {
          Puffermindesttemp = value.toInt();
          Serial.print("Puffermindesttemp: ");
          Serial.print(Puffermindesttemp);
          EEPROM.update(5, Puffermindesttemp);
          Serial.print(" - ");
          Serial.println(EEPROM.read(5));
          dfd = "";
          }
        if (command == "TEMB") {
          Pufferumladetemp = value.toInt();
          Serial.print("Pufferumladetemp: ");
          Serial.print(Pufferumladetemp);
          EEPROM.update(6, Pufferumladetemp);
          Serial.print(" - ");
          Serial.println(EEPROM.read(6));
          dfd = "";
          }
        if (command == "TEMC") {
          Ladepumpestarttemp = value.toInt();
          Serial.print("Ladepumpestarttemp: ");
          Serial.print(Ladepumpestarttemp);
          EEPROM.update(7, Ladepumpestarttemp);
          Serial.print(" - ");
          Serial.println(EEPROM.read(7));
          dfd = "";
          }
        if (command == "TEMD") {
          Ladepumpestoptemp = value.toInt();
          Serial.print("Ladepumpestoptemp: ");
          Serial.println(Ladepumpestoptemp);
          EEPROM.update(8, Ladepumpestoptemp);
          Serial.print(" - ");
          Serial.println(EEPROM.read(8));
          dfd = "";
          }
        if (command == "TEME") {
          hyst_Ladepumpe = value.toInt();
          Serial.print("hyst_Ladepumpe: ");
          Serial.println(hyst_Ladepumpe);
          EEPROM.update(9, hyst_Ladepumpe);
          Serial.print(" - ");
          Serial.println(EEPROM.read(9));
          dfd = "";
          }
        if (command == "TEMF") {
          Kesselabkuehltemperatur = value.toInt();
          Serial.print("Kesselabkuehltemperatur: ");
          Serial.println(Kesselabkuehltemperatur);
          EEPROM.update(10, Kesselabkuehltemperatur);
          Serial.print(" - ");
          Serial.println(EEPROM.read(10));
          dfd = "";
          }
        if (command == "TEMG") {
          Kesseltempkorrektur = value.toInt();
          Serial.print("Kesseltempkorrektur: ");
          Serial.println(Kesseltempkorrektur);
          EEPROM.update(11, Kesseltempkorrektur);
          Serial.print(" - ");
          Serial.println(EEPROM.read(11));
          dfd = "";
          }
        if (command == "TEMH") {
          Puffertempkorrektur = value.toInt();
          Serial.print("Puffertempkorrektur: ");
          Serial.println(Puffertempkorrektur);
          EEPROM.update(12, Puffertempkorrektur);
          Serial.print(" - ");
          Serial.println(EEPROM.read(12));
          dfd = "";
          }
        if (command == "TEMI") {
          WBW_Temp_max = value.toInt();
          Serial.print("WBW_Temp_max: ");
          Serial.println(WBW_Temp_max);
          EEPROM.update(13, WBW_Temp_max);
          Serial.print(" - ");
          Serial.println(EEPROM.read(13));
          dfd = "";
          }
        if (command == "TEMJ") {
          WBW_Temp_min = value.toInt();
          Serial.print("WBW_Temp_min: ");
          Serial.println(WBW_Temp_min);
          EEPROM.update(14, WBW_Temp_min);
          Serial.print(" - ");
          Serial.println(EEPROM.read(14));
          dfd = "";
          }
        if (command == "TEMK") {
          Legionellentemp_min = value.toInt();
          Serial.print("Legionellentemp_min: ");
          Serial.println(Legionellentemp_min);
          EEPROM.update(15, Legionellentemp_min);
          Serial.print(" - ");
          Serial.println(EEPROM.read(15));
          dfd = "";
          }
        if (command == "TEML") {
          hyst_WBW = value.toInt();
          Serial.print("hyst_WBW: ");
          Serial.println(hyst_WBW);
          EEPROM.update(16, hyst_WBW);
          Serial.print(" - ");
          Serial.println(EEPROM.read(16));
          dfd = "";
          }
        }
        }
    // -- page 8 Legionellenbehandlung
        if (pagestate == 8){
          //Serial.println("Seite 8 wird aktualisiert");

        if (dfd.substring((dfd.length() - 1), dfd.length()) == "?") {
          String command = dfd.substring(5, 9);
          String value = dfd.substring(9, dfd.length() - 1);
          Serial.println(command + " : " + value);
          dfd = "";

        if (command == "LEGD") {
          Ein_Tag = value.toInt();
          Serial.print("Ein_Tag: ");
          Serial.print(Ein_Tag);
          EEPROM.update(0, Ein_Tag);
          Serial.print(" - ");
          Serial.println(EEPROM.read(0));
          dfd = "";
          }
        if (command == "LEGS") {
          Ein_Stunde = value.toInt();
          Serial.print("Ein_Stunde: ");
          Serial.print(Ein_Stunde);
          EEPROM.update(1, Ein_Stunde);
          Serial.print(" - ");
          Serial.println(EEPROM.read(1));
          dfd = "";
          }
        if (command == "LEGM") {
          Ein_Minute = value.toInt();
          Serial.print("Ein_Minute: ");
          Serial.print(Ein_Minute);
          EEPROM.update(2, Ein_Minute);
          Serial.print(" - ");
          Serial.println(EEPROM.read(2));
          dfd = "";
          }
        }
        }
  
// -- buttonstate
  // -- Brauchwasserladung
      if (dfd == "T_P"){
        btn_state_T_P = 1;
        Serial.print("btn_state_T_P ");
        Serial.println(btn_state_T_P);
        dfd="";}
  // -- Zirkulationspumpe
      if (dfd == "Z_P"){
        btn_state_Z_P = 1;
        btn_state_hand_ZPBW = 1;
        Serial.print("btn_state_Z_P ");
        Serial.print(btn_state_Z_P);
        //Serial.println(" Zirkulationspumpe Brauchwasser ein");
        dfd="";}
  // -- hand Legio
      if (dfd == "hand_legio"){
      btn_state_legio = 1;
      Serial.print("btn_state_legio ");
      Serial.println(btn_state_legio);
      dfd="";}
  // -- hand Pufferladepumpe
      if (dfd == "hand_PLP" && (!btn_state_hand_PLP)){
      btn_state_hand_PLP = 1;
      Serial.print("btn_state_hand_PLP ");
      Serial.println(btn_state_hand_PLP);
      dfd="";}
      else if (dfd == "hand_PLP" && (btn_state_hand_PLP)){
      btn_state_hand_PLP = 0;
      Serial.print("btn_state_hand_PLP ");
      Serial.println(btn_state_hand_PLP);
      dfd="";}
  // -- hand Brauchwasserladepumpe
      if (dfd == "hand_BWLP" && (!btn_state_hand_BWLP)){
      btn_state_hand_BWLP = 1;
      Serial.print("btn_state_hand_BWLP ");
      Serial.println(btn_state_hand_BWLP);
      dfd="";}
      else if (dfd == "hand_BWLP" && (btn_state_hand_BWLP)){
      btn_state_hand_BWLP = 0;
      Serial.print("btn_state_hand_BWLP ");
      Serial.println(btn_state_hand_BWLP);
      dfd="";}
  // -- hand Zirkulationspumpe Brauchwasser
      if (dfd == "hand_ZPBW" && (!btn_state_hand_ZPBW)){
      btn_state_hand_ZPBW = 1;
      Serial.print("btn_state_hand_ZPBW ");
      Serial.println(btn_state_hand_ZPBW);
      dfd="";}
      else if (dfd == "hand_ZPBW" && (btn_state_hand_ZPBW)){
      btn_state_hand_ZPBW = 0;
      Serial.print("btn_state_hand_ZPBW ");
      Serial.println(btn_state_hand_ZPBW);
      dfd="";}
  // -- hand Zirkulationspumpe Speicherumladung
      if (dfd == "hand_ZPSU" && (!btn_state_hand_ZPSU)){
      btn_state_hand_ZPSU = 1;
      Serial.print("btn_state_hand_ZPSU ");
      Serial.println(btn_state_hand_ZPSU);
      dfd="";}
      else if (dfd == "hand_ZPSU" && (btn_state_hand_ZPSU)){
      btn_state_hand_ZPSU = 0;
      Serial.print("btn_state_hand_ZPSU ");
      Serial.println(btn_state_hand_ZPSU);
      dfd="";}
  // -- hand 3 Wegeventil
      if (dfd == "hand_WV" && (!btn_state_hand_WV)){
      btn_state_hand_WV = 1;
      Serial.print("btn_state_hand_WV ");
      Serial.println(btn_state_hand_WV);
      dfd="";}
      else if (dfd == "hand_WV" && (btn_state_hand_WV)){
      btn_state_hand_WV = 0;
      Serial.print("btn_state_hand_WV ");
      Serial.println(btn_state_hand_WV);
      dfd="";}
  // -- Zuheizung
      if (dfd == "zuheizung_gas"){
      EEPROM.update(17, 2);      
      dfd="";}
  // -- Zuheizung elektro
      if (dfd == "zuheizung_elektro"){
      EEPROM.update(17, 1);
      dfd="";}
  // -- Zuheizung aus
      if (dfd == "zuheizung_aus"){
      EEPROM.update(17, 0);
      dfd="";}
// -- Relais ein/aus
  // -- Pumpe Zirkulation Brauchwasser
      if ((btn_state_Z_P == 1) || (btn_state_hand_ZPBW == 1)){
      digitalWrite(Z_P, LOW);}
      else {
      digitalWrite(Z_P, HIGH);}
  // -- Pumpe Brauchwasserladung
      if ((((HDW_u <= WBW_Temp_min) && ((HDW_o + hyst_WBW) < P1o_S) && (HDW_o > HDW_u)) || (H0_S + Kesseltempkorrektur) >= Kesselabkuehltemperatur) ||  btn_state_T_P == 1 || btn_state_hand_BWLP == 1) {
        digitalWrite(T_P, LOW);
        //Serial.println("Brauchwasserladung ein");
        }
      if (((Uhr_d == Ein_Tag) && (Uhr_h == Ein_Stunde) && (Uhr_m == Ein_Minute)) && (P1o_S >= Legionellentemp_min)){
        digitalWrite(T_P, LOW);
        btn_state_legio = 1;
        last_status_legionellen = 1;
        EEPROM.update(30, 1);
        Serial.println("Legionellenbehandlung ein");
        }
      if ((Uhr_d == Ein_Tag) && (Uhr_h == Ein_Stunde) && (Uhr_m == Ein_Minute) && (P1o_S < Legionellentemp_min)){
        last_status_legionellen = 4;
        btn_state_legio = 0;
        EEPROM.update(30, 3);
        Serial.println("Legionellenbehandlung konnte nicht gestartet werden - Puffertemperatur zu gering");
        }
      if ((((((HDW_o + hyst_WBW) > P1o_S) || (HDW_u >= WBW_Temp_max)) && (H0_S + Kesseltempkorrektur) < Kesselabkuehltemperatur) && btn_state_hand_BWLP == 0) && btn_state_legio == 0)  {
        digitalWrite(T_P, HIGH);
        btn_state_T_P = 0;
        // Serial.println("Brauchwasserladung aus");
        }
      if ((HDW_u >= Legionellentemp_min) && (btn_state_legio == 1)){
        digitalWrite(T_P, HIGH);
        EEPROM.update(30, 2);
        Serial.println("Legionellenbehandlung abgeschlossen");
        btn_state_legio = 0;
        last_status_legionellen = 2;
        }
      if ((btn_state_legio == 1) && (HDW_u >= P1o_S)){
        digitalWrite(T_P, HIGH);
        btn_state_legio = 0;
        last_status_legionellen = 3;
        EEPROM.update(30, 4);
        Serial.println("Legionellenbehandlung abgebrochen");
        }
      
  // -- Pumpe Pufferspeicherladung
      if (((((H0_S + Kesseltempkorrektur) >= Ladepumpestarttemp) && ((H0_S + Kesseltempkorrektur) > ((P3u_S + Puffertempkorrektur) + hyst_Ladepumpe))) || ((H0_S + Kesseltempkorrektur) >= Kesselabkuehltemperatur)) || btn_state_hand_PLP == 1)
          {
          digitalWrite(OUT_A, LOW);
          //Serial.println("Pufferladepumpe ein");
          }
      if (((H0_S + Kesseltempkorrektur) <= Ladepumpestoptemp) || ((H0_S + Kesseltempkorrektur) < ((P3u_S + Puffertempkorrektur) + hyst_Ladepumpe)))
      if (btn_state_hand_PLP == 0){
          digitalWrite(OUT_A, HIGH);
          //Serial.println("Pufferladepumpe aus");
          }

  // -- Zuheizung Gas ein
      if ((P1o_S < Puffermindesttemp) && ((H0_S + Kesseltempkorrektur) < Ladepumpestarttemp) && (last_status_zuheizung == 2)){
          digitalWrite(OUT_C, LOW);
          digitalWrite(OUT_D, LOW);
          }
      if (((H0_S + Kesseltempkorrektur) > Ladepumpestoptemp) || (last_status_zuheizung == 0) || (last_status_zuheizung == 1) || (P1o_S > Puffermindesttemp)) {
          digitalWrite(OUT_C, HIGH);
          digitalWrite(OUT_D, HIGH);
          }
  // -- Zuheizung elektro ein
      if ((P1o_S < Puffermindesttemp) && ((H0_S + Kesseltempkorrektur) < Ladepumpestarttemp) && (last_status_zuheizung == 1)){
          digitalWrite(OUT_B, LOW);
          //Serial.println ("Zuheizung elektro ein");
          }
      if (((H0_S + Kesseltempkorrektur) > Ladepumpestoptemp) || (last_status_zuheizung == 0) || (last_status_zuheizung == 2) || (P1o_S > Puffermindesttemp)) {
          digitalWrite(OUT_B, HIGH);
          //Serial.println ("Zuheizung elektro aus");
          }    
  // -- Pumpe Zirkulation Speicherumladung
      if ((((P1o_S < Pufferumladetemp) && (P2o_S > P1o_S)) && (digitalRead(OUT_A) == 1)) || btn_state_hand_ZPSU == 1){
          digitalWrite(OUT_E, LOW);
          //Serial.println ("Pumpe Speicherumladung ein");
          }
      if (((P2o_S <= P1o_S) || (digitalRead(OUT_A) == 0)) && btn_state_hand_ZPSU == 0){
          digitalWrite(OUT_E, HIGH);
          //Serial.println ("Pumpe Speicherumladung aus");
          }
  // -- 3 Wegeventil
      if ((digitalRead(OUT_C) == 0) || (btn_state_hand_WV == 1)){
          digitalWrite(OUT_D, LOW);}
          else{
          digitalWrite(OUT_D, HIGH);
          }
  }
// -- Subrutine Sensoren abfragen
  void printAddress(DeviceAddress deviceAddress){ 
    for (uint8_t i = 0; i < 8; i++)  {
    Serial.print("0x");
    if (deviceAddress[i] < 0x10) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
    if (i < 7) Serial.print(", ");}
    Serial.println("");}

// -- Uhrzeit
  void Uhrzeit() {
  DateTime now = RTC.now();         // Datum und Zeit ermitteln
  Uhr_d = int(now.dayOfTheWeek());  // Wochentag ermitteln
  Uhr_h = int(now.hour());          // Stunden ermitteln
  if (Sommer == true) {             // bei Sommerzeit
  Uhr_h = int(now.hour() + 1);}     // 1 Stunde addieren
  Uhr_m = int(now.minute());        // Minuten ermitteln
  Uhr_s = int(now.second());}       // Sekunden ermitteln
  // ----------------------------------------- Subroutine Sommerzeit ermitteln -----------------------------------------------
  boolean Sommerzeit() {
  DateTime now = RTC.now();
  if (now.month() < 3 || now.month() > 10) return false;  // keine Sommerzeit Jan - Dez
  if (now.month() > 3 && now.month() < 10) return true;   // Sommerzeit Apr bis Sep
  if (now.month() == 3 && now.day() < 25) return false;   // keine Sommerzeit bis 25.März
  if (now.month() == 10 && now.day() < 25) return true;   // Sommerzeit bis 25.Okt.
  if (now.month() == 3 && (now.hour() + 24 * now.day()) >= (1 + 24 * (31 - (5 * now.year() / 4 + 4) % 7)) || now.month() == 10 && (now.hour() + 24 * now.day()) < (1 + 24 * (31 - (5 * now.year() / 4 + 1) % 7)))
  return true;
  else
  return false;}  // Ende Sommerzeit 
// -- Temperatursensoren
  void tempssensoren() {
        if (millis() - previousMillis2 >= TIME_INTERVAL2){
        //Serial.println("Sensoren lesen");
        DeviceAddress  Sensor0 = { 0x28,0xFE,0xF2,0x81,0xE3,0x3A,0x3C,0xF8 };   // H0_S    
        DeviceAddress  Sensor1 = { 0x28,0xA8,0x54,0x81,0xE3,0x64,0x3C,0x60 };   // HDW_o   
        DeviceAddress  Sensor2 = { 0x28,0x12,0x0D,0x49,0xF6,0x72,0x3C,0xD2 };   // HDW_u   
        DeviceAddress  Sensor3 = { 0x28,0x05,0x8E,0x81,0xE3,0x58,0x3C,0xF5 };   // P1o_S   
        DeviceAddress  Sensor4 = { 0x28,0x20,0x58,0x49,0xF6,0xA1,0x3C,0x1B };   // P1m_S   
        DeviceAddress  Sensor5 = { 0x28,0x83,0xCE,0x49,0xF6,0x08,0x3C,0x69 };   // P1u_S   
        DeviceAddress  Sensor6 = { 0x28,0x9F,0xE6,0x48,0xF6,0x2C,0x3C,0xFC };   // P2o_S   
        DeviceAddress  Sensor7 = { 0x28,0x9B,0xF8,0x49,0xF6,0x9B,0x3C,0x1D };   // P2m_S   
        DeviceAddress  Sensor8 = { 0x28,0x90,0x1B,0x49,0xF6,0x35,0x3C,0x43 };   // P2u_S   
        DeviceAddress  Sensor9 = { 0x28,0xCD,0x6E,0x81,0xE3,0x34,0x3C,0x06 };   // P3o_S  
        DeviceAddress Sensor10 = { 0x28,0xB2,0xC0,0x81,0xE3,0x89,0x3C,0xA0 };   // P3m_S   
        DeviceAddress Sensor11 = { 0x28,0x3A,0xBA,0x81,0xE3,0x71,0x3C,0xD4 };   // P3u_S
        DeviceAddress Sensor12 = { 0x28,0x2B,0xB2,0x80,0xE3,0xE1,0x3C,0xCA };   // Aussentemp

        sensors.requestTemperatures();
        H0_S = sensors.getTempC(Sensor0);
        //Serial.print(" H0_S: ");
        //Serial.println(H0_S);        
        HDW_o = sensors.getTempC(Sensor1);
        //Serial.print("HDW_o: ");
        //Serial.println(HDW_o);        
        HDW_u = sensors.getTempC(Sensor2);
        //Serial.print("HDW_u: ");
        //Serial.println(HDW_u);        
        P1o_S = sensors.getTempC(Sensor3);
        //Serial.print("P1o_S: ");
        //Serial.println(P1o_S);        
        P1m_S = sensors.getTempC(Sensor4);
        //Serial.print("P1m_S: ");
        //Serial.println(P1m_S);        
        P1u_S = sensors.getTempC(Sensor5);
        //Serial.print("P1u_S: ");
        //Serial.println(P1u_S);        
        P2o_S = sensors.getTempC(Sensor6);
        //Serial.print("P2o_S: ");
        //Serial.println(P2o_S);        
        P2m_S = sensors.getTempC(Sensor7);
        //Serial.print("P2m_S: ");
        //Serial.println(P2m_S);        
        P2u_S = sensors.getTempC(Sensor8);
        //Serial.print("P2u_S: ");
        //Serial.println(P2u_S);        
        P3o_S = sensors.getTempC(Sensor9);
        //Serial.print("P3o_S: ");
        //Serial.println(P3o_S);        
        P3m_S = sensors.getTempC(Sensor10);
        //Serial.print("P3m_S: ");
        //Serial.println(P3m_S);        
        P3u_S = sensors.getTempC(Sensor11);
        //Serial.print("P3u_S: ");
        //Serial.println(P3u_S);
        aussentemp = sensors.getTempC(Sensor12);
        //Serial.print("aussentemp: ");
        //Serial.println(aussentemp);       
        previousMillis2 = millis();}
         
        }

NIcht Dein Problem, aber ist das so gewollt???

Über den Rest muss ich länger schauen. Das schaff ich nicht in den nächsten MInuten bis zum Bus....

Nachtrag: Deine Prints sind alle Speicherintensiv....
Verwende das F-Makro.
Und Du benutzt Strings. Auch zum Vergleichen. Das bricht Dir das Genick...

Ja, mit den Pin's ist erst einmal so gewollt. Mit den Prints weiß ich ja auch.
Der sketch lief ja zum testen, schon eine weile auf dem UNO. Nun wollte ich ein paar Dinge ändern. Aber selbst dieser(Originalsketch) passt nun angeblich nicht mehr auf den UNO. Gebe ich jedoch den WIFI R4 ein, Ist der Speicher nicht einmal bis zur hälfte belegt. Auch beim UNO waren damals noch genügend Ressourcen.

Ich hab den hier auf einer 1.8.19 kompiliert und der fliegt mir um die Ohren.
Da ich auch schon länger keine Updates für die libs gefahren habe, ist das Problem nicht so jung. (Meine libs sind alle älter 1 Jahr++)

Mal sehen, was ich da noch rauslese und wie man das relativ schnell ändern kann, damit der wieder läuft...

UNO bedeutet in dem Fall nur die Größe und die teilweise Kompatibilität mit R3, hat aber wie man schon mit bloßem Augen sehen kann hat ganz anderen Controller drauf, der wiederum hat viel mehr Speicher OnBoard,

Da ich für solche Logiken zu haben bin, die doppelt sind....

Was fällt Dir zwischen diesen beiden Versionen auf?

    //Serial.println("Seite 0 wird aktualisiert");
    if ((P1m_S < Puffermindesttemp) && (millis() % (2000 + 2000) < 2000))
    {
      nextion.print("null.zerot18.txt=\"");
      nextion.print("BITTE ANLEGEN");
      nextion.write('"');
      nextion.write(nexend, 3);
    }
    else if (P1m_S < Puffermindesttemp)
    {
      nextion.print("null.zerot18.txt=\"");
      nextion.print(" ");
      nextion.write('"');
      nextion.write(nexend, 3);
    }

und meine:

    //Serial.println("Seite 0 wird aktualisiert");
    if (P1m_S < Puffermindesttemp)
    {
      nextion.print("null.zerot18.txt=\"");
      if (millis() % (2000 + 2000) < 2000)
      { nextion.print("BITTE ANLEGEN");  }
      else
      { nextion.print(" "); }
      nextion.write('"');
      nextion.write(nexend, 3);
    }

Und jetzt ganz wichtig:
sowas hier:

      if (millis() % (2000 + 2000) < 2000)

unbedingt vermeiden!
Magic Numbers...
Und das mit dem modulo rechnen geht evtl. auch schief wenn Du den Zeitpunkt verpasst.

Also da ist ganz viel Stoff zum überarbeiten.

Ich bin für heute leider raus.
Aber ist eine schöne Aufgabe....

Finde ich super von dir, den sketch optimieren zu wollen. Ich selbst bin noch fast blutiger Anfänger. Aber wie gesagt, diesen habe ich ich ja schon auf den UNO R3 kompilieren können. aber nach dem Update, kann ich diesen sketch nicht mehr hochladen (speicher plötzlich zu klein). Diesen benötige ich aber eben noch als Übergangslösung für meine Heizungssteuerung. Wäre schön wenn wir das lösen könnten. Für die nächste Version habe ich einen MEGA in Einsatz, verschiedene Heizkreise, Zeiten, Heizkreismischer, ect.. Wir auf jedenfalls noch recht interessant.

//Serial.println("Seite 0 wird aktualisiert");
    if (P1m_S < Puffermindesttemp)
    {
      nextion.print("null.zerot18.txt=\"");
      if (millis() % (2000 + 2000) < 2000)
      { nextion.print("BITTE ANLEGEN");  }
      else
      { nextion.print("null.zerot18.txt=\"");
        nextion.print(" "); }
        nextion.write('"');
        nextion.write(nexend, 3);
      }

Das Nextion möchte immer eine Position haben, wo es schreiben soll.

Mit ist gerade nicht ganz klar um welchen Arduino es hier geht. Uno R3? Uno R4?

Was würde aktualisiert? Das Board Framework?

Hat sich vielleicht eine Option "Compiler Optimierungen" auf "keine" verstellt?

Modulo führt da zu Hacklern/Jitter.
Hier beschrieben: [Bericht] Der (Millis) Ueberlauf im Test

Dass die Speicherauslastung bei einem Uno R4 im Vergleich zu einem Uno R3 geringer erscheint hat ja schon damit zu tun, dass auf dem Uno R4 ein gänzlich anderer Microcontroller mit wesentlich mehr Speicher verbaut ist.

Das ist kein Vergleichsmaßstab zu einem Uno R3.

Aber nicht so.
Und ich hab auch die Stelle gefunden, die Dir das Genick bricht...
Auslöser ist die Verwendung von:

Damit vollführst Du innerhalb Deines Codes gaaanz viele Additionsoperationen.
Und schwupp wird für jedes Ergebnis ein neuer Speicherbereich angelegt.

Wenn Du das

addieren von endchar da überall raus nimmst, geht das auch schon mal zu kompilieren.
An Stelle der Additionsarie könntest Du Dein

nextion.write(nexend, 3);}

danach verwenden um den selben Effekt - ohne Speicherprpbleme - zu erreichen.
Allerings gibt es da noch ganz viele Baustellen.
Ich weiß nur nicht, wo es am sinnvolsten ist anzufangen.

Der Code ist leider eine sehr lange Spaghetti - und ich hab mal angefangen aufzulösen und in Funktionen aufzuteilen.

Ein erster Ansatz ist dann das folgende - allerdings wird das vermutlich so nicht funktionieren.
Und ich muss die Nextionpage-Funktion noch auflösen und diese ganzen doppelten Codedinge rauspuzzlen.

Schau es Dir an, damit Du mal einen ersten Eindruck bekommst.
Ich mach da weiter, aber ich bin am WE nicht am Rechner.

Sobald ich die ganze Logik dahinter verstanden habe versuche ich noch einige Variablen aufzulösen und vielleicht noch 1 oder 2 struct anzulegen.

Es wird - und dann auch auf dem UNO wieder laufen :slight_smile:

// -- Zeit
#include <Wire.h>                               // Lib zur I2C-Kommunikation
#include <RTClib.h>                             // Lib für die Real Time Clock
#include <EEPROM.h>                             // Lib für das interne EEPROM
char daysOfTheWeek[7][12] = { "Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag" };
RTC_DS3231 RTC;
int Ein_Stunde, Ein_Minute;                     // Einschaltzeit
int Aus_Stunde, Aus_Minute;                     // Ausschaltzeit
int Ein_Tag;                                    // Einschalttag für Legionellen
int Datum_Tag_set, Datum_Monat_set, Datum_Jahr_set;               // Variable Zeiteingabe Nextion
int Uhr_h_set, Uhr_m_set, Uhr_s_set;

DateTime now;

// -- Nextion
String dfd = "";
String endChar = String(char(0xff)) + String(char(0xff)) + String(char(0xff));
//byte nexend[3] = {255, 255, 255};
#include <SoftwareSerial.h>
SoftwareSerial nextion(3, 2); // RX, TX

// -- Temperatursensoren
#include <OneWire.h>                            // Lib für OneWire
#include <DallasTemperature.h>                  // Lib für DS18B20
#define ONE_WIRE_BUS 4                          // Sensor an PIN (4)
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress SensorH0_S = { 0x28, 0xFE, 0xF2, 0x81, 0xE3, 0x3A, 0x3C, 0xF8 }; // H0_S
DeviceAddress SensorHDW_o = { 0x28, 0xA8, 0x54, 0x81, 0xE3, 0x64, 0x3C, 0x60 }; // HDW_o
DeviceAddress SensorHDW_u = { 0x28, 0x12, 0x0D, 0x49, 0xF6, 0x72, 0x3C, 0xD2 }; // HDW_u
DeviceAddress SensorP1o_S = { 0x28, 0x05, 0x8E, 0x81, 0xE3, 0x58, 0x3C, 0xF5 }; // P1o_S
DeviceAddress SensorP1m_S = { 0x28, 0x20, 0x58, 0x49, 0xF6, 0xA1, 0x3C, 0x1B }; // P1m_S
DeviceAddress SensorP1u_S = { 0x28, 0x83, 0xCE, 0x49, 0xF6, 0x08, 0x3C, 0x69 }; // P1u_S
DeviceAddress SensorP2o_S = { 0x28, 0x9F, 0xE6, 0x48, 0xF6, 0x2C, 0x3C, 0xFC }; // P2o_S
DeviceAddress SensorP2m_S = { 0x28, 0x9B, 0xF8, 0x49, 0xF6, 0x9B, 0x3C, 0x1D }; // P2m_S
DeviceAddress SensorP2u_S = { 0x28, 0x90, 0x1B, 0x49, 0xF6, 0x35, 0x3C, 0x43 }; // P2u_S
DeviceAddress SensorP3o_S = { 0x28, 0xCD, 0x6E, 0x81, 0xE3, 0x34, 0x3C, 0x06 }; // P3o_S
DeviceAddress SensorP3m_S = { 0x28, 0xB2, 0xC0, 0x81, 0xE3, 0x89, 0x3C, 0xA0 }; // P3m_S
DeviceAddress SensorP3u_S = { 0x28, 0x3A, 0xBA, 0x81, 0xE3, 0x71, 0x3C, 0xD4 }; // P3u_S
DeviceAddress SensorAussentemp = { 0x28, 0x2B, 0xB2, 0x80, 0xE3, 0xE1, 0x3C, 0xCA }; // Aussentemp

// -- Ausgänge
constexpr uint8_t nextion_power {12};          // Power ein für Nexton an PIN 12             Relais K1
constexpr uint8_t OUT_A         {6};           // Pumpe Speicherladung an PIN 6              Relais K7 auf K11
constexpr uint8_t OUT_B         {9};           // Zuheizung elektro an PIN 9                 Relais K4 auf K14
constexpr uint8_t OUT_C         {10};          // Zuheizung Gas an PIN 10                    Relais K3 auf K15
constexpr uint8_t OUT_D         {10};          // 3 Wegeventil an PIN 10                     Relais K3 auf K15
constexpr uint8_t OUT_E         {8};           // Pumpe Speicherumladung an PIN 8            Relais K5 auf K13
constexpr uint8_t Z_P           {7};           // Pumpe Zirkulation Brauchwasser an PIN 7    Relais K6 auf K12
constexpr uint8_t T_P           {5};           // Pumpe Brauchwasserladung an PIN 5          Relais K8 auf K10
constexpr uint8_t rest          {13};          // reset Nextion Button an PIN 13

constexpr bool aktiv {HIGH};
constexpr bool inaktiv {!aktiv};

constexpr bool ein {LOW};
constexpr bool aus {!ein};

// -- int button
uint8_t pageType;
uint8_t last_type_zuheizung;
uint8_t last_type_legionellen;
bool btn_state_T_P =               inaktiv;
bool btn_state_Z_P =               inaktiv;
bool btn_state_legio =             inaktiv;
bool btn_state_hand_PLP =          inaktiv;
bool btn_state_hand_BWLP =         inaktiv;
bool btn_state_hand_ZPBW =         inaktiv;
bool btn_state_hand_ZPSU =         inaktiv;
bool btn_state_hand_WV =           inaktiv;

bool zeit_stellen;

// -- millis
constexpr unsigned long refreshPause {10000};   // Zeit Zeitanzeige
unsigned long lastRefresh;
constexpr unsigned long sensorPause {1000}; // Zeit Sensoren auslesen
unsigned long lastSensorRead;

// -- int Temperatursensoren
int aussentemp;                         // Aussentemperatur
int H0_S;                               // Kesseltemperatur
int HDW_o;                              // Brauchwasserspeichertemperatur oben
int HDW_u;                              // Brauchwasserspeichertemperatur unten
int P1o_S;                              // Pufferspeicher 1 Temperatur oben
int P1m_S;                              // Pufferspeicher 1 Temperatur mitte
int P1u_S;                              // Pufferspeicher 1 Temperatur unten
int P2o_S;                              // Pufferspeicher 2 Temperatur oben
int P2m_S;                              // Pufferspeicher 2 Temperatur mitte
int P2u_S;                              // Pufferspeicher 2 Temperatur unten
int P3o_S;                              // Pufferspeicher 3 Temperatur oben
int P3m_S;                              // Pufferspeicher 3 Temperatur mitte
int P3u_S;                              // Pufferspeicher 3 Temperatur unten

// -- int Systemvariablen
int Puffermindesttemp;
int Pufferumladetemp;
int Ladepumpestarttemp;
int Ladepumpestoptemp;
int hyst_Ladepumpe;
int Kesselabkuehltemperatur;
int Kesseltempkorrektur;
int Puffertempkorrektur;
int WBW_Temp_max;
int WBW_Temp_min;
int Legionellentemp_min;
int hyst_WBW;

void setup()
{
  Serial.begin(19200);
  Serial.println(F("Start"));
  nextion.begin(19200);
  // -- pinMode
  pinMode(nextion_power, OUTPUT);
  digitalWrite(nextion_power, HIGH);
  pinMode(OUT_A, OUTPUT);
  digitalWrite(OUT_A, ein);
  pinMode(OUT_B, OUTPUT);
  digitalWrite(OUT_B, aus);
  pinMode(OUT_C, OUTPUT);
  digitalWrite(OUT_C, aus);
  pinMode(OUT_D, OUTPUT);
  digitalWrite(OUT_D, aus);
  pinMode(OUT_E, OUTPUT);
  digitalWrite(OUT_E, aus);
  pinMode(T_P, OUTPUT);
  digitalWrite(T_P, aus);
  pinMode(Z_P, OUTPUT);
  digitalWrite(Z_P, aus);
  pinMode(rest, INPUT_PULLUP);
  Wire.begin();
  // -- RTC
  RTC.begin();                          // Uhr starten
  //RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));  // Zeit vom PC einlesen, Wenn Uhrzeit neu gesetzt werden soll, sonst auskommentieren !!!
  //RTC.adjust(DateTime(2023, 10, 8, 21, 21, 30));
  if (!RTC.begin())
  {
    Serial.println(F("Couldn't find RTC"));
    Serial.flush();
  }
  readEepromData();
  sensorsInit();
  delay(5000);
  digitalWrite(OUT_A, aus);
  delay(2000);
  digitalWrite(nextion_power, ein); // Nextion einschalten
  delay(2000);
}

void loop()
{
  now = RTC.now();
  Zirkulationspumpe();
  getTempSensoren();
  NextionRefresh();
  time2Serial();
  checkNextion();
}

// -- Subroutine Sensoren abfragen
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    Serial.print("0x");
    if (deviceAddress[i] < 0x10)
    { Serial.print(0); }
    Serial.print(deviceAddress[i], HEX);
    if (i < 7)
    { Serial.print(", "); }
  }
  Serial.println();
}
// -- Zeit Zirkulationspumpe
void Zirkulationspumpe()
{
  static uint32_t previousMillis3 = 0;
  if (btn_state_Z_P == inaktiv)
  {
    btn_state_Z_P = inaktiv;
    previousMillis3 = millis();
  }
  else if (millis() - previousMillis3 > 300 * 1000UL)  // (300 * 1000UL)
  {
    btn_state_Z_P = inaktiv;
    btn_state_hand_ZPBW = inaktiv;
    Serial.print(F("btn_state_Z_P "));
    Serial.print(btn_state_Z_P);
    Serial.println(F(" Zirkulationspumpe Brauchwasser aus"));
  }
}
// -- reset Nextion
void NextionRefresh()
{
  if (!digitalRead(rest))
  {
    nextion.print(F("rest"));
    nextEnd();
    Serial.println(F("Nextion reset"));
    delay(1000);
    pageType = 0;
  }
}

// ----------------------------------------- Subroutine Sommerzeit ermitteln -----------------------------------------------
boolean sommerzeit()
{
  if (now.month() > 3 && now.month() < 10)
  { return true;  } // Sommerzeit Apr bis Sep
  if (now.month() == 10 && now.day() < 25)
  { return true; } // Sommerzeit bis 25.Okt.
  if (now.month() == 3 && (now.hour() + 24 * now.day()) >= (1 + 24 * (31 - (5 * now.year() / 4 + 4) % 7)) ||
      now.month() == 10 && (now.hour() + 24 * now.day()) < (1 + 24 * (31 - (5 * now.year() / 4 + 1) % 7)))
  { return true; } // Sommerzeit zwischen März und Oktober
  return false; // keine Sommerzeit
}  // Ende Sommerzeit

// -- Temperatursensoren abfragen
void getTempSensoren()
{
  if (millis() - lastSensorRead >= sensorPause)
  {
    //Serial.println("Sensoren lesen");
    H0_S = sensors.getTempC(SensorH0_S);
    //Serial.print(" H0_S: ");
    //Serial.println(H0_S);
    HDW_o = sensors.getTempC(SensorHDW_o);
    //Serial.print("HDW_o: ");
    //Serial.println(HDW_o);
    HDW_u = sensors.getTempC(SensorHDW_u);
    //Serial.print("HDW_u: ");
    //Serial.println(HDW_u);
    P1o_S = sensors.getTempC(SensorP1o_S);
    //Serial.print("P1o_S: ");
    //Serial.println(P1o_S);
    P1m_S = sensors.getTempC(SensorP1m_S);
    //Serial.print("P1m_S: ");
    //Serial.println(P1m_S);
    P1u_S = sensors.getTempC(SensorP1u_S);
    //Serial.print("P1u_S: ");
    //Serial.println(P1u_S);
    P2o_S = sensors.getTempC(SensorP2o_S);
    //Serial.print("P2o_S: ");
    //Serial.println(P2o_S);
    P2m_S = sensors.getTempC(SensorP2m_S);
    //Serial.print("P2m_S: ");
    //Serial.println(P2m_S);
    P2u_S = sensors.getTempC(SensorP2u_S);
    //Serial.print("P2u_S: ");
    //Serial.println(P2u_S);
    P3o_S = sensors.getTempC(SensorP3o_S);
    //Serial.print("P3o_S: ");
    //Serial.println(P3o_S);
    P3m_S = sensors.getTempC(SensorP3m_S);
    //Serial.print("P3m_S: ");
    //Serial.println(P3m_S);
    P3u_S = sensors.getTempC(SensorP3u_S);
    //Serial.print("P3u_S: ");
    //Serial.println(P3u_S);
    aussentemp = sensors.getTempC(SensorAussentemp);
    //Serial.print("aussentemp: ");
    //Serial.println(aussentemp);
    sensors.requestTemperatures();
    lastSensorRead = millis();
  }
}

void nextPrintValueWithEnd(const char *text, const int &value)
{
  nextPrintValueWithoutEnd(text, value);
  nextEnd();
}

void nextPrintValueWithoutEnd(const char *text, const int &value)
{
  nextion.print(text);
  nextion.print(value);
}

void nextEnd()
{
  for (byte b = 0; b < 3; b++)
  { nextion.write(0xFF); }
}

void sensorsInit()
{
  // wird einmalig aufgerufen!
  // -- Temperatursensoren im BUS lokalisieren
  sensors.begin();                        // Sensoren starten
  Serial.println(F("Suche Sensoren..."));
  Serial.print(F("gefunden "));
  uint8_t deviceCount = sensors.getDeviceCount();
  Serial.print(deviceCount, DEC);
  Serial.println(F(" Sensoren."));
  Serial.println();
  Serial.println(F("schreibe Adressen..."));
  DeviceAddress Thermometer;
  for (int i = 0;  i < deviceCount;  i++)
  {
    Serial.print(F("Sensor "));
    Serial.print(i + 1);
    Serial.print(F(" : "));
    sensors.getAddress(Thermometer, i);
    printAddress(Thermometer);
  }
  sensors.requestTemperatures();
  delay(1000); // Wartezeit für temperatursensorik
  getTempSensoren();
}

void readEepromData()
{
  // -- EEPROM einlesen
  Ein_Tag =                   EEPROM.read(0);      // Einschalttag auslesen
  Ein_Stunde =                EEPROM.read(1);      // Einschaltzeit Stunde einlesen
  Ein_Minute =                EEPROM.read(2);      // Einschaltzeit Minute einlesen
  Puffermindesttemp =         EEPROM.read(5);      // Pufferspeichermindesttemperatur 40°C
  Pufferumladetemp =          EEPROM.read(6);      // Pufferspeicherumladungstemperatur 55°C
  Ladepumpestarttemp =        EEPROM.read(7);      // Einschalttemperatur Speicherladepumpe 68 °C
  Ladepumpestoptemp =         EEPROM.read(8);      // Ausschalttemperatur Speicherladepumpe 65°C
  hyst_Ladepumpe =            EEPROM.read(9);      // Hysterese Pufferladepumpe 2 °
  Kesselabkuehltemperatur =   EEPROM.read(10);     // Kesselabkuehltemperatur 90°C
  Kesseltempkorrektur =       EEPROM.read(11);     // Temperaturkorrektur Sensor Kessel 1°C
  Puffertempkorrektur =       EEPROM.read(12);     // Temperaturkorrektur Sensoren Pufferspeicher 0°C
  WBW_Temp_max =              EEPROM.read(13);     // Brauchwassermaximaltemperatur 60°C
  WBW_Temp_min =              EEPROM.read(14);     // Brauchwassermidensttemperatur 40°C
  Legionellentemp_min =       EEPROM.read(15);     // Legionellentemperatur 70°C
  hyst_WBW =                  EEPROM.read(16);     // Hysterese Brauchwasser 5°C
  last_type_zuheizung =       EEPROM.read(17);     // status Zuheizung - 1 elektro aktiviert - 2 Gas aktiviert - 3 keine aktiviert
  last_type_legionellen =     EEPROM.read(30);     // status letzte Legionellenbehandlung - 1 wird ausgeführt - 2 abgeschlossen - 3 abgebrochen - 4 konnte nicht gestartet werden
  Serial.println(F("EEPROM eingelesen"));
}

void time2Serial()
{
  static byte lastSecond = 60;
  if (lastSecond != now.second())
  {
    lastSecond = now.second();
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
  }
}

// -- Nextion Input
void checkNextion()
{
  // Noch zu ändern! - dfd muss chararray werden
  if (nextion.available())
  { dfd += char (nextion.read()); }
  if (dfd.endsWith(endChar))
  {
    Serial.print(dfd);
    Serial.println(F(" Fehler"));
    dfd = "";
  }
  nextionPage();
}

void brauchwasserLadung()
{
  // -- Pumpe Brauchwasserladung
  if ((((HDW_u <= WBW_Temp_min) && ((HDW_o + hyst_WBW) < P1o_S) && (HDW_o > HDW_u)) || (H0_S + Kesseltempkorrektur) >= Kesselabkuehltemperatur) ||  btn_state_T_P == aktiv || btn_state_hand_BWLP == aktiv)
  {
    digitalWrite(T_P, ein);
    //Serial.println("Brauchwasserladung ein");
  }
  if (((now.dayOfTheWeek() == Ein_Tag) && (now.hour() + sommerzeit() == Ein_Stunde) && (now.minute() == Ein_Minute)) && (P1o_S >= Legionellentemp_min))
  {
    digitalWrite(T_P, ein);
    btn_state_legio = 1;
    last_type_legionellen = 1;
    EEPROM.update(30, last_type_legionellen);
    Serial.println(F("Legionellenbehandlung ein"));
  }
  if ((now.dayOfTheWeek() == Ein_Tag) && (now.hour() + sommerzeit() == Ein_Stunde) && (now.minute() == Ein_Minute) && (P1o_S < Legionellentemp_min))
  {
    last_type_legionellen = 4;
    btn_state_legio = 0;
    EEPROM.update(30, 3);
    Serial.println(F("Legionellenbehandlung konnte nicht gestartet werden - Puffertemperatur zu gering"));
  }
  if ((((((HDW_o + hyst_WBW) > P1o_S) || (HDW_u >= WBW_Temp_max)) && (H0_S + Kesseltempkorrektur) < Kesselabkuehltemperatur) && btn_state_hand_BWLP == inaktiv) && btn_state_legio == inaktiv)
  {
    digitalWrite(T_P, aus);
    btn_state_T_P = 0;
    // Serial.println("Brauchwasserladung aus");
  }
  if ((HDW_u >= Legionellentemp_min) && (btn_state_legio == aktiv))
  {
    digitalWrite(T_P, aus);
    last_type_legionellen = 2;
    EEPROM.update(30, last_type_legionellen);
    Serial.println(F("Legionellenbehandlung abgeschlossen"));
    btn_state_legio = inaktiv;
  }
  if ((btn_state_legio == 1) && (HDW_u >= P1o_S))
  {
    digitalWrite(T_P, aus);
    btn_state_legio = 0;
    last_type_legionellen = 3;
    EEPROM.update(30, 4);
    Serial.println(F("Legionellenbehandlung abgebrochen"));
  }
}

void zirkulationsPumpe()
{
  // -- Pumpe Zirkulation Brauchwasser
  if ((btn_state_Z_P == aktiv) || (btn_state_hand_ZPBW == aktiv))
  { digitalWrite(Z_P, ein); }
  else
  { digitalWrite(Z_P, aus); }
}

void nextionPage()
{
  // -- Nextion pagestate
  if (dfd != "")
  {
    nextion.print(dfd);
    nextEnd();
  }
  if (dfd == "page 0")
  { pageType = 0; }
  else if (dfd == "page 1")
  { pageType = 1; }
  else if (dfd == "page 2")
  {
    pageType = 2;
    nextPrintValueWithEnd("n0.val=", now.day());
    nextPrintValueWithEnd("n1.val=", now.month());
    nextPrintValueWithEnd("n2.val=", now.year());
    nextPrintValueWithEnd("n3.val=", now.hour());
    nextPrintValueWithEnd("n4.val=", now.minute());
    nextPrintValueWithEnd("n5.val=", now.second());
  }
  else if (dfd == "page 3")
  { pageType = 3; }
  else if (dfd == "page 4")
  { pageType = 4; }
  else if (dfd == "page 5")
  { pageType = 5; }
  else if (dfd == "page 6")
  { pageType = 6; }
  else if (dfd == "page 7")
  {
    pageType = 7;
    nextPrintValueWithEnd("n0.val=", Puffermindesttemp);
    nextPrintValueWithEnd("n1.val=", Pufferumladetemp);
    nextPrintValueWithEnd("n2.val=", Ladepumpestarttemp);
    nextPrintValueWithEnd("n3.val=", Ladepumpestoptemp);
    nextPrintValueWithEnd("n4.val=", hyst_Ladepumpe);
    nextPrintValueWithEnd("n5.val=", Kesselabkuehltemperatur);
    nextPrintValueWithEnd("n6.val=", Kesseltempkorrektur);
    nextPrintValueWithEnd("n7.val=", Puffertempkorrektur);
    nextPrintValueWithEnd("n8.val=", WBW_Temp_max);
    nextPrintValueWithEnd("n9.val=", WBW_Temp_min);
    nextPrintValueWithEnd("n10.val=", Legionellentemp_min);
    nextPrintValueWithEnd("n11.val=", hyst_WBW);
  }
  else if (dfd == "page 8")
  {
    pageType = 8;
    nextPrintValueWithEnd("select0.val=", Ein_Tag);
    nextPrintValueWithEnd("select1.val=", Ein_Stunde);
    nextPrintValueWithEnd("select2.val=", Ein_Minute);
  }
  else if (dfd == "page 9")
  { pageType = 9; }
  Serial.print(F("pagestate "));
  Serial.println(pageType);
  //************
  // -- page 0 Hauptseite
  if (pageType == 0)
  {
    //Serial.println("Seite 0 wird aktualisiert");
    if ((P1m_S < Puffermindesttemp) && (millis() % (2000 + 2000) < 2000))
    {
      nextion.print(F("null.zerot18.txt=\""));
      nextion.print(F("BITTE ANLEGEN"));
      nextion.write('"');
      nextEnd();
    }
    else if (P1m_S < Puffermindesttemp)
    {
      nextion.print(F("null.zerot18.txt=\""));
      nextion.print(' ');
      nextion.write('"');
      nextEnd();
    }
    if ((digitalRead(OUT_A) == 0) && (millis() % (1000 + 1000) < 1000)) // wenn Pufferspeicherladepumpe ein
    {
      nextion.print(F("null.zerot4.pco=2016")); // + endChar);
      nextEnd();
    }
    else if (digitalRead(OUT_A) == 0)
    {
      nextion.print(F("null.zerot4.pco=0")); // + endChar);
      nextEnd();
    }
    if (digitalRead(OUT_A) == 1)  // wenn Pufferspeicherladepumpe aus
    {
      nextion.print(F("null.zerot4.pco=63488")); // + endChar);
      nextEnd();
    }
    if ((digitalRead(OUT_B) == 0) || (digitalRead(OUT_C) == 0))
    {
      //nextion.print("null.zerot19.pco=1024" + endChar);
      nextion.print(F("null.zerot19.txt=\""));
      nextion.print(F("Zuheizung aktiv"));
      nextion.write('"');
      nextEnd();
    }
    if (((digitalRead(OUT_B) == 1) && (digitalRead(OUT_C) == 1)) && ((last_type_zuheizung == 1) || (last_type_zuheizung == 2)))
    {
      nextion.print(F("null.zerot19.pco=64512")); // + endChar);
      nextEnd();
      nextion.print(F("null.zerot19.txt=\""));
      nextion.print(F("Zuheizung bereit"));
      nextion.write('"');
      nextEnd();
    }
    if ((last_type_zuheizung == 0) && (millis() % (2000 + 2000) < 2000))
    {
      nextion.print(F("null.zerot19.pco=63488")); // + endChar);
      nextEnd();
      nextion.print(F("null.zerot19.txt=\""));
      nextion.print(F("ACHTUNG KEIN FROSTSCHUTZ"));
      nextion.write('"');
      nextEnd();
    }
    else if (last_type_zuheizung == 0)
    {
      nextion.print(F("null.zerot19.txt=\""));
      nextion.print(' ');
      nextion.write('"');
      nextEnd();
    }
    if (last_type_zuheizung == 1)
    {
      nextion.print(F("null.zerot17.txt=\""));
      nextion.print(F("Zuheizung elektro ausgewaehlt"));
      nextion.write('"');
      nextEnd();
    }
    if (last_type_zuheizung == 2)
    {
      nextion.print(F("null.zerot17.txt=\""));
      nextion.print(F("Zuheizung Gas ausgewaehlt"));
      nextion.write('"');
      nextEnd();
    }
    if (last_type_zuheizung == 0)
    {
      nextion.print(F("null.zerot17.txt=\""));
      nextion.print(F("keine Zuheizung ausgewaehlt"));
      nextion.write('"');
      nextEnd();
    }
    nextion.print(digitalRead(OUT_C) == ein ? F("null.zerot38.pco=2016") : F("null.zerot38.pco=63488"));
    nextEnd();
    nextion.print(digitalRead(OUT_D) == ein ? F("null.zerot7.pco=2016") : F("null.zerot7.pco=63488"));
    nextEnd();
    if (digitalRead(Z_P) == ein)
    {
      if (millis() % (1000 + 1000) < 1000)
      { nextion.print(F("null.zerot6.pco=2016")); }
      else
      { nextion.print(F("null.zerot6.pco=0")); }
    }
    else
    { nextion.print(F("null.zerot6.pco=63488")); }
    nextEnd();
    if (digitalRead(T_P) == ein)
    {
      if (millis() % (1000 + 1000) < 1000)
      { nextion.print(F("null.zerot5.pco=2016")); }
      else
      { nextion.print(F("null.zerot5.pco=0")); }
    }
    else
    { nextion.print(F("null.zerot5.pco=63488")); }
    nextEnd();
    if ((digitalRead(OUT_E) == 0) && (millis() % (1000 + 1000) < 1000))
    {
      nextion.print(F("null.zerot14.pco=2016"));
      nextEnd();
    }
    else if (digitalRead(OUT_E) == 0)
    {
      nextion.print(F("null.zerot14.pco=0"));
      nextEnd();
    }
    if (digitalRead(OUT_E) == 1)
    {
      nextion.print(F("null.zerot14.pco=63488"));
      nextEnd();
    }
    // -- Nextion page update
    // -- Temperaturanzeige
    if ((aussentemp) < (-100))
    {
      nextion.print(F("null.zerot11.txt=\""));
      nextion.print("--");
      nextion.write('"');
      nextEnd();
    }
    else
    {
      nextion.print(F("null.zerot11.txt=\""));
      nextion.print(aussentemp);
      nextion.write('"');
      nextEnd();
    }
    if ((H0_S) < (-100))
    {
      nextion.print(F("null.H0.txt=\""));
      nextion.print("--");
      nextion.write('"');
      nextEnd();
    }
    else
    {
      nextion.print(F("null.H0.txt=\""));
      nextion.print(H0_S + Kesseltempkorrektur);
      nextion.write('"');
      nextEnd();
    }
    if ((HDW_o) < (-100))
    {
      nextion.print(F("null.HDWo.txt=\""));
      nextion.print("--");
      nextion.write('"');
      nextEnd();
    }
    else
    {
      nextion.print(F("null.HDWo.txt=\""));
      nextion.print(HDW_o);
      nextion.write('"');
      nextEnd();
    }
    if ((HDW_u) < (-100))
    {
      nextion.print(F("null.HDWu.txt=\""));
      nextion.print("--");
      nextion.write('"');
      nextEnd();
    }
    else
    {
      nextion.print(F("null.HDWu.txt=\""));
      nextion.print(HDW_u);
      nextion.write('"');
      nextEnd();
    }
    if ((P1o_S) < (-100))
    {
      nextion.print(F("null.P1o.txt=\""));
      nextion.print("--");
      nextion.write('"');
      nextEnd();
    }
    else
    {
      nextion.print(F("null.P1o.txt=\""));
      nextion.print(P1o_S);
      nextion.write('"');
      nextEnd();
    }
    if ((P1m_S) < (-100))
    {
      nextion.print(F("null.P1m.txt=\""));
      nextion.print("--");
      nextion.write('"');
      nextEnd();
    }
    else
    {
      nextion.print(F("null.P1m.txt=\""));
      nextion.print(P1m_S);
      nextion.write('"');
      nextEnd();
    }
    if ((P1u_S) < (-100))
    {
      nextion.print(F("null.P1u.txt=\""));
      nextion.print("--");
      nextion.write('"');
      nextEnd();
    }
    else
    {
      nextion.print(F("null.P1u.txt=\""));
      nextion.print(P1u_S);
      nextion.write('"');
      nextEnd();
    }
    if ((P2o_S) < (-100))
    {
      nextion.print(F("null.P2o.txt=\""));
      nextion.print("--");
      nextion.write('"');
      nextEnd();
    }
    else
    {
      nextion.print(F("null.P2o.txt=\""));
      nextion.print(P2o_S);
      nextion.write('"');
      nextEnd();
    }
    if ((P2m_S) < (-100))
    {
      nextion.print(F("null.P2m.txt=\""));
      nextion.print("--");
      nextion.write('"');
      nextEnd();
    }
    else
    {
      nextion.print(F("null.P2m.txt=\""));
      nextion.print(P2m_S);
      nextion.write('"');
      nextEnd();
    }
    if ((P2u_S) < (-100))
    {
      nextion.print(F("null.P2u.txt=\""));
      nextion.print("--");
      nextion.write('"');
      nextEnd();
    }
    else
    {
      nextion.print(F("null.P2u.txt=\""));
      nextion.print(P2u_S);
      nextion.write('"');
      nextEnd();
    }
    if ((P3o_S) < (-100))
    {
      nextion.print(F("null.P3o.txt=\""));
      nextion.print("--");
      nextion.write('"');
      nextEnd();
    }
    else
    {
      nextion.print(F("null.P3o.txt=\""));
      nextion.print(P3o_S);
      nextion.write('"');
      nextEnd();
    }
    if ((P3m_S) < (-100))
    {
      nextion.print(F("null.P3m.txt=\""));
      nextion.print("--");
      nextion.write('"');
      nextEnd();
    }
    else
    {
      nextion.print(F("null.P3m.txt=\""));
      nextion.print(P3m_S);
      nextion.write('"');
      nextEnd();
    }
    if ((P3u_S) < (-100))
    {
      nextion.print(F("null.P3u.txt=\""));
      nextion.print("--");
      nextion.write('"');
      nextEnd();
    }
    else
    {
      nextion.print(F("null.P3u.txt=\""));
      nextion.print(P3u_S);
      nextion.write('"');
      nextEnd();
    }
    if (millis() - lastRefresh >= refreshPause)
    {
      nextion.print(F("null.zerot9.txt=\""));
      nextion.print(daysOfTheWeek[now.dayOfTheWeek()]);
      nextion.print(' ');
      if (now.day() < 10)
      {
        nextion.print(0);
      }
      nextion.print(now.day(), DEC);
      nextion.print('.');
      if (now.month() < 10)
      {
        nextion.print(0);
      }
      nextion.print(now.month(), DEC);
      nextion.print('.');
      nextion.print(now.year(), DEC);
      nextion.write('"');
      nextEnd();
      nextion.print(F("null.zerozeit.txt=\""));
      if (now.hour() + sommerzeit() < 10)
      { nextion.print(0); }
      nextion.print(now.hour() + sommerzeit());                  // Stunden anzeigen
      nextion.print(':');
      if (now.minute() < 10)
      {
        nextion.print(0);
      }
      nextion.print(now.minute());
      nextion.write('"');
      nextEnd();
      lastRefresh = millis();
      //Sommer = sommerzeit();
    }
  }
  // -- page 2 Uhrzeit
  if (pageType == 2)
  {
    //Serial.println("Seite 2 wird aktualisiert");
    if (dfd.substring((dfd.length() - 1), dfd.length()) == "?")
    {
      String command = dfd.substring(5, 9);
      String value = dfd.substring(9, dfd.length() - 1);
      Serial.println(command + " : " + value);
      if (command == "DATT")
      {
        Datum_Tag_set = value.toInt();
        //Serial.print("Tag: ");
        Serial.print(Datum_Tag_set);
        Serial.print('.');
      }
      else if (command == "DATM")
      {
        Datum_Monat_set = value.toInt();
        //Serial.print("Monat: ");
        Serial.print(Datum_Monat_set);
        Serial.print('.');
      }
      else if (command == "DATJ")
      {
        Datum_Jahr_set = value.toInt();
        //Serial.print("Jahr: ");
        Serial.print(Datum_Jahr_set);
        Serial.print(F(" - "));
      }
      else if (command == "ZEIS")
      {
        Uhr_h_set = value.toInt();
        //Serial.print("Stunde: ");
        Serial.print(Uhr_h_set);
        Serial.print(":");
      }
      else if (command == "ZEIM")
      {
        Uhr_m_set = value.toInt();
        //Serial.print("Stunde: ");
        Serial.print(Uhr_m_set);
        Serial.print(":");
      }
      else if (command == "ZEIX")
      {
        Uhr_s_set = value.toInt();
        //Serial.print("Sekunde: ");
        Serial.println(Uhr_s_set);
        dfd = "";
      }
      RTC.adjust(DateTime(Datum_Jahr_set, Datum_Monat_set, Datum_Tag_set, Uhr_h_set, Uhr_m_set, Uhr_s_set));
      Serial.println(F("Uhrzeit eingestellt"));
    }
  }
  // -- page 3 Zuheizung
  if (pageType == 3)
  {
    //Serial.println("Seite 3 wird aktualisiert");
    if (last_type_zuheizung == 1)
    {
      nextion.print(F("zuheizung.t3.txt=\""));
      nextion.print(F("Zuheizung elektro ausgewaehlt"));
      nextion.write('"');
      nextEnd();
    }
    else
    {
      nextion.print(F("zuheizung.t3.txt=\""));
      nextion.print(F("Zuheizung elektro aktivieren"));
      nextion.write('"');
      nextEnd();
    }
    if (last_type_zuheizung == 2)
    {
      nextion.print(F("zuheizung.t1.txt=\""));
      nextion.print(F("Zuheizung Gasherme ausgewaehlt"));
      nextion.write('"');
      nextEnd();
    }
    else
    {
      nextion.print(F("zuheizung.t1.txt=\""));
      nextion.print(F("Zuheizung Gastherme aktivieren"));
      nextion.write('"');
      nextEnd();
    }
  }
  // -- page 4 Handbetrieb
  if (pageType == 4)
  {
    //Serial.println("Seite 4 wird aktualisiert");
    nextion.print(btn_state_hand_PLP ? F("hand.t0.pco=2016") : F("hand.t0.pco=63488"));
    nextEnd();
    nextion.print(btn_state_hand_BWLP ? F("hand.t1.pco=2016") : F("hand.t1.pco=63488"));
    nextEnd();
    nextion.print(btn_state_hand_ZPBW ? F("hand.t2.pco=2016") : F("hand.t2.pco=63488"));
    nextEnd();
    nextion.print(btn_state_hand_ZPSU ? F("hand.t3.pco=2016") : F("hand.t3.pco=63488"));
    nextEnd();
    nextion.print(btn_state_hand_WV ? F("hand.t4.pco=2016") : F("hand.t4.pco=63488"));
    nextEnd();
  }
  // -- page 5 Brauchwasser
  if (pageType == 5)
  {
    //Serial.println("Seite 5 wird aktualisiert");
    nextion.print(F("warmwasser.t0.txt=\""));
    nextion.print(btn_state_T_P ? F("Brauchwasserladung aktiviert") : F("1 x manuelle Brauchwasserladung"));
    nextion.write('"');
    nextEnd();
    nextion.print(F("warmwasser.t1.txt=\""));
    nextion.print(btn_state_Z_P ? F("Zirkulation aktiviert") : F("Zirkulationspumpe  5 min. aktivieren"));
    nextion.write('"');
    nextEnd();
    nextion.print(F("warmwasser.t3.txt=\""));
    switch (last_type_legionellen)
    {
      case 1:
        nextion.print(F("Legionellenbehandlung wurde aktiviert"));
        break;
      case 2:
        nextion.print(F("Legionellenbehandlung abgeschlossen"));
        break;
      case 3:
        nextion.print(F("konnte nicht gestartet werden Puffertemp zu gering"));
        break;
      case 4:
        nextion.print(F("Legionellenbehandlung abgebrochen"));
        break;
    }
    nextion.write('"');
    nextEnd();
  }
  // -- page 6 temps
  if (pageType == 6)
  {
    //Serial.println("Seite 6 wird aktualisiert");
    nextion.print(F("temps.H1_S.txt=\""));
    nextion.print(aussentemp);
    nextion.write('"');
    nextEnd();
    nextion.print(F("temps.H0_S.txt=\""));
    nextion.print(H0_S);
    nextion.write('"');
    nextEnd();
    nextion.print(F("temps.HDW_o.txt=\""));
    nextion.print(HDW_o);
    nextion.write('"');
    nextEnd();
    nextion.print(F("temps.HDW_u.txt=\""));
    nextion.print(HDW_u);
    nextion.write('"');
    nextEnd();
    nextion.print(F("temps.P1o_S.txt=\""));
    nextion.print(P1o_S);
    nextion.write('"');
    nextEnd();
    nextion.print(F("temps.P1m_S.txt=\""));
    nextion.print(P1m_S);
    nextion.write('"');
    nextEnd();
    nextion.print(F("temps.P1u_S.txt=\""));
    nextion.print(P1u_S);
    nextion.write('"');
    nextEnd();
    nextion.print(F("temps.P2o_S.txt=\""));
    nextion.print(P2o_S);
    nextion.write('"');
    nextEnd();
    nextion.print(F("temps.P2m_S.txt=\""));
    nextion.print(P2m_S);
    nextion.write('"');
    nextEnd();
    nextion.print(F("temps.P2u_S.txt=\""));
    nextion.print(P2u_S);
    nextion.write('"');
    nextEnd();
    nextion.print(F("temps.P3o_S.txt=\""));
    nextion.print(P3o_S);
    nextion.write('"');
    nextEnd();
    nextion.print(F("temps.P3m_S.txt=\""));
    nextion.print(P3m_S);
    nextion.write('"');
    nextEnd();
    nextion.print(F("temps.P3u_S.txt=\""));
    nextion.print(P3u_S);
    nextion.write('"');
    nextEnd();
  }
  // -- page 7 systemwerte
  if (pageType == 7)
  {
    //Serial.println("Seite 7 wird aktualisiert");
    if (dfd.substring((dfd.length() - 1), dfd.length()) == "?")
    {
      String command = dfd.substring(5, 9);
      String value = dfd.substring(9, dfd.length() - 1);
      Serial.println(command + " : " + value);
      dfd = "";
      if (command == "TEMA")
      {
        Puffermindesttemp = value.toInt();
        Serial.print(F("Puffermindesttemp: "));
        Serial.print(Puffermindesttemp);
        EEPROM.update(5, Puffermindesttemp);
        Serial.print(F(" - "));
        Serial.println(EEPROM.read(5));
        dfd = "";
      }
      if (command == "TEMB")
      {
        Pufferumladetemp = value.toInt();
        Serial.print(F("Pufferumladetemp: "));
        Serial.print(Pufferumladetemp);
        EEPROM.update(6, Pufferumladetemp);
        Serial.print(F(" - "));
        Serial.println(EEPROM.read(6));
        dfd = "";
      }
      if (command == "TEMC")
      {
        Ladepumpestarttemp = value.toInt();
        Serial.print(F("Ladepumpestarttemp: "));
        Serial.print(Ladepumpestarttemp);
        EEPROM.update(7, Ladepumpestarttemp);
        Serial.print(F(" - "));
        Serial.println(EEPROM.read(7));
        dfd = "";
      }
      if (command == "TEMD")
      {
        Ladepumpestoptemp = value.toInt();
        Serial.print(F("Ladepumpestoptemp: "));
        Serial.println(Ladepumpestoptemp);
        EEPROM.update(8, Ladepumpestoptemp);
        Serial.print(F(" - "));
        Serial.println(EEPROM.read(8));
        dfd = "";
      }
      if (command == "TEME")
      {
        hyst_Ladepumpe = value.toInt();
        Serial.print(F("hyst_Ladepumpe: "));
        Serial.println(hyst_Ladepumpe);
        EEPROM.update(9, hyst_Ladepumpe);
        Serial.print(F(" - "));
        Serial.println(EEPROM.read(9));
        dfd = "";
      }
      if (command == "TEMF")
      {
        Kesselabkuehltemperatur = value.toInt();
        Serial.print(F("Kesselabkuehltemperatur: "));
        Serial.println(Kesselabkuehltemperatur);
        EEPROM.update(10, Kesselabkuehltemperatur);
        Serial.print(F(" - "));
        Serial.println(EEPROM.read(10));
        dfd = "";
      }
      if (command == "TEMG")
      {
        Kesseltempkorrektur = value.toInt();
        Serial.print(F("Kesseltempkorrektur: "));
        Serial.println(Kesseltempkorrektur);
        EEPROM.update(11, Kesseltempkorrektur);
        Serial.print(F(" - "));
        Serial.println(EEPROM.read(11));
        dfd = "";
      }
      if (command == "TEMH")
      {
        Puffertempkorrektur = value.toInt();
        Serial.print(F("Puffertempkorrektur: "));
        Serial.println(Puffertempkorrektur);
        EEPROM.update(12, Puffertempkorrektur);
        Serial.print(F(" - "));
        Serial.println(EEPROM.read(12));
        dfd = "";
      }
      if (command == "TEMI")
      {
        WBW_Temp_max = value.toInt();
        Serial.print(F("WBW_Temp_max: "));
        Serial.println(WBW_Temp_max);
        EEPROM.update(13, WBW_Temp_max);
        Serial.print(F(" - "));
        Serial.println(EEPROM.read(13));
        dfd = "";
      }
      if (command == "TEMJ")
      {
        WBW_Temp_min = value.toInt();
        Serial.print(F("WBW_Temp_min: "));
        Serial.println(WBW_Temp_min);
        EEPROM.update(14, WBW_Temp_min);
        Serial.print(F(" - "));
        Serial.println(EEPROM.read(14));
        dfd = "";
      }
      if (command == "TEMK")
      {
        Legionellentemp_min = value.toInt();
        Serial.print(F("Legionellentemp_min: "));
        Serial.println(Legionellentemp_min);
        EEPROM.update(15, Legionellentemp_min);
        Serial.print(F(" - "));
        Serial.println(EEPROM.read(15));
        dfd = "";
      }
      if (command == "TEML")
      {
        hyst_WBW = value.toInt();
        Serial.print(F("hyst_WBW: "));
        Serial.println(hyst_WBW);
        EEPROM.update(16, hyst_WBW);
        Serial.print(F(" - "));
        Serial.println(EEPROM.read(16));
        dfd = "";
      }
    }
  }
  // -- page 8 Legionellenbehandlung
  if (pageType == 8)
  {
    //Serial.println("Seite 8 wird aktualisiert");
    if (dfd.substring((dfd.length() - 1), dfd.length()) == "?")
    {
      String command = dfd.substring(5, 9);
      String value = dfd.substring(9, dfd.length() - 1);
      Serial.println(command + " : " + value);
      dfd = "";
      if (command == "LEGD")
      {
        Ein_Tag = value.toInt();
        Serial.print(F("Ein_Tag: "));
        Serial.print(Ein_Tag);
        EEPROM.update(0, Ein_Tag);
        Serial.print(F(" - "));
        Serial.println(EEPROM.read(0));
        dfd = "";
      }
      if (command == "LEGS")
      {
        Ein_Stunde = value.toInt();
        Serial.print(F("Ein_Stunde: "));
        Serial.print(Ein_Stunde);
        EEPROM.update(1, Ein_Stunde);
        Serial.print(F(" - "));
        Serial.println(EEPROM.read(1));
        dfd = "";
      }
      if (command == "LEGM")
      {
        Ein_Minute = value.toInt();
        Serial.print(F("Ein_Minute: "));
        Serial.print(Ein_Minute);
        EEPROM.update(2, Ein_Minute);
        Serial.print(F(" - "));
        Serial.println(EEPROM.read(2));
        dfd = "";
      }
    }
    // -- buttonstate
    // -- Brauchwasserladung
    if (dfd == "T_P")
    {
      btn_state_T_P = 1;
      Serial.print(F("btn_state_T_P "));
      Serial.println(btn_state_T_P);
      dfd = "";
    }
    // -- Zirkulationspumpe
    if (dfd == "Z_P")
    {
      btn_state_Z_P = 1;
      btn_state_hand_ZPBW = 1;
      Serial.print(F("btn_state_Z_P "));
      Serial.print(btn_state_Z_P);
      //Serial.println(" Zirkulationspumpe Brauchwasser ein");
      dfd = "";
    }
    // -- hand Legio
    if (dfd == "hand_legio")
    {
      btn_state_legio = 1;
      Serial.print(F("btn_state_legio "));
      Serial.println(btn_state_legio);
      dfd = "";
    }
    // -- hand Pufferladepumpe
    if (dfd == "hand_PLP" && (!btn_state_hand_PLP))
    {
      btn_state_hand_PLP = 1;
      Serial.print(F("btn_state_hand_PLP "));
      Serial.println(btn_state_hand_PLP);
      dfd = "";
    }
    else if (dfd == "hand_PLP" && (btn_state_hand_PLP))
    {
      btn_state_hand_PLP = 0;
      Serial.print(F("btn_state_hand_PLP "));
      Serial.println(btn_state_hand_PLP);
      dfd = "";
    }
    // -- hand Brauchwasserladepumpe
    if (dfd == "hand_BWLP" && (!btn_state_hand_BWLP))
    {
      btn_state_hand_BWLP = 1;
      Serial.print(F("btn_state_hand_BWLP "));
      Serial.println(btn_state_hand_BWLP);
      dfd = "";
    }
    else if (dfd == "hand_BWLP" && (btn_state_hand_BWLP))
    {
      btn_state_hand_BWLP = 0;
      Serial.print(F("btn_state_hand_BWLP "));
      Serial.println(btn_state_hand_BWLP);
      dfd = "";
    }
    // -- hand Zirkulationspumpe Brauchwasser
    if (dfd == "hand_ZPBW" && (!btn_state_hand_ZPBW))
    {
      btn_state_hand_ZPBW = 1;
      Serial.print(F("btn_state_hand_ZPBW "));
      Serial.println(btn_state_hand_ZPBW);
      dfd = "";
    }
    else if (dfd == "hand_ZPBW" && (btn_state_hand_ZPBW))
    {
      btn_state_hand_ZPBW = 0;
      Serial.print(F("btn_state_hand_ZPBW "));
      Serial.println(btn_state_hand_ZPBW);
      dfd = "";
    }
    // -- hand Zirkulationspumpe Speicherumladung
    if (dfd == "hand_ZPSU" && (!btn_state_hand_ZPSU))
    {
      btn_state_hand_ZPSU = 1;
      Serial.print(F("btn_state_hand_ZPSU "));
      Serial.println(btn_state_hand_ZPSU);
      dfd = "";
    }
    else if (dfd == "hand_ZPSU" && (btn_state_hand_ZPSU))
    {
      btn_state_hand_ZPSU = 0;
      Serial.print(F("btn_state_hand_ZPSU "));
      Serial.println(btn_state_hand_ZPSU);
      dfd = "";
    }
    // -- hand 3 Wegeventil
    if (dfd == "hand_WV" && (!btn_state_hand_WV))
    {
      btn_state_hand_WV = 1;
      Serial.print(F("btn_state_hand_WV "));
      Serial.println(btn_state_hand_WV);
      dfd = "";
    }
    else if (dfd == "hand_WV" && (btn_state_hand_WV))
    {
      btn_state_hand_WV = 0;
      Serial.print(F("btn_state_hand_WV "));
      Serial.println(btn_state_hand_WV);
      dfd = "";
    }
    // -- Zuheizung
    if (dfd == "zuheizung_gas")
    {
      EEPROM.update(17, 2);
      dfd = "";
    }
    // -- Zuheizung elektro
    if (dfd == "zuheizung_elektro")
    {
      EEPROM.update(17, 1);
      dfd = "";
    }
    // -- Zuheizung aus
    if (dfd == "zuheizung_aus")
    {
      EEPROM.update(17, 0);
      dfd = "";
    }
    // -- Relais ein/aus
    zirkulationsPumpe();
    brauchwasserLadung();
    // -- Pumpe Pufferspeicherladung
    if (((((H0_S + Kesseltempkorrektur) >= Ladepumpestarttemp) && ((H0_S + Kesseltempkorrektur) > ((P3u_S + Puffertempkorrektur) + hyst_Ladepumpe))) || ((H0_S + Kesseltempkorrektur) >= Kesselabkuehltemperatur)) || btn_state_hand_PLP == 1)
    {
      digitalWrite(OUT_A, ein);
      //Serial.println("Pufferladepumpe ein");
    }
    if (((H0_S + Kesseltempkorrektur) <= Ladepumpestoptemp) || ((H0_S + Kesseltempkorrektur) < ((P3u_S + Puffertempkorrektur) + hyst_Ladepumpe)))
      if (btn_state_hand_PLP == ein)
      {
        digitalWrite(OUT_A, aus);
        //Serial.println("Pufferladepumpe aus");
      }
    // -- Zuheizung Gas ein
    if ((P1o_S < Puffermindesttemp) && ((H0_S + Kesseltempkorrektur) < Ladepumpestarttemp) && (last_type_zuheizung == 2))
    {
      digitalWrite(OUT_C, ein);
      digitalWrite(OUT_D, ein);
    }
    if (((H0_S + Kesseltempkorrektur) > Ladepumpestoptemp) || (last_type_zuheizung == 0) || (last_type_zuheizung == 1) || (P1o_S > Puffermindesttemp))
    {
      digitalWrite(OUT_C, aus);
      digitalWrite(OUT_D, aus);
    }
    // -- Zuheizung elektro ein
    if ((P1o_S < Puffermindesttemp) && ((H0_S + Kesseltempkorrektur) < Ladepumpestarttemp) && (last_type_zuheizung == 1))
    {
      digitalWrite(OUT_B, ein);
      //Serial.println ("Zuheizung elektro ein");
    }
    if (((H0_S + Kesseltempkorrektur) > Ladepumpestoptemp) || (last_type_zuheizung == 0) || (last_type_zuheizung == 2) || (P1o_S > Puffermindesttemp))
    {
      digitalWrite(OUT_B, ein);
      //Serial.println ("Zuheizung elektro aus");
    }
    // -- Pumpe Zirkulation Speicherumladung
    if ((((P1o_S < Pufferumladetemp) && (P2o_S > P1o_S)) && (digitalRead(OUT_A) == ein)) || btn_state_hand_ZPSU == aktiv)
    {
      digitalWrite(OUT_E, ein);
      //Serial.println ("Pumpe Speicherumladung ein");
    }
    if (((P2o_S <= P1o_S) || (digitalRead(OUT_A) == 0)) && btn_state_hand_ZPSU == 0)
    {
      digitalWrite(OUT_E, aus);
      //Serial.println ("Pumpe Speicherumladung aus");
    }
    // -- 3 Wegeventil
    if ((digitalRead(OUT_C) == ein) || (btn_state_hand_WV == aktiv))
    { digitalWrite(OUT_D, ein); }
    else
    { digitalWrite(OUT_D, aus); }
  }
  dfd = "";
}

compiliert bei mit: