nene1234

lilka second display

Nov 16th, 2025
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 9.83 KB | None | 0 0
  1. esphome:
  2.   name: lilka
  3.   friendly_name: lilka
  4.   on_boot:
  5.     priority: 600
  6.     then:
  7.       - output.turn_on: display_power
  8.       - delay: 100ms
  9.  
  10. esp32:
  11.   board: esp32-s3-devkitc-1
  12.   framework:
  13.     type: esp-idf
  14.  
  15. wifi:
  16.   ssid: !secret wifi_ssid
  17.   password: !secret wifi_password
  18.   ap:
  19.     ssid: "Lilka Fallback Hotspot"
  20.     password: "hnYImYM4O6I0"
  21.  
  22. captive_portal:
  23. web_server:
  24.   port: 80
  25.  
  26. api:
  27.   encryption:
  28.     key: "Yw3yq8lxsaze+jdggjAwxKpV4GD6gNZptvw4d6OPfOc="
  29.  
  30. logger:
  31. ota:
  32.   - platform: esphome
  33.     password: "bb198feb99159fdaefc8092f10039acd"
  34.  
  35. output:
  36.   - platform: gpio
  37.     pin: 46
  38.     id: display_power
  39.     inverted: false
  40.  
  41. # ---------------------------------------------------
  42. # СЕНСОРИ
  43. # ---------------------------------------------------
  44.  
  45. sensor:
  46.   - platform: adc
  47.     pin: GPIO3
  48.     name: "Battery Voltage"
  49.     id: battery_voltage
  50.     attenuation: 12db
  51.     update_interval: 10s
  52.     filters:
  53.       - multiply: 1.33
  54.  
  55.   - platform: template
  56.     name: "Battery Level"
  57.     id: battery_level
  58.     unit_of_measurement: "%"
  59.     accuracy_decimals: 0
  60.     update_interval: 10s
  61.     lambda: |-
  62.       float voltage = id(battery_voltage).state;
  63.       float percent = (voltage - 3.0) / (4.2 - 3.0) * 100.0;
  64.       if (percent > 100) percent = 100;
  65.       if (percent < 0) percent = 0;
  66.       return percent;
  67.  
  68. # ---------------------------------------------------
  69. # ДИСПЛЕЙ + LVGL
  70. # ---------------------------------------------------
  71.  
  72. spi:
  73.   clk_pin: 18
  74.   mosi_pin: 17
  75.  
  76. display:
  77.   - platform: mipi_spi
  78.     model: ST7789V
  79.     id: my_display
  80.     dc_pin: 15
  81.     cs_pin: 7
  82.     update_interval: 1s
  83.     rotation: 270
  84.     invert_colors: true
  85.     color_order: BGR
  86.     pixel_mode: 16bit
  87.     dimensions:
  88.       width: 280
  89.       height: 240
  90.       offset_width: 20
  91.       offset_height: 0
  92.     auto_clear_enabled: false
  93.  
  94. lvgl:
  95.   log_level: INFO
  96.  
  97.   pages:
  98.     # ---------------- MAIN PAGE -----------------
  99.     - id: main_page
  100.       bg_color: 0x000000
  101.       widgets:
  102.         - button:
  103.             id: red_button
  104.             align: CENTER
  105.             y: -40
  106.             width: 180
  107.             height: 50
  108.             bg_color: 0xFF0000
  109.             widgets:
  110.               - label:
  111.                   id: battery_label
  112.                   text: "Battery: --"
  113.                   align: CENTER
  114.  
  115.         - button:
  116.             id: green_button
  117.             align: CENTER
  118.             y: 20
  119.             width: 180
  120.             height: 50
  121.             bg_color: 0x00FF00
  122.             widgets:
  123.               - label:
  124.                   id: voltage_label
  125.                   text: "Voltage: --"
  126.                   align: CENTER
  127.                   text_color: 0x000000
  128.  
  129.         - button:
  130.             id: blue_button
  131.             align: CENTER
  132.             y: 80
  133.             width: 180
  134.             height: 50
  135.             bg_color: 0x0000FF
  136.             widgets:
  137.               - label:
  138.                   text: "Lilka LVGL"
  139.                   align: CENTER
  140.                   text_color: 0xFFFFFF
  141.  
  142.     # ---------------- SWITCH PAGE -----------------
  143.     - id: switch_page
  144.       bg_color: 0x000000
  145.       widgets:
  146.         - button:
  147.             id: sw_btn1
  148.             x: 10
  149.             y: 100
  150.             width: 80
  151.             height: 80
  152.             bg_color: 0x303030
  153.             radius: 20
  154.             widgets:
  155.               - label:
  156.                   id: sw_label1
  157.                   text: "Вана"
  158.                   align: CENTER
  159.  
  160.         - button:
  161.             id: sw_btn2
  162.             x: 100
  163.             y: 100
  164.             width: 80
  165.             height: 80
  166.             bg_color: 0x303030
  167.             radius: 20
  168.             widgets:
  169.               - label:
  170.                   id: sw_label2
  171.                   text: "Комора"
  172.                   align: CENTER
  173.  
  174.         - button:
  175.             id: sw_btn3
  176.             x: 190
  177.             y: 100
  178.             width: 80
  179.             height: 80
  180.             bg_color: 0x303030
  181.             radius: 20
  182.             widgets:
  183.               - label:
  184.                   id: sw_label3
  185.                   text: "Кухня"
  186.                   align: CENTER
  187.  
  188. # ---------------------------------------------------
  189. # HA LIGHTS AS SWITCHES
  190. # ---------------------------------------------------
  191.  
  192. switch:
  193.   - platform: homeassistant
  194.     id: sw1
  195.     entity_id: light.tz3000_qewo8dlz_ts0013_light
  196.  
  197.   - platform: homeassistant
  198.     id: sw2
  199.     entity_id: light.tz3000_qewo8dlz_ts0013_light_2
  200.  
  201.   - platform: homeassistant
  202.     id: sw3
  203.     entity_id: light.tz3000_qewo8dlz_ts0013_light_3
  204.  
  205. # ---------------------------------------------------
  206. # ГЛОБАЛЬНІ ЗМІННІ
  207. # ---------------------------------------------------
  208.  
  209. globals:
  210.   - id: current_main_index
  211.     type: int
  212.     initial_value: '0'
  213.  
  214.   - id: current_switch_index
  215.     type: int
  216.     initial_value: '0'
  217.  
  218.   - id: current_page
  219.     type: int
  220.     initial_value: '0'   # 0 = main_page, 1 = switch_page
  221.  
  222. # ---------------------------------------------------
  223. # ФОКУС ДЛЯ СТОРІНОК
  224. # ---------------------------------------------------
  225.  
  226. script:
  227.   - id: update_main_focus
  228.     then:
  229.       - lvgl.widget.update:
  230.           id: red_button
  231.           border_width: !lambda 'return id(current_main_index)==0?3:0;'
  232.       - lvgl.widget.update:
  233.           id: green_button
  234.           border_width: !lambda 'return id(current_main_index)==1?3:0;'
  235.       - lvgl.widget.update:
  236.           id: blue_button
  237.           border_width: !lambda 'return id(current_main_index)==2?3:0;'
  238.  
  239.   - id: update_switch_focus
  240.     then:
  241.       - lvgl.widget.update:
  242.           id: sw_btn1
  243.           border_width: !lambda 'return id(current_switch_index)==0?3:0;'
  244.       - lvgl.widget.update:
  245.           id: sw_btn2
  246.           border_width: !lambda 'return id(current_switch_index)==1?3:0;'
  247.       - lvgl.widget.update:
  248.           id: sw_btn3
  249.           border_width: !lambda 'return id(current_switch_index)==2?3:0;'
  250.  
  251. # ---------------------------------------------------
  252. # КНОПКИ
  253. # ---------------------------------------------------
  254.  
  255. binary_sensor:
  256.   # --- Навігація UP / DOWN тільки на головній сторінці ---
  257.   - platform: gpio
  258.     pin:
  259.       number: 38
  260.       mode: INPUT_PULLUP
  261.       inverted: true
  262.     id: button_up
  263.     on_press:
  264.       - lambda: |-
  265.           if (id(current_page) == 0) {
  266.             id(current_main_index)--;
  267.             if (id(current_main_index) < 0) id(current_main_index) = 2;
  268.           }
  269.       - script.execute: update_main_focus
  270.  
  271.   - platform: gpio
  272.     pin:
  273.       number: 41
  274.       mode: INPUT_PULLUP
  275.       inverted: true
  276.     id: button_down
  277.     on_press:
  278.       - lambda: |-
  279.           if (id(current_page) == 0) {
  280.             id(current_main_index)++;
  281.             if (id(current_main_index) > 2) id(current_main_index) = 0;
  282.           }
  283.       - script.execute: update_main_focus
  284.  
  285.   # --- Ліво/право для сторінки світла ---
  286.   - platform: gpio
  287.     pin:
  288.       number: 39
  289.       mode: INPUT_PULLUP
  290.       inverted: true
  291.     id: button_left
  292.     on_press:
  293.       - lambda: |-
  294.           if (id(current_page) == 1) {
  295.             id(current_switch_index)--;
  296.             if (id(current_switch_index) < 0) id(current_switch_index) = 2;
  297.           }
  298.       - script.execute: update_switch_focus
  299.  
  300.   - platform: gpio
  301.     pin:
  302.       number: 40
  303.       mode: INPUT_PULLUP
  304.       inverted: true
  305.     id: button_right
  306.     on_press:
  307.       - lambda: |-
  308.           if (id(current_page) == 1) {
  309.             id(current_switch_index)++;
  310.             if (id(current_switch_index) > 2) id(current_switch_index) = 0;
  311.           }
  312.       - script.execute: update_switch_focus
  313.  
  314.   # --- A: сторінка вперед ---
  315.   - platform: gpio
  316.     pin:
  317.       number: 5
  318.       mode: INPUT_PULLUP
  319.       inverted: true
  320.     id: button_a
  321.     on_press:
  322.       - lambda: |-
  323.           id(current_page)++;
  324.           if (id(current_page) > 1) id(current_page) = 0;
  325.       - if:
  326.           condition:
  327.             lambda: 'return id(current_page)==0;'
  328.           then:
  329.             - lvgl.page.show: main_page
  330.           else:
  331.             - lvgl.page.show: switch_page
  332.  
  333.   # --- D: сторінка назад ---
  334.   - platform: gpio
  335.     pin:
  336.       number: 9
  337.       mode: INPUT_PULLUP
  338.       inverted: true
  339.     id: button_d
  340.     on_press:
  341.       - lambda: |-
  342.           id(current_page)--;
  343.           if (id(current_page) < 0) id(current_page) = 1;
  344.       - if:
  345.           condition:
  346.             lambda: 'return id(current_page)==0;'
  347.           then:
  348.             - lvgl.page.show: main_page
  349.           else:
  350.             - lvgl.page.show: switch_page
  351.  
  352.   # --- SELECT → toggle вибраного світла ---
  353.   - platform: gpio
  354.     pin:
  355.       number: 0
  356.       mode: INPUT_PULLUP
  357.       inverted: true
  358.     id: button_select
  359.     on_press:
  360.       - lambda: |-
  361.           if (id(current_page) == 1) {
  362.             if (id(current_switch_index) == 0) id(sw1).toggle();
  363.             if (id(current_switch_index) == 1) id(sw2).toggle();
  364.             if (id(current_switch_index) == 2) id(sw3).toggle();
  365.           }
  366.  
  367. # ---------------------------------------------------
  368. # ОНОВЛЕННЯ БАТАРЕЇ
  369. # ---------------------------------------------------
  370.  
  371. interval:
  372.   - interval: 5s
  373.     then:
  374.       - lvgl.label.update:
  375.           id: battery_label
  376.           text: !lambda |-
  377.             static char buf[32];
  378.             int perc = (int) id(battery_level).state;
  379.             if (perc < 0) perc = 0;
  380.             if (perc > 100) perc = 100;
  381.             snprintf(buf, sizeof(buf), "Battery: %d%%", perc);
  382.             return buf;
  383.  
  384.       - lvgl.label.update:
  385.           id: voltage_label
  386.           text: !lambda |-
  387.             static char buf2[32];
  388.             snprintf(buf2, sizeof(buf2), "Voltage: %.2fV", id(battery_voltage).state);
  389.             return buf2;
Advertisement
Add Comment
Please, Sign In to add comment