找回密码
 立即注册

微信扫码登录

搜索
查看: 75|回复: 5

[硬件DIY] ESP32空调面板

[复制链接]

11

主题

64

回帖

651

积分

论坛分享达人

积分
651
金钱
576
HASS币
0
发表于 3 小时前 | 显示全部楼层 |阅读模式
开发商给的破面板太丑,不能编程

自己用ESPHOME+LVGL写了一个空调地暖都可以控制
1000010148 (002).jpg

评分

参与人数 2金钱 +30 收起 理由
冬瓜HA + 20 论坛有你更精彩!
book123 + 10 高手,这是高手!

查看全部评分

回复

使用道具 举报

15

主题

296

回帖

2776

积分

金牌会员

积分
2776
金钱
2460
HASS币
50
发表于 2 小时前 | 显示全部楼层
能分享一下esphome代码供学习吗
回复

使用道具 举报

11

主题

64

回帖

651

积分

论坛分享达人

积分
651
金钱
576
HASS币
0
 楼主| 发表于 2 小时前 | 显示全部楼层
book123 发表于 2025-12-23 16:19
能分享一下esphome代码供学习吗
# Substitution variables used through the codebase
substitutions:
  lightbulb:         "\U000F0335"
  ceiling_light:     "\U000F0769"
  lamp:              "\U000F06B5"
  floor_lamp:        "\U000F08DD"
  string_lights:     "\U000F12BA"
  track_light:       "\U000F0914"
  bulkhead_light:    "\U000F1A2F"
  led_strip:         "\U000F07D6"
  coach_lamp:        "\U000F1020"
  ceiling_fan_light: "\U000F1798"
  bed:               "\U000F02E3"
  sunny:             "\U000F05A8"
  homeicon:          "\U000F10B5"
  computer:          "\U000F07C0"
  fan:               "\U000F0210"
  cover:             "\U000F1846"
  coverclose:        "\U000F1846"
  wifi_25:           "\U000F08BF" # wifi signal from 25% to 1%
  wifi_50:           "\U000F08BC" # wifi signal from 50% to 25%
  wifi_75:           "\U000F08BD" # wifi signal from 75% to 50%
  wifi_100:          "\U000F08BE" # wifi signal from 100% to 75% or disable
  illumination:      "\U000F050E"  # lux
  color_temp:        "\U000F1A79"  # color_temp
  icon_font: light40
  text_font: cn24
  text_color: white
  bg_color: black
  button_on_color: "ep_orange"
  button_off_color: "very_dark_gray"
  mode_on_color: "cc_blue"
  mode_off_color: "cc_black"
  icon_on_color: "yellow"
  icon_off_color: "gray"
  label_on_color: "white"
  label_off_color: "gray"
  button_text_color: "white"
  button_height_single: '109px'
  button_height_double: '228px'
  button_height_full: '460px'
  button_width: '150px'
  touchscreen_idle_timeout: "30s"
  touchscreen_daytime_brightness: "80%"
  touchscreen_nighttime_brightness: "30%"
  # Boot screen configuration
  boot_screen_delay: 5s

  # Set Night mode  at Mightnight
  screen_night_hour: '21'
  screen_night_minute: '0'

  # Set Day mode at 5:30am
  screen_day_hour: '7'
  screen_day_minute: '30'

  # Screen Size
  screen_height: '480px'
  screen_width: '480px'
  

esphome:
  name: "climate-panel-r1"
  friendly_name: "climateR1"
  comment: "Guition ESP32-4848S040 480px * 480px Smart Screen"

# Time update script - This is run once per second. Use it to update any time related labels.
script:
  - id: time_update
    then:
      - lambda: |-
          auto time = id(system_time).now();
          char time_str[6];
          snprintf(time_str, sizeof(time_str), "%02d:%02d", time.hour, time.minute);
  - id: delay_script
    then:
      - logger.log: "开始延时"
      - delay: 1s  # 延时5秒(支持ms/s/m/h单位)
      - logger.log: "延时结束,执行后续操作"
packages:
  # Generic configuration for ESP32 screens
  # If you need Wi-Fi include this
  wifi: !include modules/base/wifi.yaml
  # Basic ESP 32 stuff
  base: !include modules/base/base.yaml
  # If you have a touch screen include this
  touchscreen: !include modules/base/touchscreen.yaml
  # If your touch screen has a backlight include this
  backlight: !include modules/base/backlignt.yaml
  # All the colors
  colors: !include modules/base/color.yaml
  # Fonts you need
  fonts: !include modules/base/fonts.yaml
  # Your Images
  images: !include modules/base/images.yaml
  # Some basic sensors
  basicsensor: !include
    file: modules/sensors/sensors_base.yaml
    vars:
      uid: climateR1
  # Styles + Themes
  theme_style: !include modules/base/theme_style.yaml

  # Harware description file - for your board
  hardware: !include modules/hardware/guition-esp32-s3-4848s040.yaml

  # This section will Update button and relay state from Home Assistant
  # Any button that has real time updates needs a section here

  # Button 1 - Local relay button with state updates
  # ha_name - will show up as a control in Home Assistant
  button_1_state: !include
    file: modules/sensors/local_relay_button_state.yaml
    vars:
      uid: button_1
      ha_name: floor_heat_3
      entity_id: internal_relay_1
  # Button 5 - Standard light button with state updates
  button_5_state: !include
    file: modules/sensors/fan_state.yaml
    vars:
      uid: button_5
      entity_id: fan.mynewair 
  # 包含空调传感器模块
  climate_sensor1_state: !include
    file: modules/sensors/climate_sensor.yaml
    vars:
      uid: climateR1
      heatuid: switch.climater1_floor_heat_3
      climate_entity_id: climate.york_modbus_york_modbus_192_168_0_118_2
      timer_entity_id: timer.climate3
  # 包含空调传感器模块
  climate_sensor2_state: !include
    file: modules/sensors/climate_sensor.yaml
    vars:
      uid: climateR1_2
      heatuid: switch.climater1_floor_heat_3
      climate_entity_id: climate.york_modbus_york_modbus_192_168_0_118_1
      timer_entity_id: timer.climate4
# -------------------------------------------------------------------------
# LVGL pages and buttons
# -------------------------------------------------------------------------
lvgl:
  # Boot screen
  top_layer: !include
    file: modules/screens/boot_screen.yaml
    vars:
      height: $screen_height
      width: $screen_width
  # 主页面
  pages:
    # 空调控制页面
    - id: climate_page1
      <<: !include
        file: modules/sections/swipe_navigation.yaml
      widgets:
        # 空调控制面板
        - obj: !include
            file: modules/buttons/climate_control.yaml
            vars:
              climate_entity_id: climate.york_modbus_york_modbus_192_168_0_118_2
              timer_entity_id: timer.climate3
              uid: climateR1
              nameuid: 客厅
    # 空调控制页面
    - id: climate_page2
      <<: !include
        file: modules/sections/swipe_navigation.yaml
      widgets:
        # 空调控制面板
        - obj: !include
            file: modules/buttons/climate_control.yaml
            vars:
              climate_entity_id: climate.york_modbus_york_modbus_192_168_0_118_1
              timer_entity_id: timer.climate4
              uid: climateR1_2      
              nameuid: 餐厅        
    - id: main_page
      <<: !include
        file: modules/sections/swipe_navigation.yaml
      layout:
        type: flex
        flex_flow: COLUMN_WRAP
      width: 100%
      styles: page_style
      bg_color: 0x000000
      widgets:
        # 按钮 1 - 新风
        - button: !include
            file: modules/buttons/fan_button.yaml
            vars:
              uid: button_5
              height: $button_height_double
              text: "新风"
              icon: $fan
              entity_id: fan.mynewair
        # 按钮  - 标准(双高)内部继电器按钮,带状态更新 hidden
        - button: !include
            file: modules/buttons/local_relay_button.yaml
            vars:
              uid: button_1
              height: 0px
              text: " "
              icon: $lightbulb
回复

使用道具 举报

15

主题

296

回帖

2776

积分

金牌会员

积分
2776
金钱
2460
HASS币
50
发表于 2 小时前 | 显示全部楼层
好人
回复

使用道具 举报

11

主题

64

回帖

651

积分

论坛分享达人

积分
651
金钱
576
HASS币
0
 楼主| 发表于 2 小时前 | 显示全部楼层
# 使用方式:在设备配置中 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
回复

使用道具 举报

8

主题

737

回帖

4933

积分

论坛元老

积分
4933
金钱
4183
HASS币
40
QQ
发表于 10 分钟前 | 显示全部楼层
这个面板哪里有卖的?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian ( 晋ICP备17001384号-1 )

GMT+8, 2025-12-23 19:02 , Processed in 0.228976 second(s), 10 queries , MemCached On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表