nene1234

lilka 1 disp

Nov 16th, 2025 (edited)
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 7.29 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.     id: battery_voltage
  49.     name: "Battery Voltage"
  50.     icon: "mdi:lightning-bolt"
  51.     update_interval: 10s
  52.     attenuation: 12db
  53.     filters:
  54.       - multiply: 1.33
  55.    
  56.   - platform: template
  57.     id: battery_level
  58.     name: "Battery Level"
  59.     icon: "mdi:battery"
  60.     unit_of_measurement: "%"
  61.     accuracy_decimals: 0
  62.     update_interval: 10s
  63.     lambda: |-
  64.       float voltage = id(battery_voltage).state;
  65.       float percent = (voltage - 3.0) / (4.2 - 3.0) * 100.0;
  66.       if (percent > 100) percent = 100;
  67.       if (percent < 0) percent = 0;
  68.       return percent;
  69.  
  70. # ---------------------------------------------------
  71. # ДИСПЛЕЙ ST7789V + LVGL
  72. # ---------------------------------------------------
  73.  
  74. spi:
  75.   clk_pin: 18
  76.   mosi_pin: 17
  77.  
  78. display:
  79.   - platform: mipi_spi
  80.     model: ST7789V
  81.     id: my_display
  82.     dc_pin: 15
  83.     cs_pin: 7
  84.     update_interval: 1s
  85.     rotation: 270
  86.     invert_colors: true
  87.     color_order: BGR
  88.     pixel_mode: 16bit
  89.     dimensions:
  90.       width: 280
  91.       height: 240
  92.       offset_width: 20
  93.       offset_height: 0
  94.     auto_clear_enabled: false
  95.  
  96. lvgl:
  97.   log_level: INFO
  98.   style_definitions:
  99.     - id: default_style
  100.       bg_color: 0x000000
  101.       text_color: 0xFFFFFF
  102.     - id: focused_style
  103.       border_color: 0xFFFFFF
  104.       border_width: 3
  105.  
  106.   pages:
  107.     - id: main_page
  108.       bg_color: 0x000000
  109.       widgets:
  110.         - button:
  111.             id: red_button
  112.             align: CENTER
  113.             y: -40
  114.             width: 180
  115.             height: 50
  116.             bg_color: 0xFF0000
  117.             widgets:
  118.               - label:
  119.                   id: battery_label
  120.                   text: "Battery: --"
  121.                   align: CENTER
  122.  
  123.         - button:
  124.             id: green_button
  125.             align: CENTER
  126.             y: 20
  127.             width: 180
  128.             height: 50
  129.             bg_color: 0x00FF00
  130.             widgets:
  131.               - label:
  132.                   id: voltage_label
  133.                   text: "Voltage: --"
  134.                   align: CENTER
  135.                   text_color: 0x000000
  136.  
  137.         - button:
  138.             id: blue_button
  139.             align: CENTER
  140.             y: 80
  141.             width: 180
  142.             height: 50
  143.             bg_color: 0x0000FF
  144.             widgets:
  145.               - label:
  146.                   text: "Lilka LVGL"
  147.                   align: CENTER
  148.                   text_color: 0xFFFFFF
  149.  
  150. # ---------------------------------------------------
  151. # ГЛОБАЛЬНІ ЗМІННІ ТА СКРИПТ ФОКУСУ
  152. # ---------------------------------------------------
  153.  
  154. globals:
  155.   - id: current_button_index
  156.     type: int
  157.     restore_value: no
  158.     initial_value: '0'
  159.  
  160. script:
  161.   - id: update_focus
  162.     then:
  163.       - lvgl.widget.update:
  164.           id: red_button
  165.           border_width: !lambda 'return id(current_button_index) == 0 ? 3 : 0;'
  166.       - lvgl.widget.update:
  167.           id: green_button
  168.           border_width: !lambda 'return id(current_button_index) == 1 ? 3 : 0;'
  169.       - lvgl.widget.update:
  170.           id: blue_button
  171.           border_width: !lambda 'return id(current_button_index) == 2 ? 3 : 0;'
  172.  
  173. # ---------------------------------------------------
  174. # КНОПКИ (ВСІ ВИДИМІ У HOME ASSISTANT)
  175. # ---------------------------------------------------
  176.  
  177. binary_sensor:
  178.  # D-Pad
  179.   - platform: gpio
  180.     pin:
  181.       number: 38
  182.       mode: INPUT_PULLUP
  183.       inverted: true
  184.     id: button_up
  185.     name: "Button Up"
  186.     icon: "mdi:arrow-up-circle"
  187.     filters:
  188.       - delayed_on_off: 50ms
  189.     on_press:
  190.       - lambda: |-
  191.           id(current_button_index)--;
  192.           if (id(current_button_index) < 0) id(current_button_index) = 2;
  193.       - script.execute: update_focus
  194.  
  195.   - platform: gpio
  196.     pin:
  197.       number: 41
  198.       mode: INPUT_PULLUP
  199.       inverted: true
  200.     id: button_down
  201.     name: "Button Down"
  202.     icon: "mdi:arrow-down-circle"
  203.     filters:
  204.       - delayed_on_off: 50ms
  205.     on_press:
  206.       - lambda: |-
  207.           id(current_button_index)++;
  208.           if (id(current_button_index) > 2) id(current_button_index) = 0;
  209.       - script.execute: update_focus
  210.  
  211.   - platform: gpio
  212.     pin:
  213.       number: 39
  214.       mode: INPUT_PULLUP
  215.       inverted: true
  216.     id: button_left
  217.     name: "Button Left"
  218.     icon: "mdi:arrow-left-circle"
  219.     filters:
  220.       - delayed_on_off: 50ms
  221.  
  222.   - platform: gpio
  223.     pin:
  224.       number: 40
  225.       mode: INPUT_PULLUP
  226.       inverted: true
  227.     id: button_right
  228.     name: "Button Right"
  229.     icon: "mdi:arrow-right-circle"
  230.     filters:
  231.       - delayed_on_off: 50ms
  232.  
  233.   # A B C D
  234.   - platform: gpio
  235.     pin:
  236.       number: 5
  237.       mode: INPUT_PULLUP
  238.       inverted: true
  239.     id: button_a
  240.     name: "Button A"
  241.     icon: "mdi:alpha-a-circle"
  242.     filters:
  243.       - delayed_on_off: 50ms
  244.  
  245.   - platform: gpio
  246.     pin:
  247.       number: 6
  248.       mode: INPUT_PULLUP
  249.       inverted: true
  250.     id: button_b
  251.     name: "Button B"
  252.     icon: "mdi:alpha-b-circle"
  253.     filters:
  254.       - delayed_on_off: 50ms
  255.  
  256.   - platform: gpio
  257.     pin:
  258.       number: 10
  259.       mode: INPUT_PULLUP
  260.       inverted: true
  261.     id: button_c
  262.     name: "Button C"
  263.     icon: "mdi:alpha-c-circle"
  264.     filters:
  265.       - delayed_on_off: 50ms
  266.  
  267.   - platform: gpio
  268.     pin:
  269.       number: 9
  270.       mode: INPUT_PULLUP
  271.       inverted: true
  272.     id: button_d
  273.     name: "Button D"
  274.     icon: "mdi:alpha-d-circle"
  275.     filters:
  276.       - delayed_on_off: 50ms
  277.  
  278.   # Start / Select
  279.   - platform: gpio
  280.     pin:
  281.       number: 4
  282.       mode: INPUT_PULLUP
  283.       inverted: true
  284.     id: button_start
  285.     name: "Button Start"
  286.     icon: "mdi:play-circle"
  287.     filters:
  288.       - delayed_on_off: 50ms
  289.  
  290.   - platform: gpio
  291.     pin:
  292.       number: 0
  293.       mode: INPUT_PULLUP
  294.       inverted: true
  295.     id: button_select
  296.     name: "Button Select"
  297.     icon: "mdi:checkbox-marked-circle"
  298.     filters:
  299.       - delayed_on_off: 50ms
  300.  
  301. # ---------------------------------------------------
  302. # ОНОВЛЕННЯ СТАТУСУ БАТАРЕЇ НА ЕКРАНІ
  303. # ---------------------------------------------------
  304.  
  305. interval:
  306.   - interval: 5s
  307.     then:
  308.       - lvgl.label.update:
  309.           id: battery_label
  310.           text: !lambda |-
  311.             return std::string("Battery: ") + to_string((int)id(battery_level).state) + "%";
  312.  
  313.       - lvgl.label.update:
  314.           id: voltage_label
  315.           text: !lambda |-
  316.             char buf[20];
  317.             snprintf(buf, sizeof(buf), "Voltage: %.2fV", id(battery_voltage).state);
  318.             return std::string(buf);
Advertisement
Add Comment
Please, Sign In to add comment