lambda: |-

      // Map weather states to MDI characters.
      std::map<std::string, std::string> weather_icon_map
        {
          {"cloudy", "\U000F0590"},
          {"cloudy-alert", "\U000F0F2F"},
          {"cloudy-arrow-right", "\U000F0E6E"},
          {"fog", "\U000F0591"},
          {"hail", "\U000F0592"},
          {"hazy", "\U000F0F30"},
          {"hurricane", "\U000F0898"},
          {"lightning", "\U000F0593"},
          {"lightning-rainy", "\U000F067E"},
          {"clear-night", "\U000F0594"},
          {"night-partly-cloudy", "\U000F0F31"},
          {"partlycloudy", "\U000F0595"},
          {"partly-lightning", "\U000F0F32"},
          {"partly-rainy", "\U000F0F33"},
          {"partly-snowy", "\U000F0F34"},
          {"partly-snowy-rainy", "\U000F0F35"},
          {"pouring", "\U000F0596"},
          {"rainy", "\U000F0597"},
          {"snowy", "\U000F0598"},
          {"snowy-heavy", "\U000F0F36"},
          {"snowy-rainy", "\U000F067F"},
          {"sunny", "\U000F0599"},
          {"sunny-alert", "\U000F0F37"},
          {"sunny-off", "\U000F14E4"},
          {"sunset", "\U000F059A"},
          {"sunset-down", "\U000F059B"},
          {"sunset-up", "\U000F059C"},
          {"tornado", "\U000F0F38"},
          {"windy", "\U000F059D"},
          {"windy-variant", "\U000F059E"},
        };

      // Fill background.
      it.fill(color_bg);

      int wifi_icon_x = 440;
      int wifi_icon_y = 765;

      int battery_icon_x = 40;
      int battery_icon_y = 765;


      if (id(initial_data_received) == false) 
      {

        it.fill(color_white);

        if (id(show_frame_alignment_aid_switch).state)
        {
          it.rectangle(25, 60, 435, 675, color_text);          
        }

        it.printf(240, 390, id(font_small_bold), color_black, TextAlign::TOP_CENTER, "WARTE AUF DATEN...");

        if (!id(auto_deep_sleep_activated).state)
        {
          it.printf(240, 750, id(font_small_book), color_black, TextAlign::TOP_CENTER, "Auto Sleep Mode deaktiviert.");
        }

        char str_time[17];
        char str_date[17];
        time_t currTime = id(homeassistant_time).now().timestamp;
        strftime(str_time, sizeof(str_time), "%H:%M", localtime(&currTime));
        strftime(str_date, sizeof(str_date), "%d.%m.%Y", localtime(&currTime));

        it.printf(240, 770, id(font_small_book), color_black, TextAlign::TOP_CENTER, "Status von %s Uhr am %s", str_time, str_date);

        if(id(wifi_signal_percent).has_state()) 
        {
          if (id(wifi_signal_percent).state >= -50) {
              //Excellent
              it.print(wifi_icon_x, wifi_icon_y, id(font_wifi_bat), color_black, TextAlign::TOP_CENTER, "󰤨");
              ESP_LOGI("WiFi", "Exellent");
          } else if (id(wifi_signal_percent).state  >= 90) {
              //Good
              it.print(wifi_icon_x, wifi_icon_y, id(font_wifi_bat), color_black, TextAlign::TOP_CENTER, "󰤥");
              ESP_LOGI("WiFi", "Good");
          } else if (id(wifi_signal_percent).state  >= 50) {
              //Fair
              it.print(wifi_icon_x, wifi_icon_y, id(font_wifi_bat), color_black, TextAlign::TOP_CENTER, "󰤢");
              ESP_LOGI("WiFi", "Fair");
          } else if (id(wifi_signal_percent).state  >= 30) {
              //Weak
              it.print(wifi_icon_x, wifi_icon_y, id(font_wifi_bat), color_black, TextAlign::TOP_CENTER, "󰤟");
              ESP_LOGI("WiFi", "Weak");
          } else {
              //Unlikely working signal
              it.print(wifi_icon_x, wifi_icon_y, id(font_wifi_bat), color_black, TextAlign::TOP_CENTER, "󰤯");
              ESP_LOGI("WiFi", "Unlikely");
          }
        } else
        {
          //no signal (yet)
          it.print(wifi_icon_x, wifi_icon_y, id(font_wifi_bat), color_black, TextAlign::TOP_CENTER, "󰤮");
          ESP_LOGI("WiFi", "No signal");          
        }

        if(id(battery_percentage).has_state()) 
        {
          if (id(battery_percentage).state >= 95) 
          {
              // 100 %
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_black, TextAlign::TOP_CENTER, "󰁹");
          } else if (id(battery_percentage).state  >= 90) {
              // 90 %
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_black, TextAlign::TOP_CENTER, "󰂂");
          } else if (id(battery_percentage).state  >= 80) {
              // 80%
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_black, TextAlign::TOP_CENTER, "󰂁");
          } else if (id(battery_percentage).state  >= 70) {
              // 70%
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_black, TextAlign::TOP_CENTER, "󰂀");
          } else if (id(battery_percentage).state  >= 60) {
              // 60%
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_black, TextAlign::TOP_CENTER, "󰁿");
          } else if (id(battery_percentage).state  >= 50) {
              // 50%
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_black, TextAlign::TOP_CENTER, "󰁾");
          } else if (id(battery_percentage).state  >= 40) {
              // 40%
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_black, TextAlign::TOP_CENTER, "󰁽");
          } else if (id(battery_percentage).state  >= 30) {
              // 30%
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_black, TextAlign::TOP_CENTER, "󰁼");
          } else if (id(battery_percentage).state  >= 20) {
              // 20%
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_black, TextAlign::TOP_CENTER, "󰁻");
          } else {
              // 10%
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_black, TextAlign::TOP_CENTER, "󰁺");
          }
        }

      } else {

        it.fill(color_black);
        
        if (id(show_frame_alignment_aid_switch).state)
        {
          it.rectangle(25, 60, 435, 675, color_text);        
        }

        // Weather Section
        // it.image(0, 88, id(title_weather)); 
        //it.printf(240, 84, id(font_title), color_text, TextAlign::TOP_CENTER, "WETTER");
        it.printf(100, 34, id(font_mdi_large), color_text, TextAlign::TOP_CENTER, "%s", weather_icon_map[id(weather_condition_now).state.c_str()].c_str());
        it.printf(300, 34, id(font_large_bold), color_text, TextAlign::TOP_CENTER, "%2.0f°C", id(weather_temperature_0).state);
        
        it.filled_rectangle(70, 140, 350, 3,color_text);
        
        it.printf(85, 158, id(font_small_book), color_text, TextAlign::TOP_CENTER, "%s", id(weather_timestamp_0).state.c_str());
        it.printf(85, 182, id(font_mdi_medium), color_text, TextAlign::TOP_CENTER, "%s", weather_icon_map[id(weather_condition_0).state.c_str()].c_str());
        it.printf(85, 230, id(font_small_bold), color_text, TextAlign::TOP_CENTER, "%2.0f°C", id(weather_temperature_0).state);

        it.printf(165, 158, id(font_small_book), color_text, TextAlign::TOP_CENTER, "%s", id(weather_timestamp_1).state.c_str());
        it.printf(165, 182, id(font_mdi_medium), color_text, TextAlign::TOP_CENTER, "%s", weather_icon_map[id(weather_condition_1).state.c_str()].c_str());
        it.printf(165, 230, id(font_small_bold), color_text, TextAlign::TOP_CENTER, "%2.0f°C", id(weather_temperature_1).state);

        it.printf(245, 158, id(font_small_book), color_text, TextAlign::TOP_CENTER, "%s", id(weather_timestamp_2).state.c_str());
        it.printf(245, 182, id(font_mdi_medium), color_text, TextAlign::TOP_CENTER, "%s", weather_icon_map[id(weather_condition_2).state.c_str()].c_str());
        it.printf(245, 230, id(font_small_bold), color_text, TextAlign::TOP_CENTER, "%2.0f°C", id(weather_temperature_2).state);

        it.printf(325, 158, id(font_small_book), color_text, TextAlign::TOP_CENTER, "%s", id(weather_timestamp_3).state.c_str());
        it.printf(325, 182, id(font_mdi_medium), color_text, TextAlign::TOP_CENTER, "%s", weather_icon_map[id(weather_condition_3).state.c_str()].c_str());
        it.printf(325, 230, id(font_small_bold), color_text, TextAlign::TOP_CENTER, "%2.0f°C", id(weather_temperature_3).state);

        it.printf(405, 158, id(font_small_book), color_white, TextAlign::TOP_CENTER, "%s", id(weather_timestamp_4).state.c_str());
        it.printf(405, 182, id(font_mdi_medium), color_white, TextAlign::TOP_CENTER, "%s", weather_icon_map[id(weather_condition_4).state.c_str()].c_str());
        it.printf(405, 230, id(font_small_bold), color_white, TextAlign::TOP_CENTER, "%2.0f°C", id(weather_temperature_4).state);


        it.filled_rectangle(70, 265, 350, 3,color_text);


        it.printf(240, 285, id(font_medium_bold), color_text, TextAlign::TOP_CENTER, "%s", id(wochentag_datum).state.c_str());



        std::string heute = id(termine_heute).state; 
        // Display position and line height
        int xPos1 = 35, yPos1 = 360, lineHeight1 = 30;
        //it.printf(150, 524, id(font_small_bold), color_text, TextAlign::TOP_CENTER, "%s", id(termine_heute).state.c_str());
        it.printf(xPos1, 335, id(font_small_book), color_text, TextAlign::TOP_LEFT, "HEUTE");
        std::string delimiter1 = "%";
        std::size_t curPos1 = 0, commaPos1 = 0;
        while (commaPos1 != std::string::npos) {
          commaPos1 = heute.find(delimiter1, curPos1);
          it.printf(xPos1, yPos1, id(font_small_bold), color_text, TextAlign::TOP_LEFT, "%s", heute.substr(curPos1, commaPos1 - curPos1).c_str()); //print it!
          yPos1 += lineHeight1;
          curPos1 = commaPos1 + delimiter1.size();
        }
                    
        yPos1=yPos1-15;
        it.printf(xPos1, yPos1, id(font_small_book), color_text, TextAlign::TOP_LEFT, "%s", id(morgen).state.c_str());
        yPos1=yPos1+25;

        std::string morgen = id(termine_morgen).state; 
        //std::string delimiter1 = "%";
        std::size_t curPos2 = 0, commaPos2 = 0;
        while (commaPos2 != std::string::npos) {
          commaPos2 = morgen.find(delimiter1, curPos2);
          it.printf(xPos1, yPos1, id(font_small_bold), color_text, TextAlign::TOP_LEFT, "%s", morgen.substr(curPos2, commaPos2 - curPos2).c_str()); //print it!
          yPos1 += lineHeight1;
          curPos2 = commaPos2 + delimiter1.size();
        }


        yPos1=yPos1-15;
        it.printf(xPos1, yPos1, id(font_small_book), color_text, TextAlign::TOP_LEFT, "%s", id(uebermorgen).state.c_str());
        yPos1=yPos1+25;

        std::string uebermorgen = id(termine_uebermorgen).state; 
        //std::string delimiter1 = "%";
        std::size_t curPos3 = 0, commaPos3 = 0;
        while (commaPos3 != std::string::npos) {
          commaPos3 = uebermorgen.find(delimiter1, curPos3);
          it.printf(xPos1, yPos1, id(font_small_bold), color_text, TextAlign::TOP_LEFT, "%s", uebermorgen.substr(curPos3, commaPos3 - curPos3).c_str()); //print it!
          yPos1 += lineHeight1;
          curPos3 = commaPos3 + delimiter1.size();
        }

        yPos1=yPos1-15;
        if (yPos1 <= 710) {
          it.printf(xPos1, yPos1, id(font_small_book), color_text, TextAlign::TOP_LEFT, "%s", id(ueberuebermorgen).state.c_str());
          yPos1=yPos1+25;

          std::string ueberuebermorgen = id(termine_ueberuebermorgen).state; 
          //std::string delimiter1 = "%";
          std::size_t curPos4 = 0, commaPos4 = 0;
          while (commaPos4 != std::string::npos) {
            commaPos4 = ueberuebermorgen.find(delimiter1, curPos4);
            //if (yPos1 < 715) {
              it.printf(xPos1, yPos1, id(font_small_bold), color_text, TextAlign::TOP_LEFT, "%s", ueberuebermorgen.substr(curPos4, commaPos4 - curPos4).c_str()); //print it!
              yPos1 += lineHeight1;
              curPos4 = commaPos4 + delimiter1.size();
            //}
            //else {
            //  yPos1 += lineHeight1;
            //}
          }
        }

        yPos1=yPos1-15;
        if (yPos1 <= 710) {
          it.printf(xPos1, yPos1, id(font_small_book), color_text, TextAlign::TOP_LEFT, "%s", id(ueberueberuebermorgen).state.c_str());
          yPos1=yPos1+25;

          std::string ueberueberuebermorgen = id(termine_ueberueberuebermorgen).state; 
          //std::string delimiter1 = "%";
          std::size_t curPos4 = 0, commaPos4 = 0;
          while (commaPos4 != std::string::npos || yPos1 <= 710) {
            //it.printf(xPos1, yPos1, id(font_small_bold), color_text, TextAlign::TOP_LEFT, "%s", yPos1);
            commaPos4 = ueberueberuebermorgen.find(delimiter1, curPos4);
            //if (yPos1 <= 600) {
              it.printf(xPos1, yPos1, id(font_small_bold), color_text, TextAlign::TOP_LEFT, "%s", ueberueberuebermorgen.substr(curPos4, commaPos4 - curPos4).c_str()); //print it!
              yPos1 += lineHeight1;
              curPos4 = commaPos4 + delimiter1.size();
            //}
            //else {
            //  yPos1 += lineHeight1;
            //}
          }
            
        }

        
        if (!id(auto_deep_sleep_activated).state)
        {
          it.printf(240, 750, id(font_small_book), color_white, TextAlign::TOP_CENTER, "Auto Sleep Mode deaktiviert.");
        }

        // Refresh Timestamp
        // Code by EnsconcE from https://community.home-assistant.io/t/esphome-show-time/348903
        char str_time[17];
        char str_date[17];
        time_t currTime = id(homeassistant_time).now().timestamp;
        strftime(str_time, sizeof(str_time), "%H:%M", localtime(&currTime));
        strftime(str_date, sizeof(str_date), "%d.%m.%Y", localtime(&currTime));
        it.printf(240, 770, id(font_small_book), color_white, TextAlign::TOP_CENTER, "Status von %s Uhr am %s", str_time, str_date);

        if(id(wifi_signal_percent).has_state()) 
        {
          if (id(wifi_signal_percent).state >= -50) {
              //Excellent
              it.print(wifi_icon_x, wifi_icon_y, id(font_wifi_bat), color_white, TextAlign::TOP_CENTER, "󰤨");
              ESP_LOGI("WiFi", "Exellent");
          } else if (id(wifi_signal_percent).state  >= 90) {
              //Good
              it.print(wifi_icon_x, wifi_icon_y, id(font_wifi_bat), color_white, TextAlign::TOP_CENTER, "󰤥");
              ESP_LOGI("WiFi", "Good");
          } else if (id(wifi_signal_percent).state  >= 50) {
              //Fair
              it.print(wifi_icon_x, wifi_icon_y, id(font_wifi_bat), color_white, TextAlign::TOP_CENTER, "󰤢");
              ESP_LOGI("WiFi", "Fair");
          } else if (id(wifi_signal_percent).state  >= 30) {
              //Weak
              it.print(wifi_icon_x, wifi_icon_y, id(font_wifi_bat), color_white, TextAlign::TOP_CENTER, "󰤟");
              ESP_LOGI("WiFi", "Weak");
          } else {
              //Unlikely working signal
              it.print(wifi_icon_x, wifi_icon_y, id(font_wifi_bat), color_white, TextAlign::TOP_CENTER, "󰤯");
              ESP_LOGI("WiFi", "Unlikely");
          }
        } else
        {
          //no signal (yet)
          it.print(wifi_icon_x, wifi_icon_y, id(font_wifi_bat), color_white, TextAlign::TOP_CENTER, "󰤮");
          ESP_LOGI("WiFi", "No signal");          
        }

        if(id(battery_percentage).has_state()) 
        {
          if (id(battery_percentage).state >= 95) 
          {
              // 100 %
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_white, TextAlign::TOP_CENTER, "󰁹");
          } else if (id(battery_percentage).state  >= 90) {
              // 90 %
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_white, TextAlign::TOP_CENTER, "󰂂");
          } else if (id(battery_percentage).state  >= 80) {
              // 80%
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_white, TextAlign::TOP_CENTER, "󰂁");
          } else if (id(battery_percentage).state  >= 70) {
              // 70%
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_white, TextAlign::TOP_CENTER, "󰂀");
          } else if (id(battery_percentage).state  >= 60) {
              // 60%
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_white, TextAlign::TOP_CENTER, "󰁿");
          } else if (id(battery_percentage).state  >= 50) {
              // 50%
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_white, TextAlign::TOP_CENTER, "󰁾");
          } else if (id(battery_percentage).state  >= 40) {
              // 40%
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_white, TextAlign::TOP_CENTER, "󰁽");
          } else if (id(battery_percentage).state  >= 30) {
              // 30%
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_white, TextAlign::TOP_CENTER, "󰁼");
          } else if (id(battery_percentage).state  >= 20) {
              // 20%
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_white, TextAlign::TOP_CENTER, "󰁻");
          } else {
              // 10%
              it.print(battery_icon_x, battery_icon_y, id(font_wifi_bat), color_white, TextAlign::TOP_CENTER, "󰁺");
          }
        }
      }
The above esphome lambda function renders a display of appointments for days of the week. There seems to be an error in the above code as it outputs the appointments for ueberueberuebermorgen multiple times. Can you find and fix the error?