# 使用方式:在设备配置中 include 此文件,并传入 climate_entity_id 和 uid 参数
styles: container_fullscreen # 引用已定义的样式
width: 480px
height: 480px
bg_image_src: background
scrollable: false
widgets:
# 中文
- label:
id: onffchinese
text: "开关"
width: 60px
height: 60px
text_font: cn24
text_color: 0xFFFFFF
align_to:
id: mode_off_btn_${uid}
align: OUT_BOTTOM_MID
x: 5px
y: 5px
- label:
id: coolchinese
text: "制冷"
width: 60px
height: 60px
text_font: cn24
text_color: 0xFFFFFF
align_to:
id: onffchinese
align: OUT_RIGHT_MID
x: 26px
- label:
id: heatchinese
text: "制热"
width: 60px
height: 60px
text_font: cn24
text_color: 0xFFFFFF
align_to:
id: coolchinese
align: OUT_RIGHT_MID
x: 26px
- label:
id: drychinese
text: "除湿"
width: 60px
height: 60px
text_font: cn24
text_color: 0xFFFFFF
align_to:
id: heatchinese
align: OUT_RIGHT_MID
x: 26px
- label:
id: floorheatchinese
text: "地暖"
width: 60px
height: 60px
text_font: cn24
text_color: 0xFFFFFF
align_to:
id: drychinese
align: OUT_RIGHT_MID
x: 26px
# wifi显示ICON
- label:
id: wifi_icon_${uid}
text: "\U000F05A9"
width: 30px
height: 30px
text_font: light24 # 使用大号字体
text_color: 0xFFFFFF
x: 10px
y: 10px
# time 显示
- label:
id: time_${uid}
text: "time"
width: 120px
height: 30px
text_font: roboto20 # 使用大号字体
text_color: 0xFFFFFF
x: 380px
y: 10px
# 天气标签
- label:
id: weather_temperature_${uid}
text: "25°"
width: 50px
height: 28px
text_font: roboto20 # 使用大号字体
text_color: 0xFFFFFF
align_to:
id: time_${uid}
align: OUT_LEFT_MID
x: -10
# 天气标签
- label:
id: weather_condition_${uid}
text: "\U000F14E4"
width: 30px
height: 30px
text_font: light24 # 使用大号字体
text_color: 0xFFFFFF
align_to:
id: weather_temperature_${uid}
align: OUT_LEFT_MID
x: -10
# 温度调节标签
- label:
id: temp_set_display_${uid}
text: "25°C"
width: 180px
height: 101px
text_font: roboto72 # 使用大号字体
text_color: 0xFFFFFF
x: 100px
y: 156px
# 温度显示标签
- label:
id: temp_display_${uid}
text: "25°C"
width: 60px
height: 28px
text_font: roboto20 # 使用大号字体
text_color: 0xFFFFFF
align_to:
id: temp_set_display_${uid}
align: OUT_BOTTOM_RIGHT
y: 5
# 温度显示ICON
- label:
id: temp_icon_${uid}
text: "\U000F02DC"
width: 30px
height: 30px
text_font: light24 # 使用大号字体
text_color: 0xFFFFFF
align_to:
id: temp_display_${uid}
align: OUT_LEFT_MID
x: 3
# 左侧透明<按钮
- button:
bg_opa: TRANSP
align_to:
id: temp_set_display_${uid}
align: OUT_LEFT_MID
y: -5
width: 80
height: 101
id: temp_decrease_${uid}
checkable: false
widgets:
- label:
text_font: roboto36 # 使用小号字体
text_color: 0xFFFFFF
align: center
text: "<"
on_press:
- lvgl.widget.update:
id: temp_decrease_${uid}
bg_opa: COVER
bg_color: 0x1E90FF
- lvgl.label.update:
id: temp_set_display_${uid}
text: !lambda |-
const char* temp_str = lv_label_get_text(id(temp_set_display_${uid}));
int current_temp = atoi(temp_str);
char temp_text[10];
snprintf(temp_text, sizeof(temp_text), "%d°C", current_temp - 1);
return temp_text;
on_release:
- delay: 300ms # 增加短暂延迟确保操作稳定
- lvgl.widget.update:
id: temp_decrease_${uid}
bg_opa: TRANSP
- if:
condition:
lambda: |-
static unsigned long last_press_time = 0;
const char* temp_str = lv_label_get_text(id(temp_set_display_${uid}));
int temp = atoi(temp_str);
unsigned long current_time = millis();
if (current_time - last_press_time > 1000) { // 1秒内无新操作
last_press_time = current_time;
ESP_LOGD("climate_control", "Setting temperature to %d", temp);
return temp > 16 && temp < 30;
}
ESP_LOGD("climate_control", "Operation too fast, skipping");
return false;
then:
- homeassistant.action:
action: climate.set_temperature
data:
entity_id: ${climate_entity_id}
temperature: !lambda |-
const char* temp_str = lv_label_get_text(id(temp_set_display_${uid}));
int temp = atoi(temp_str);
ESP_LOGD("climate_control", "Temperature set to %d", temp);
return temp;
- logger.log:
level: DEBUG
format: "Temperature control operation completed"
- delay: 300ms # 增加短暂延迟确保操作稳定
# 右侧透明>按钮
- button:
bg_opa: TRANSP
align_to:
id: temp_set_display_${uid}
align: OUT_RIGHT_MID
y: -5
x: -25
width: 80
height: 101
id: temp_increase_${uid}
checkable: false
widgets:
- label:
text_font: roboto36 # 使用小号字体
text_color: 0xFFFFFF
align: center
text: ">"
on_press:
- lvgl.widget.update:
id: temp_increase_${uid}
bg_opa: COVER
bg_color: 0x1E90FF
- lvgl.label.update:
id: temp_set_display_${uid}
text: !lambda |-
const char* temp_str = lv_label_get_text(id(temp_set_display_${uid}));
int current_temp = atoi(temp_str);
char temp_text[10];
snprintf(temp_text, sizeof(temp_text), "%d°C", current_temp + 1);
return temp_text;
# - homeassistant.action:
# action: climate.set_temperature
# data:
# entity_id: ${climate_entity_id}
# temperature: !lambda |- # 使用!lambda标签来定义lambda表达式
# const char* temp_str = lv_label_get_text(id(temp_set_display_${uid})); // 使用 lv_label_get_text 函数
# int current_temp = atoi(temp_str);
# return current_temp;
on_release:
- delay: 300ms # 增加短暂延迟确保操作稳定
- lvgl.widget.update:
id: temp_increase_${uid}
bg_opa: TRANSP
- if:
condition:
lambda: |-
static unsigned long last_press_time = 0;
const char* temp_str = lv_label_get_text(id(temp_set_display_${uid}));
int temp = atoi(temp_str);
unsigned long current_time = millis();
if (current_time - last_press_time > 1000) { // 1秒内无新操作
last_press_time = current_time;
ESP_LOGD("climate_control", "Setting temperature to %d", temp);
return temp > 16 && temp < 30;
}
ESP_LOGD("climate_control", "Operation too fast, skipping");
return false;
then:
- homeassistant.action:
action: climate.set_temperature
data:
entity_id: ${climate_entity_id}
temperature: !lambda |-
const char* temp_str = lv_label_get_text(id(temp_set_display_${uid}));
int temp = atoi(temp_str);
ESP_LOGD("climate_control", "Temperature set to %d", temp);
return temp;
- logger.log:
level: DEBUG
format: "Temperature control operation completed"
- delay: 300ms # 增加短暂延迟确保操作稳定
# 右侧风量选择下拉列表(透明设计)
- roller:
bg_opa: TRANSP
border_opa: TRANSP
id: fan_roller_${uid}
text_font: cn24 # 使用小号字体
text_color: 0xFFFFFF
bg_color: 0x1E90FF
visible_row_count: 4
options:
- "自动"
- "低风"
- "中风"
- "高风"
selected_index: 0
width: 120px
height: 100px
align_to:
id: temp_increase_${uid}
align: OUT_RIGHT_MID
on_value:
- homeassistant.action:
action: climate.set_fan_mode
data:
entity_id: ${climate_entity_id}
fan_mode: !lambda |
static const char* fan_str[] = {"auto", "low", "medium", "high"};
return fan_str[x];
# 模式按钮
- button:
id: mode_off_btn_${uid}
widgets:
- label:
align: center
text: "\U000F0425"
text_font: light24 # 使用大号字体
text_color: 0xFFFFFF
bg_color: 0x1E90FF # 初始背景颜色为蓝色
text_color: 0xFFFFFF
radius: LV_RADIUS_CIRCLE # 圆形按钮
width: 60px
height: 60px
x: 41px
y: 370px
on_press:
- homeassistant.action:
action: climate.set_hvac_mode
data:
entity_id: ${climate_entity_id}
hvac_mode: "off"
on_release:
- lvgl.widget.update:
id: mode_off_btn_${uid}
bg_color: 0x1E90FF
- lvgl.widget.update:
id: mode_cool_btn_${uid}
bg_color: 0x000000
- lvgl.widget.update:
id: mode_heat_btn_${uid}
bg_color: 0x000000
- lvgl.widget.update:
id: mode_dry_btn_${uid}
bg_color: 0x000000
- button:
id: mode_cool_btn_${uid}
widgets:
- label:
align: center
text: "\U000F0717"
text_font: light24 # 使用大号字体
text_color: 0xFFFFFF
bg_color: 0x000000 # 初始背景颜色为蓝色
text_color: 0xFFFFFF
radius: LV_RADIUS_CIRCLE # 圆形按钮
width: 60px
height: 60px
align_to:
id: mode_off_btn_${uid}
align: OUT_RIGHT_MID
x: 26px
on_press:
- homeassistant.action:
action: climate.set_hvac_mode
data:
entity_id: ${climate_entity_id}
hvac_mode: "cool"
on_release:
- lvgl.widget.update:
id: mode_off_btn_${uid}
bg_color: 0x000000
- lvgl.widget.update:
id: mode_cool_btn_${uid}
bg_color: 0x1E90FF
- lvgl.widget.update:
id: mode_heat_btn_${uid}
bg_color: 0x000000
- lvgl.widget.update:
id: mode_dry_btn_${uid}
bg_color: 0x000000
- button:
id: mode_heat_btn_${uid}
widgets:
- label:
align: center
text: "\U000F0238"
text_font: light24 # 使用大号字体
text_color: 0xFFFFFF
bg_color: 0x000000 # 初始背景颜色为蓝色
text_color: 0xFFFFFF
radius: LV_RADIUS_CIRCLE # 圆形按钮
width: 60px
height: 60px
align_to:
id: mode_cool_btn_${uid}
align: OUT_RIGHT_MID
x: 26px
on_press:
- homeassistant.action:
action: climate.set_hvac_mode
data:
entity_id: ${climate_entity_id}
hvac_mode: "heat"
on_release:
- lvgl.widget.update:
id: mode_off_btn_${uid}
bg_color: 0x000000
- lvgl.widget.update:
id: mode_cool_btn_${uid}
bg_color: 0x000000
- lvgl.widget.update:
id: mode_heat_btn_${uid}
bg_color: 0x1E90FF
- lvgl.widget.update:
id: mode_dry_btn_${uid}
bg_color: 0x000000
- button:
id: mode_dry_btn_${uid}
widgets:
- label:
align: center
text: "\U000F058C"
text_font: light24 # 使用大号字体
text_color: 0xFFFFFF
bg_color: 0x000000 # 初始背景颜色为蓝色
text_color: 0xFFFFFF
radius: LV_RADIUS_CIRCLE # 圆形按钮
width: 60px
height: 60px
align_to:
id: mode_heat_btn_${uid}
align: OUT_RIGHT_MID
x: 26px
on_press:
- homeassistant.action:
action: climate.set_hvac_mode
data:
entity_id: ${climate_entity_id}
hvac_mode: "dry"
on_release:
- lvgl.widget.update:
id: mode_off_btn_${uid}
bg_color: 0x000000
- lvgl.widget.update:
id: mode_cool_btn_${uid}
bg_color: 0x000000
- lvgl.widget.update:
id: mode_heat_btn_${uid}
bg_color: 0x000000
- lvgl.widget.update:
id: mode_dry_btn_${uid}
bg_color: 0x1E90FF
- button:
id: heat_floor_btn_${uid}
widgets:
- label:
align: center
text: "\U000F1AAF"
text_font: light24 # 使用icon
text_color: 0xFFFFFF
bg_color: 0x000000 # 初始背景颜色为蓝色
text_color: 0xFFFFFF
radius: LV_RADIUS_CIRCLE # 圆形按钮
width: 60px
height: 60px
align_to:
id: mode_dry_btn_${uid}
align: OUT_RIGHT_MID
x: 26px
on_press:
switch.toggle: local_switch_button_1
# 添加定时按钮
- button:
id: timer_btn_${uid}
widgets:
- label:
align: center
text: "\U000F0150" # 定时图标
text_font: light24 # 使用icon字体
text_color: 0xFFFFFF
bg_color: 0x000000
text_color: 0xFFFFFF
radius: LV_RADIUS_CIRCLE # 圆形按钮
width: 60px
height: 60px
x: 41px
y: 60px
on_press:
- lvgl.widget.update:
id: timer_popup_${uid}
hidden: false
- lvgl.widget.disable:
- id: fan_roller_${uid}
- id: temp_increase_${uid}
- id: temp_decrease_${uid}
# 定时器倒计时显示
- label:
id: timer_countdown_${uid}
hidden: true # 初始隐藏,定时器运行时显示
text: "" # 动态更新,初始为空
width: 80px
height: 30px
text_font: roboto20
text_color: 0xFFFFFF
align_to:
id: wifi_icon_${uid}
align: OUT_Right_MID
x: 10px
- obj:
id: timer_popup_${uid}
hidden: true
bg_color: 0x000000
bg_opa: 100%
border_color: 0x1E90FF
border_width: 2
radius: 10
width: 300px
height: 200px
x: 90px
y: 60px
widgets:
# 定时器标题
- label:
text: "定时关机"
text_font: cn24
text_color: 0xFFFFFF
align: TOP_MID
y: 10
# 时间显示
- label:
id: timer_display_${uid}
text: "0.5h"
text_font: cn24
text_color: 0xFFFFFF
align: CENTER
y: -10
# 减少时间按钮
- button:
id: timer_decrease_${uid}
width: 60px
height: 40px
bg_color: 0x1E90FF
radius: 5
x: 50px
y: 80px
widgets:
- label:
text: "-"
text_font: cn24
text_color: 0xFFFFFF
align: center
on_press:
- lambda: |-
const char* current_text = lv_label_get_text(id(timer_display_${uid}));
float timer_hours = std::stof(std::string(current_text).substr(0, std::string(current_text).size()-1)); // Remove 'h' suffix
timer_hours = std::max(timer_hours - 0.5f, 0.5f);
char buffer[10];
snprintf(buffer, sizeof(buffer), "%.1fh", timer_hours);
lv_label_set_text(id(timer_display_${uid}), buffer);
# 增加时间按钮
- button:
id: timer_increase_${uid}
width: 60px
height: 40px
bg_color: 0x1E90FF
radius: 5
x: 190px
y: 80px
widgets:
- label:
text: "+"
text_font: cn24
text_color: 0xFFFFFF
align: center
on_press:
- lambda: |-
const char* current_text = lv_label_get_text(id(timer_display_${uid}));
float timer_hours = std::stof(std::string(current_text).substr(0, std::string(current_text).size()-1)); // Remove 'h' suffix
timer_hours += 0.5f;
char buffer[10];
snprintf(buffer, sizeof(buffer), "%.1fh", timer_hours);
lv_label_set_text(id(timer_display_${uid}), buffer);
# 确定按钮
- button:
id: timer_confirm_${uid}
width: 80px
height: 40px
bg_color: 0x1E90FF
radius: 5
x: 60px
y: 140px
widgets:
- label:
text: "确定"
text_font: cn24
text_color: 0x000000
align: center
on_press:
- homeassistant.action:
service: timer.start
data:
entity_id: ${timer_entity_id}
duration: !lambda |-
// 直接从显示标签获取文本并转换为总秒数
const char* display_text = lv_label_get_text(id(timer_display_${uid}));
float hours = std::stof(std::string(display_text).substr(0, std::string(display_text).size()-1));
return static_cast<int>(hours * 3600);
- logger.log: "倒计时开始"
on_release:
- then:
- logger.log: "释放按钮"
- lvgl.widget.enable:
- id: fan_roller_${uid}
- id: temp_increase_${uid}
- id: temp_decrease_${uid}
- logger.log: "启用组件"
- lvgl.widget.update:
id: timer_popup_${uid}
hidden: true
- lvgl.widget.update:
id: timer_countdown_${uid}
hidden: false
# 取消按钮
- button:
id: timer_cancel_${uid}
bg_color: 0x1E90FF
width: 80px
height: 40px
radius: 5
x: 160px
y: 140px
widgets:
- label:
text: "取消"
text_font: cn24
text_color: 0x000000
align: center
on_press:
- lvgl.widget.update:
id: timer_countdown_${uid}
hidden: true
- homeassistant.action:
service: timer.cancel
data:
entity_id: ${timer_entity_id}
- logger.log: "定时取消"
on_release:
- then:
- logger.log: "释放按钮"
- lvgl.widget.enable:
- id: fan_roller_${uid}
- id: temp_increase_${uid}
- id: temp_decrease_${uid}
- logger.log: "启用组件"
- lvgl.widget.update:
id: timer_popup_${uid}
hidden: true
|