Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- esphome:
- name: esp32-cyd-server-rack
- friendly_name: esp32-cyd-server-rack
- on_boot:
- priority: 800
- then:
- - delay: 3s
- - lambda: |-
- ESP_LOGI("boot", "Marking boot successful");
- # - wait_until:
- # condition:
- # lambda: 'return api_is_connected() && id(light_dining_room_counter_light).has_state();'
- # timeout: 10s
- - lvgl.resume
- - script.execute: manage_run_and_sleep
- esp32:
- board: esp32dev
- framework:
- type: esp-idf
- # Enable logging
- logger:
- # Enable Home Assistant API
- api:
- encryption:
- key: "oVIEa0xxsoCfE4LkZFewon/qtXRlcTeWRF1XkUrdTSU="
- on_client_connected:
- then:
- - delay: 500ms
- - if:
- condition:
- lambda: 'return id(light_dining_room_counter_light).has_state();'
- then:
- - lvgl.widget.update:
- id: w_mn01dnrvu1c6v
- state:
- checked: !lambda return id(light_dining_room_counter_light).state;
- - if:
- condition:
- lambda: 'return id(switch_multiplug).has_state();'
- then:
- - lvgl.widget.update:
- id: w_mn0b6u39ywr7b
- state:
- checked: !lambda return id(switch_multiplug).state;
- - if:
- condition:
- lambda: 'return id(switch_jw_hp).has_state();'
- then:
- - lvgl.widget.update:
- id: w_mn0cb70a1o0zd
- state:
- checked: !lambda return id(switch_jw_hp).state;
- - if:
- condition:
- lambda: 'return id(switch_ew_hp).has_state();'
- then:
- - lvgl.widget.update:
- id: w_mn0f1jw1d3hxa
- state:
- checked: !lambda return id(switch_ew_hp).state;
- ota:
- - platform: esphome
- password: "dc6183133995a2cd0358e51bfd6e3922"
- wifi:
- ssid: !secret wifi_ssid
- password: !secret wifi_password
- # Enable fallback hotspot (captive portal) in case wifi connection fails
- ap:
- ssid: "Esp32-Cyd-Server-Rack"
- password: "KBGU81QY2x6y"
- web_server:
- port: 80
- captive_portal:
- spi:
- - id: lcd
- clk_pin: GPIO14
- mosi_pin: GPIO13
- miso_pin: GPIO12
- - id: touch
- clk_pin: GPIO25
- mosi_pin: GPIO32
- miso_pin: GPIO39
- i2c:
- sda: GPIO27
- scl: GPIO22
- scan: true
- id: i2c_bus_a
- display:
- - platform: ili9xxx
- model: ili9341
- spi_id: lcd
- dc_pin: GPIO2
- cs_pin: GPIO15
- id: display_1
- invert_colors: false
- update_interval: 16ms # ~60 FPS (smooth)
- auto_clear_enabled: false
- show_test_card: false
- dimensions:
- width: 320
- height: 240
- transform:
- swap_xy: true
- mirror_x: false
- mirror_y: false
- touchscreen:
- platform: xpt2046
- spi_id: touch
- cs_pin: GPIO33
- interrupt_pin: GPIO36
- update_interval: 50ms
- id: touchscreen_1
- # report_interval: 1s
- threshold: 400
- calibration:
- x_min: 294
- x_max: 3796
- y_min: 200
- y_max: 3700
- transform:
- swap_xy: true
- mirror_x: false
- mirror_y: false
- on_touch:
- then:
- - script.execute: wake_screen
- # on_touch:
- # - lambda: |-
- # ESP_LOGI("cal", "x=%d, y=%d, x_raw=%d, y_raw=%0d",
- # touch.x,
- # touch.y,
- # touch.x_raw,
- # touch.y_raw
- # );
- on_release:
- - if:
- condition: lvgl.is_paused
- then:
- - lvgl.resume:
- - light.turn_on: display_backlight
- # Define pins for backlight display and rear LED
- output:
- - platform: ledc
- pin: 21
- id: gpio_backlight_pwm
- - id: output_red
- platform: ledc
- pin: 4
- inverted: true
- - id: output_green
- platform: ledc
- pin: 16
- inverted: true
- - id: output_blue
- platform: ledc
- pin: 17
- inverted: true
- light:
- - platform: monochromatic
- output: gpio_backlight_pwm
- name: Display Backlight
- icon: mdi:lightbulb-on
- id: display_backlight
- restore_mode: ALWAYS_ON
- on_turn_on:
- - delay: 3s # give LVGL time to be ready
- - platform: rgb
- id: rgb_led
- name: RGB LED
- red: output_red
- green: output_green
- blue: output_blue
- restore_mode: ALWAYS_OFF
- globals:
- - id: display_page
- type: int
- restore_value: true
- initial_value: '0'
- - id: page_refresh_default_s
- type: int
- restore_value: true
- initial_value: '600'
- - id: page_refresh_current_s
- type: int
- restore_value: false
- initial_value: '60'
- - id: last_page_switch_time
- type: uint32_t
- restore_value: false
- initial_value: '0'
- time:
- - platform: homeassistant
- id: ha_time
- on_time:
- - seconds: 0
- then:
- - lvgl.label.update:
- id: w_mmyk1aw5azz82
- text: !lambda |-
- auto now = id(ha_time).now();
- return now.strftime("%H:%M\n%a, %b %d").c_str();
- sensor:
- - platform: homeassistant
- id: sensor_server_rack_temperature
- entity_id: sensor.server_rack_temperature
- on_value:
- then:
- - lvgl.widget.refresh: temp_icon
- - lvgl.widget.refresh: temp_text
- internal: true
- binary_sensor:
- - platform: homeassistant
- id: light_dining_room_counter_light
- entity_id: light.dining_room_counter_light
- on_state:
- then:
- - lvgl.widget.update:
- id: w_mn01dnrvu1c6v
- state:
- checked: !lambda return id(light_dining_room_counter_light).state;
- internal: true
- - platform: homeassistant
- id: switch_multiplug
- entity_id: switch.multiplug
- on_state:
- then:
- - lvgl.widget.update:
- id: w_mn0b6u39ywr7b
- state:
- checked: !lambda return id(switch_multiplug).state;
- internal: true
- - platform: homeassistant
- id: switch_jw_hp
- entity_id: switch.jw_hp
- on_state:
- then:
- - lvgl.widget.update:
- id: w_mn0cb70a1o0zd
- state:
- checked: !lambda return id(switch_jw_hp).state;
- internal: true
- - platform: homeassistant
- id: switch_ew_hp
- entity_id: switch.ew_hp
- on_state:
- then:
- - lvgl.widget.update:
- id: w_mn0f1jw1d3hxa
- state:
- checked: !lambda return id(switch_ew_hp).state;
- internal: true
- - platform: homeassistant
- id: switch_wilkencloud01
- entity_id: switch.wilkencloud01
- on_state:
- then:
- - lvgl.widget.update:
- id: w_mn1ibftg5zi7r
- state:
- checked: !lambda return id(switch_wilkencloud01).state;
- internal: true
- - platform: homeassistant
- id: switch_wilkencloud02
- entity_id: switch.wilkencloud02
- on_state:
- then:
- - lvgl.widget.update:
- id: w_mn1ibftg206a7
- state:
- checked: !lambda return id(switch_wilkencloud02).state;
- internal: true
- - platform: gpio
- pin: GPIO35
- name: "Server Rack Motion"
- device_class: motion
- font:
- - file:
- type: gfonts
- family: "Roboto"
- weight: 700
- italic: false
- id: font_roboto_700_12
- size: 12
- glyphsets: [GF_Latin_Kernel]
- ignore_missing_glyphs: true
- - file:
- type: gfonts
- family: "Roboto"
- weight: 400
- italic: false
- id: font_roboto_400_8
- size: 8
- glyphsets: [GF_Latin_Kernel]
- ignore_missing_glyphs: true
- - file:
- type: gfonts
- family: "Roboto"
- weight: 400
- italic: false
- id: font_roboto_400_20
- size: 20
- glyphsets: [GF_Latin_Kernel]
- ignore_missing_glyphs: true
- - file: "fonts/materialdesignicons-webfont.ttf"
- id: font_material_design_icons_400_10
- size: 10
- glyphs: ["\U000F050F", "\U000F0E4C", "\U000F10C2"]
- - file:
- type: gfonts
- family: "Roboto"
- weight: 400
- italic: false
- id: font_roboto_400_15
- size: 15
- glyphsets: [GF_Latin_Kernel]
- ignore_missing_glyphs: true
- - file:
- type: gfonts
- family: "Roboto"
- weight: 400
- italic: false
- id: font_roboto_400_10
- size: 10
- glyphsets: [GF_Latin_Kernel]
- ignore_missing_glyphs: true
- lvgl:
- id: my_lvgl
- log_level: WARN
- bg_color: "0x000000"
- displays:
- - display_1
- pages:
- - id: page_0
- on_load:
- then:
- - delay: 2s # give LVGL time to render
- # - script.execute: sync_ui
- widgets:
- # Background container (decorative, non-blocking)
- - obj:
- id: w_mmxla1ug3vlfe
- x: 0
- y: 2
- width: 319
- height: 237
- bg_color: "0x000000" # keep black background
- bg_opa: 0 # fully opaque so LVGL renders it
- border_color: "0xFFFFFF"
- border_width: 3
- radius: 20
- clickable: false
- scrollable: false # ensure it doesn’t try to catch touches
- # WORKING SWITCH — direct child of page
- - switch:
- id: w_mn01dnrvu1c6v
- bg_color: "gray"
- height: 27
- ignore_layout: true
- indicator:
- bg_color: "blue"
- knob:
- bg_color: "white"
- on_value:
- -
- homeassistant.service:
- data:
- entity_id: light.dining_room_counter_light
- service: homeassistant.toggle
- opa: cover
- scrollable: false
- state:
- checked: !lambda return id(light_dining_room_counter_light).state;
- width: 51
- x: 40
- y: 94
- # Temperature display (icon + text)
- - obj:
- id: temp_container
- x: 245
- y: 8
- width: 64
- height: 69
- bg_opa: transp
- border_width: 0
- clickable: false
- widgets:
- - label:
- id: temp_icon
- height: 14
- width: 20
- align: top_mid
- clickable: false
- text_color: "0xFFFFFF"
- text_font: font_material_design_icons_400_10
- text: !lambda |-
- if (id(sensor_server_rack_temperature).has_state()) {
- float t = id(sensor_server_rack_temperature).state;
- if (t <= 10) return "\U000F0E4C";
- if (t <= 25) return "\U000F050F";
- return "\U000F10C2";
- }
- return "\U000F050F";
- - label:
- id: temp_text
- height: 16
- width: 100%
- y: 12
- text_align: center
- clickable: false
- text_color: "0xFFFFFF"
- text_font: font_roboto_400_10
- text: !lambda |-
- if (id(sensor_server_rack_temperature).has_state()) {
- return str_sprintf("%.1f°C", id(sensor_server_rack_temperature).state).c_str();
- }
- return "--°C";
- # Clock label
- - label:
- id: w_mmyk1aw5azz82
- x: 23
- y: 15
- width: 61
- height: 37
- text_align: center
- text_color: "0xFFFFFF"
- text_font: font_roboto_700_12
- clickable: false
- text: !lambda |-
- auto now = id(ha_time).now();
- return now.strftime("%H:%M\n%a, %b %d").c_str();
- # Server Rack label
- - label:
- id: w_mmyjzi4xmr8z9
- x: 107
- y: 28
- width: 120
- height: 40
- text_align: left
- text_color: "0xFFFFFF"
- text_font: font_roboto_400_20
- clickable: false
- text: "Server Rack"
- # Decorative line under header
- - line:
- id: w_mmyjx2wpcpl8r
- x: 41
- y: 59
- width: 240
- height: 3
- line_color: "0xFFFFFF"
- line_width: 3
- line_rounded: true
- opa: cover
- clickable: false
- points:
- - x: 0
- y: 0
- - x: 240
- y: 0
- # DR Light Switch Label
- - label:
- id: w_mn0b0hyvltn7m
- border_color: "black"
- border_side: none
- border_width: 0
- height: 22
- opa: cover
- radius: 0
- text: "Light"
- text_align: left
- text_color: "0xFFFFFF"
- text_font: font_roboto_400_15
- width: 39
- x: 40
- y: 72
- - label:
- id: w_mn0b6u392gaj8
- border_color: "black"
- border_side: none
- border_width: 0
- height: 22
- opa: cover
- radius: 0
- text: "Fans"
- text_align: left
- text_color: "0xFFFFFF"
- text_font: font_roboto_400_15
- width: 65
- x: 40
- y: 129
- - switch:
- id: w_mn0b6u39ywr7b
- bg_color: "gray"
- height: 27
- ignore_layout: true
- indicator:
- bg_color: "blue"
- knob:
- bg_color: "white"
- on_value:
- -
- homeassistant.service:
- data:
- entity_id: switch.multiplug
- service: homeassistant.toggle
- opa: cover
- scrollable: false
- state:
- checked: !lambda return id(switch_multiplug).state;
- width: 51
- x: 40
- y: 150
- - label:
- id: w_mn0cb70axj09e
- border_color: "black"
- border_side: none
- border_width: 0
- height: 22
- opa: cover
- radius: 0
- text: "JW-HP"
- text_align: left
- text_color: "0xFFFFFF"
- text_font: font_roboto_400_15
- width: 50
- x: 137
- y: 72
- - switch:
- id: w_mn0cb70a1o0zd
- bg_color: "gray"
- height: 27
- ignore_layout: true
- indicator:
- bg_color: "blue"
- knob:
- bg_color: "white"
- on_value:
- -
- homeassistant.service:
- data:
- entity_id: switch.jw_hp
- service: homeassistant.toggle
- opa: cover
- scrollable: false
- state:
- checked: !lambda return id(switch_jw_hp).state;
- width: 51
- x: 136
- y: 94
- - switch:
- id: w_mn0f1jw1d3hxa
- bg_color: "gray"
- height: 27
- ignore_layout: true
- indicator:
- bg_color: "blue"
- knob:
- bg_color: "white"
- on_value:
- -
- homeassistant.service:
- data:
- entity_id: switch.ew_hp
- service: homeassistant.toggle
- opa: cover
- scrollable: false
- state:
- checked: !lambda return id(switch_ew_hp).state;
- width: 51
- x: 137
- y: 150
- - label:
- id: w_mn0f1jw1xfgy0
- border_color: "black"
- border_side: none
- border_width: 0
- height: 22
- opa: cover
- radius: 0
- text: "EW-HP"
- text_align: left
- text_color: "0xFFFFFF"
- text_font: font_roboto_400_15
- width: 50
- x: 137
- y: 128
- - label:
- id: w_mn1ibftgoer2x
- border_color: "black"
- border_side: none
- border_width: 0
- height: 22
- opa: cover
- radius: 0
- text: "Cloud01"
- text_align: left
- text_color: "0xFFFFFF"
- text_font: font_roboto_400_15
- width: 70
- x: 230
- y: 72
- - switch:
- id: w_mn1ibftg5zi7r
- bg_color: "gray"
- height: 27
- ignore_layout: true
- indicator:
- bg_color: "blue"
- knob:
- bg_color: "white"
- on_value:
- -
- homeassistant.service:
- data:
- entity_id: switch.wilkencloud01
- service: homeassistant.toggle
- opa: cover
- scrollable: false
- state:
- checked: !lambda return id(switch_wilkencloud01).state;
- width: 51
- x: 229
- y: 94
- - label:
- id: w_mn1ibftgb47cy
- border_color: "black"
- border_side: none
- border_width: 0
- height: 22
- opa: cover
- radius: 0
- text: "Cloud02"
- text_align: left
- text_color: "0xFFFFFF"
- text_font: font_roboto_400_15
- width: 70
- x: 230
- y: 128
- - switch:
- id: w_mn1ibftg206a7
- bg_color: "gray"
- height: 27
- ignore_layout: true
- indicator:
- bg_color: "blue"
- knob:
- bg_color: "white"
- on_value:
- -
- homeassistant.service:
- data:
- entity_id: switch.wilkencloud02
- service: homeassistant.toggle
- opa: cover
- scrollable: false
- state:
- checked: !lambda return id(switch_wilkencloud02).state;
- width: 51
- x: 230
- y: 150
- script:
- - id: manage_run_and_sleep
- mode: restart
- then:
- - logger.log: "Waiting for sync..."
- - delay: 5s
- - lambda: |-
- int interval = id(page_refresh_default_s);
- id(page_refresh_current_s) = interval;
- - component.update: display_1
- - delay: 300ms
- - script.execute: sync_ui_dr_counter_light
- - script.execute: sync_ui_sr_fans
- - script.execute: sync_ui_switch_jw_hp
- - script.execute: sync_ui_switch_ew_hp
- - script.execute: sync_ui_switch_wilkencloud01
- - script.execute: sync_ui_switch_wilkencloud02
- - script.execute: dim_screen
- - delay: !lambda 'return id(page_refresh_current_s) * 1000;'
- - script.execute: manage_run_and_sleep
- - id: sync_ui_dr_counter_light
- then:
- - lvgl.widget.update:
- id: w_mn01dnrvu1c6v
- state:
- checked: !lambda return id(light_dining_room_counter_light).state;
- # force visual refresh (important!)
- - lvgl.widget.redraw: w_mn01dnrvu1c6v
- - id: sync_ui_sr_fans
- then:
- - lvgl.widget.update:
- id: w_mn0b6u39ywr7b
- state:
- checked: !lambda return id(switch_multiplug).state;
- # force visual refresh (important!)
- - lvgl.widget.redraw: w_mn0b6u39ywr7b
- - id: sync_ui_switch_jw_hp
- then:
- - lvgl.widget.update:
- id: w_mn0cb70a1o0zd
- state:
- checked: !lambda return id(switch_jw_hp).state;
- # force visual refresh (important!)
- - lvgl.widget.redraw: w_mn0cb70a1o0zd
- - id: sync_ui_switch_ew_hp
- then:
- - lvgl.widget.update:
- id: w_mn0f1jw1d3hxa
- state:
- checked: !lambda return id(switch_ew_hp).state;
- # force visual refresh (important!)
- - lvgl.widget.redraw: w_mn0f1jw1d3hxa
- - id: sync_ui_switch_wilkencloud01
- then:
- - lvgl.widget.update:
- id: w_mn1ibftg5zi7r
- state:
- checked: !lambda return id(switch_wilkencloud01).state;
- # force visual refresh (important!)
- - lvgl.widget.redraw: w_mn1ibftg5zi7r
- - id: sync_ui_switch_wilkencloud02
- then:
- - lvgl.widget.update:
- id: w_mn1ibftg206a7
- state:
- checked: !lambda return id(switch_wilkencloud02).state;
- # force visual refresh (important!)
- - lvgl.widget.redraw: w_mn1ibftg206a7
- - id: wake_screen
- mode: restart
- then:
- - light.turn_on:
- id: display_backlight
- brightness: 100%
- transition_length: 0s
- - script.execute: dim_screen
- - id: dim_screen
- mode: restart
- then:
- - delay: 15s
- - light.turn_on:
- id: display_backlight
- brightness: 40% # Dimmed level
- transition_length: 5s
- switch:
- - platform: restart
- name: "ESP32-2432S028 Display Restart"
Advertisement
Add Comment
Please, Sign In to add comment