#------------------- Высота солнца над горизонтом  -------------------#
  - platform: sun
    id: ${weather}_sun_elevation
    type: elevation
    force_update: true
    on_value:
      then:
        - lambda: |-
            if (x <= -3) 
              { lv_obj_add_flag(id(${lvgl}_weather_uv_icon_state), LV_OBJ_FLAG_HIDDEN);
                std::string phase = id(${weather}_moon_phase).state; 
                if (phase == "unavailable" || phase == "unknown")
                  { lv_img_set_src(id(${lvgl}_weather_uv_moon_sun_icon), id(${image}_ha_sensor_na_40)); }
                else
                  { const std::string const_phase = id(${weather}_moon_phase).state;
                    static const std::pair<const char*, const void*> moon_icon[] PROGMEM = 
                      { {"new_moon",        (const void*) id(${image}_moon_1)},
                        {"waxing_crescent", (const void*) id(${image}_moon_2)},
                        {"first_quarter",   (const void*) id(${image}_moon_3)},
                        {"waxing_gibbous",  (const void*) id(${image}_moon_4)},
                        {"full_moon",       (const void*) id(${image}_moon_5)},
                        {"waning_gibbous",  (const void*) id(${image}_moon_6)},
                        {"last_quarter",    (const void*) id(${image}_moon_7)},
                        {"waning_crescent", (const void*) id(${image}_moon_8)} };
                    const void* icon = (const void*) id(${image}_ha_sensor_na_40);
                    for (const auto& pair : moon_icon)
                      { if (const_phase == pair.first) 
                        { icon = pair.second;
                          break; } }
                    lv_img_set_src(id(${lvgl}_weather_uv_moon_sun_icon), icon); } } }

            if (x >= 3)
              int uv = id(${weather}_uv_index).state;
              if (isnan(uv))
                { lv_img_set_src(id(${lvgl}_weather_uv_moon_sun_icon), id(${image}_ha_sensor_na_40));
                  lv_obj_add_flag(id(${lvgl}_weather_uv_icon_state), LV_OBJ_FLAG_HIDDEN); }
              else
                { if (uv >= 1 && uv <= 8)
                  { lv_img_set_src(id(${lvgl}_weather_uv_moon_sun_icon), id(${image}_uv_index));
                    esphome::image::Image* uv_icons_state[] =
                      { id(${image}_state_1), id(${image}_state_2), id(${image}_state_3),
                        id(${image}_state_4), id(${image}_state_5), id(${image}_state_6),
                        id(${image}_state_7), id(${image}_state_8) };
                    lv_img_set_src(id(${lvgl}_weather_uv_icon_state), uv_icons_state[int(uv) - 1]); }
                  else if (uv < 1)
                    { lv_obj_add_flag(id(${lvgl}_weather_uv_moon_sun_icon), LV_OBJ_FLAG_HIDDEN);
                      lv_obj_add_flag(id(${lvgl}_weather_uv_icon_state), LV_OBJ_FLAG_HIDDEN); } }

            if ((x > -3) && (x < 3))
              { lv_obj_clear_flag(id(${lvgl}_weather_uv_moon_sun_icon), LV_OBJ_FLAG_HIDDEN);
                lv_obj_add_flag(id(${lvgl}_weather_uv_icon_state), LV_OBJ_FLAG_HIDDEN);
                if ((x > -3) && (x < 0))
                  { if (id(${weather}_solar_rising).state == "True")
                      { lv_img_set_src(id(${lvgl}_weather_uv_moon_sun_icon), id(${image}_moon_set)); } 
                    else if (id(${weather}_solar_rising).state == "False")
                      { lv_img_set_src(id(${lvgl}_weather_uv_moon_sun_icon), id(${image}_moon_rise)); } }
                else if ((x >= 0) && (x < 3))
                  { if (id(${weather}_solar_rising).state == "True")
                      { lv_img_set_src(id(${lvgl}_weather_uv_moon_sun_icon), id(${image}_sun_rise)); }
                    else if (id(${weather}_solar_rising).state == "False")
                      { lv_img_set_src(id(${lvgl}_weather_uv_moon_sun_icon), id(${image}_sun_set)); } } }

            const int brightness_levels[] = {30,40,50,60,70,80,90,100};
            int index = x < -3 ? 0 : x < -2 ? 1 : x < -1 ? 2 : x < 0 ? 3 : 
                        x < 1 ? 4 : x < 2 ? 5 : x < 3 ? 6 : 7;
            if (id(${device}_backlight_dim).state != brightness_levels[index])
              { auto call = id(${device}_backlight_dim).make_call();
                call.set_value(brightness_levels[index]);
                call.perform(); }