Missed button presses when using a spi LCD screen

I’m struggling with something that should be simple in principle.
I simplified my project to a simple lcd screen (spi ILI9488_A), binary sensor (gpio input), rotary encoder and a switch (gpio output).
I’ve noticed that when the lcd writes a lot of information like a simple filled rectangle many button presses are lost (for backlight on/off, unusable) but not the encoder pulses.
I’m trying to find to activate an interrupt for the gpio input but I can’t find anything similar in configuration.
No lcd settings improve this behavior like data rate, update interval or auto clear.
I understant that the encoder works with interrupts, so I suppose that something similar could be able for gpio?
Any tips? Thanks!

ESPhome 2025.5.0 on ESP32-S3 N16R8
Display ILI9488_A SPI

Or some of the numerous peripherals Esp32 has. Idea is same.
But afaik, theres no way to use interrupts for binary sensor.

Post your yaml and esphome logs.

yaml

esphome:
  on_boot:
    then:
    - switch.turn_on: lcd1_led

  name: XXXX-s3
  friendly_name: XXXX_S3
  platformio_options:                         
    board_build.arduino.memory_type: qio_opi
    board_upload.maximum_ram_size: 327680
    board_upload.maximum_size: 16777216

esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  flash_size: 16MB
  partitions: "/config/custom_16MB.csv"       
  framework:
    type: arduino

psram:                                       
  mode: octal
  speed: 80MHz


logger:
  logs:
    component: ERROR                         


api:
  encryption:
    key: "XXXXXX"


ota:
  platform: esphome
  password: "XXXX    "


wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password


  ap:
    ssid: "XXXX"
    password: "XXXXX"

captive_portal:


color:
  - id: my_red
    red: 100%
    green: 3%
    blue: 5%

  - id: my_green
    red_int: 0
    green_int: 153
    blue_int: 51


  - id: my_blue
    red_int: 153
    green_int: 204
    blue_int: 255

  - id: my_white
    red_int: 255
    green_int: 255
    blue_int: 255

  - id: my_gray
    red_int: 180
    green_int: 180
    blue_int: 180


spi:
  - id: spi_bus3
    clk_pin: GPIO13                         # (Pin on display - SCK/T_CLK)
    mosi_pin: GPIO11                        # (Pin on display - SDI(MOSI)/T_DIN)
    miso_pin: GPIO12                        # (Pin on display - SDO(MISO)/T_DO)
    interface: spi3
    

display:
  - platform: ili9xxx              
    model: ILI9488_A
    id: pantalla1
    data_rate: 80MHz
    update_interval: 250ms
    dimensions: 480x320
    rotation: 270
    dc_pin: GPIO41
    cs_pin: GPIO39
    reset_pin: GPIO40
    spi_id: spi_bus3
    auto_clear_enabled: True
    pixel_mode: 16bit
    color_order: bgr
    invert_colors: False
    pages:
      - id: page1                              
        lambda: |-
          it.fill(Color::WHITE);
          it.filled_rectangle(0, 200, 320, 480, my_blue);
      - id: page2                               
        lambda: |-
          it.fill(Color::WHITE);
          it.filled_rectangle(0, 300, 320, 480, my_red);


switch:
  - platform: gpio
    pin: GPIO5
    name: "LCD1_LED"
    id: lcd1_led


binary_sensor:
  - platform: gpio
    icon: mdi:button-pointer
    internal: true
    pin:
      number: GPIO08
      mode:
        input: true
        pulldown: true
    name: "Encoder button"
    on_press:
      then:
        - switch.toggle: lcd1_led

sensor:

- platform: rotary_encoder
  name: "Encoder"
  id: encoder
  pin_a: GPIO06
  pin_b: GPIO07
  on_anticlockwise:                                                   

    - display.page.show_previous: pantalla1
    - component.update: pantalla1


  on_clockwise:
    - display.page.show_next: pantalla1
    - component.update: pantalla1

Logs

INFO Starting log output from 192.168.1.104 using esphome API
INFO Successfully connected to XXXX-s3 @ 192.168.1.104 in 7.546s
INFO Successful handshake with XXXX-s3 @ 192.168.1.104 in 1.161s
[12:47:02][I][app:115]: ESPHome version 2025.5.0 compiled on May 28 2025, 12:46:24
[12:47:02][C][wifi:600]: WiFi:
[12:47:02][C][wifi:428]:   Local MAC: XXXX
[12:47:02][C][wifi:433]:   SSID: [redacted]
[12:47:02][C][wifi:436]:   IP Address: 192.168.1.104
[12:47:02][C][wifi:440]:   BSSID: [redacted]
[12:47:02][C][wifi:441]:   Hostname: 'XXX-s3'
[12:47:02][C][wifi:443]:   Signal strength: -38 dB ▂▄▆█
[12:47:02][C][wifi:447]:   Channel: 6
[12:47:02][C][wifi:448]:   Subnet: 255.255.255.0
[12:47:02][C][wifi:449]:   Gateway: 192.168.1.1
[12:47:02][C][wifi:450]:   DNS1: 192.168.1.1
[12:47:02][C][wifi:451]:   DNS2: 0.0.0.0
[12:47:02][C][logger:224]: Logger:
[12:47:02][C][logger:225]:   Max Level: DEBUG
[12:47:02][C][logger:226]:   Initial Level: DEBUG
[12:47:02][C][logger:228]:   Log Baud Rate: 115200
[12:47:02][C][logger:229]:   Hardware UART: USB_CDC
[12:47:02][C][logger:233]:   Task Log Buffer Size: 768
[12:47:02][C][logger:238]:   Level for 'component': ERROR
[12:47:03][C][spi:068]: SPI bus:
[12:47:03][C][spi:069]:   CLK Pin: GPIO13
[12:47:03][C][spi:070]:   SDI Pin: GPIO12
[12:47:03][C][spi:071]:   SDO Pin: GPIO11
[12:47:03][C][spi:076]:   Using HW SPI: FSPI
[12:47:04][C][ili9xxx:091]: ili9xxx
[12:47:04][C][ili9xxx:091]:   Rotations: 270 °
[12:47:04][C][ili9xxx:091]:   Dimensions: 320px x 480px
[12:47:04][C][ili9xxx:092]:   Width Offset: 0
[12:47:04][C][ili9xxx:093]:   Height Offset: 0
[12:47:04][C][ili9xxx:099]:   Color mode: 16bit
[12:47:04][C][ili9xxx:108]:   Data rate: 80MHz
[12:47:04][C][ili9xxx:110]:   Reset Pin: GPIO40
[12:47:04][C][ili9xxx:111]:   CS Pin: GPIO39
[12:47:04][C][ili9xxx:112]:   DC Pin: GPIO41
[12:47:04][C][ili9xxx:114]:   Color order: BGR
[12:47:04][C][ili9xxx:115]:   Swap_xy: YES
[12:47:04][C][ili9xxx:116]:   Mirror_x: NO
[12:47:04][C][ili9xxx:117]:   Mirror_y: NO
[12:47:04][C][ili9xxx:118]:   Invert colors: NO
[12:47:04][C][ili9xxx:123]:   Update Interval: 0.2s
[12:47:04][C][switch.gpio:068]: GPIO Switch 'LCD1_LED'
[12:47:04][C][switch.gpio:091]:   Restore Mode: always OFF
[12:47:04][C][switch.gpio:031]:   Pin: GPIO5
[12:47:05][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Encoder button'
[12:47:05][C][gpio.binary_sensor:016]:   Pin: GPIO8
[12:47:06][C][psram:018]: PSRAM:
[12:47:06][C][psram:033]:   Available: YES
[12:47:06][C][psram:040]:   Size: 8192 KB
[12:47:06][C][rotary_encoder:164]: Rotary Encoder 'Encoder'
[12:47:06][C][rotary_encoder:164]:   State Class: ''
[12:47:06][C][rotary_encoder:164]:   Unit of Measurement: 'steps'
[12:47:06][C][rotary_encoder:164]:   Accuracy Decimals: 0
[12:47:06][C][rotary_encoder:164]:   Icon: 'mdi:rotate-right'
[12:47:06][C][rotary_encoder:165]:   Pin A: GPIO6
[12:47:06][C][rotary_encoder:166]:   Pin B: GPIO7
[12:47:06][C][rotary_encoder:180]:   Restore Mode: Restore (Defaults to zero)
[12:47:06][C][rotary_encoder:184]:   Resolution: 1 Pulse Per Cycle
[12:47:07][C][captive_portal:089]: Captive Portal:
[12:47:08][C][mdns:120]: mDNS:
[12:47:08][C][mdns:121]:   Hostname: XXXX-s3
[12:47:08][C][esphome.ota:073]: Over-The-Air updates:
[12:47:08][C][esphome.ota:074]:   Address: XXXX-s3.local:3232
[12:47:08][C][esphome.ota:075]:   Version: 2
[12:47:08][C][esphome.ota:078]:   Password configured
[12:47:09][C][safe_mode:018]: Safe Mode:
[12:47:09][C][safe_mode:020]:   Boot considered successful after 60 seconds
[12:47:09][C][safe_mode:021]:   Invoke after 10 boot attempts
[12:47:09][C][safe_mode:023]:   Remain in safe mode for 300 seconds
[12:47:09][C][api:170]: API Server:
[12:47:09][C][api:171]:   Address: XXXX-s3.local:6053
[12:47:09][C][api:173]:   Using noise encryption: YES
[12:47:12][D][sensor:094]: 'Encoder': Sending state 157.00000 steps with 0 decimals of accuracy
[12:47:13][D][sensor:094]: 'Encoder': Sending state 158.00000 steps with 0 decimals of accuracy
[12:47:14][D][sensor:094]: 'Encoder': Sending state 159.00000 steps with 0 decimals of accuracy
[12:47:15][D][sensor:094]: 'Encoder': Sending state 160.00000 steps with 0 decimals of accuracy
[12:47:17][D][sensor:094]: 'Encoder': Sending state 161.00000 steps with 0 decimals of accuracy
[12:47:19][D][binary_sensor:036]: 'Encoder button': Sending state OFF
[12:47:19][D][binary_sensor:036]: 'Encoder button': Sending state ON
[12:47:19][D][switch:020]: 'LCD1_LED' Toggling OFF.
[12:47:19][D][switch:055]: 'LCD1_LED': Sending state OFF
[12:47:21][D][binary_sensor:036]: 'Encoder button': Sending state OFF
[12:47:22][D][binary_sensor:036]: 'Encoder button': Sending state ON
[12:47:22][D][switch:020]: 'LCD1_LED' Toggling ON.
[12:47:22][D][switch:055]: 'LCD1_LED': Sending state ON
[12:47:22][D][binary_sensor:036]: 'Encoder button': Sending state OFF
[12:47:23][D][binary_sensor:036]: 'Encoder button': Sending state ON
[12:47:23][D][switch:020]: 'LCD1_LED' Toggling OFF.
[12:47:23][D][switch:055]: 'LCD1_LED': Sending state OFF
[12:47:23][D][binary_sensor:036]: 'Encoder button': Sending state OFF
[12:47:24][D][binary_sensor:036]: 'Encoder button': Sending state ON
[12:47:24][D][switch:020]: 'LCD1_LED' Toggling ON.
[12:47:24][D][switch:055]: 'LCD1_LED': Sending state ON
[12:47:25][D][binary_sensor:036]: 'Encoder button': Sending state OFF
[12:47:26][D][binary_sensor:036]: 'Encoder button': Sending state ON
[12:47:26][D][switch:020]: 'LCD1_LED' Toggling OFF.
[12:47:26][D][switch:055]: 'LCD1_LED': Sending state OFF
[12:47:27][D][binary_sensor:036]: 'Encoder button': Sending state OFF
[12:47:28][D][binary_sensor:036]: 'Encoder button': Sending state ON
[12:47:28][D][switch:020]: 'LCD1_LED' Toggling ON.
[12:47:28][D][switch:055]: 'LCD1_LED': Sending state ON
[12:47:30][D][sensor:094]: 'Encoder': Sending state 162.00000 steps with 0 decimals of accuracy
[12:47:32][D][sensor:094]: 'Encoder': Sending state 163.00000 steps with 0 decimals of accuracy
[12:47:33][D][sensor:094]: 'Encoder': Sending state 164.00000 steps with 0 decimals of accuracy
[12:47:34][D][sensor:094]: 'Encoder': Sending state 165.00000 steps with 0 decimals of accuracy
[12:47:36][D][sensor:094]: 'Encoder': Sending state 166.00000 steps with 0 decimals of accuracy
[12:47:39][D][binary_sensor:036]: 'Encoder button': Sending state OFF
[12:47:39][D][binary_sensor:036]: 'Encoder button': Sending state ON
[12:47:39][D][switch:020]: 'LCD1_LED' Toggling OFF.
[12:47:39][D][switch:055]: 'LCD1_LED': Sending state OFF
[12:47:40][D][binary_sensor:036]: 'Encoder button': Sending state OFF
[12:47:40][D][binary_sensor:036]: 'Encoder button': Sending state ON
[12:47:40][D][switch:020]: 'LCD1_LED' Toggling ON.
[12:47:40][D][switch:055]: 'LCD1_LED': Sending state ON
[12:47:52][I][safe_mode:041]: Boot seems successful; resetting boot loop counter
[12:47:52][D][esp32.preferences:114]: Saving 2 preferences to flash...
[12:47:52][D][esp32.preferences:143]: Saving 2 preferences to flash: 0 cached, 2 written, 0 failed

Thanks for your reply

The log doesn’t present the situation where Esp is “blocked”.
Try with debug if you can get some useful info like loop time.

I can’t see nothing except a high loop time.
I can try to force the CPU speed to 240Mhz but I think this is not the problem. Misses 3 or 4 button push each 5.

INFO ESPHome 2025.5.0
INFO Reading configuration /config/XXXX-s3.yaml...
INFO Starting log output from 192.168.1.104 using esphome API
INFO Successfully connected to XXXX-s3 @ 192.168.1.104 in 0.030s
INFO Successful handshake with XXXX-s3 @ 192.168.1.104 in 1.086s
[21:53:34][I][app:115]: ESPHome version 2025.5.0 compiled on May 28 2025, 21:50:11
[21:53:34][C][wifi:600]: WiFi:
[21:53:34][C][wifi:428]:   Local MAC: XXXXX
[21:53:34][C][wifi:433]:   SSID: [redacted]
[21:53:34][C][wifi:436]:   IP Address: 192.168.1.104
[21:53:34][C][wifi:440]:   BSSID: [redacted]
[21:53:34][C][wifi:441]:   Hostname: 'XXXX-s3'
[21:53:34][C][wifi:443]:   Signal strength: -36 dB ▂▄▆█
[21:53:34][C][wifi:447]:   Channel: 6
[21:53:34][C][wifi:448]:   Subnet: 255.255.255.0
[21:53:34][C][wifi:449]:   Gateway: 192.168.1.1
[21:53:34][C][wifi:450]:   DNS1: 192.168.1.1
[21:53:34][C][wifi:451]:   DNS2: 0.0.0.0
[21:53:35][C][logger:224]: Logger:
[21:53:35][C][logger:225]:   Max Level: DEBUG
[21:53:35][C][logger:226]:   Initial Level: DEBUG
[21:53:35][C][logger:228]:   Log Baud Rate: 115200
[21:53:35][C][logger:229]:   Hardware UART: USB_CDC
[21:53:35][C][logger:233]:   Task Log Buffer Size: 768
[21:53:35][C][logger:238]:   Level for 'component': ERROR
[21:53:35][C][spi:068]: SPI bus:
[21:53:35][C][spi:069]:   CLK Pin: GPIO13
[21:53:35][C][spi:070]:   SDI Pin: GPIO12
[21:53:35][C][spi:071]:   SDO Pin: GPIO11
[21:53:35][C][spi:076]:   Using HW SPI: FSPI
[21:53:36][C][ili9xxx:091]: ili9xxx
[21:53:36][C][ili9xxx:091]:   Rotations: 270 °
[21:53:36][C][ili9xxx:091]:   Dimensions: 320px x 480px
[21:53:36][C][ili9xxx:092]:   Width Offset: 0
[21:53:36][C][ili9xxx:093]:   Height Offset: 0
[21:53:36][C][ili9xxx:099]:   Color mode: 16bit
[21:53:36][C][ili9xxx:108]:   Data rate: 80MHz
[21:53:36][C][ili9xxx:110]:   Reset Pin: GPIO40
[21:53:36][C][ili9xxx:111]:   CS Pin: GPIO39
[21:53:36][C][ili9xxx:112]:   DC Pin: GPIO41
[21:53:36][C][ili9xxx:114]:   Color order: BGR
[21:53:36][C][ili9xxx:115]:   Swap_xy: YES
[21:53:36][C][ili9xxx:116]:   Mirror_x: NO
[21:53:36][C][ili9xxx:117]:   Mirror_y: NO
[21:53:36][C][ili9xxx:118]:   Invert colors: NO
[21:53:36][C][ili9xxx:123]:   Update Interval: 0.2s
[21:53:37][C][switch.gpio:068]: GPIO Switch 'LCD1_LED'
[21:53:37][C][switch.gpio:091]:   Restore Mode: always OFF
[21:53:37][C][switch.gpio:031]:   Pin: GPIO5
[21:53:37][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Encoder button'
[21:53:37][C][gpio.binary_sensor:016]:   Pin: GPIO8
[21:53:38][C][psram:018]: PSRAM:
[21:53:38][C][psram:033]:   Available: YES
[21:53:38][C][psram:040]:   Size: 8192 KB
[21:53:39][D][sensor:094]: 'Heap Free': Sending state 272904.00000 B with 0 decimals of accuracy
[21:53:39][D][sensor:094]: 'Loop Time': Sending state 518.00000 ms with 0 decimals of accuracy
[21:53:39][D][sensor:094]: 'CPU Frequency': Sending state 160000000.00000 Hz with 0 decimals of accuracy
[21:53:39][D][sensor:094]: 'Heap Max Block': Sending state 258036.00000 B with 0 decimals of accuracy
[21:53:39][D][sensor:094]: 'Free PSRAM': Sending state 8066503.00000 B with 0 decimals of accuracy
[21:53:39][C][rotary_encoder:164]: Rotary Encoder 'Encoder'
[21:53:39][C][rotary_encoder:164]:   State Class: ''
[21:53:39][C][rotary_encoder:164]:   Unit of Measurement: 'steps'
[21:53:39][C][rotary_encoder:164]:   Accuracy Decimals: 0
[21:53:39][C][rotary_encoder:164]:   Icon: 'mdi:rotate-right'
[21:53:39][C][rotary_encoder:165]:   Pin A: GPIO6
[21:53:39][C][rotary_encoder:166]:   Pin B: GPIO7
[21:53:39][C][rotary_encoder:180]:   Restore Mode: Restore (Defaults to zero)
[21:53:39][C][rotary_encoder:184]:   Resolution: 1 Pulse Per Cycle
[21:53:40][C][captive_portal:089]: Captive Portal:
[21:53:40][C][mdns:120]: mDNS:
[21:53:40][C][mdns:121]:   Hostname: XXXX-s3
[21:53:41][C][esphome.ota:073]: Over-The-Air updates:
[21:53:41][C][esphome.ota:074]:   Address: XXXX-s3.local:3232
[21:53:41][C][esphome.ota:075]:   Version: 2
[21:53:41][C][esphome.ota:078]:   Password configured
[21:53:41][C][safe_mode:018]: Safe Mode:
[21:53:41][C][safe_mode:020]:   Boot considered successful after 60 seconds
[21:53:41][C][safe_mode:021]:   Invoke after 10 boot attempts
[21:53:41][C][safe_mode:023]:   Remain in safe mode for 300 seconds
[21:53:42][C][api:170]: API Server:
[21:53:42][C][api:171]:   Address: XXXX-s3.local:6053
[21:53:42][C][api:173]:   Using noise encryption: YES
[21:53:42][C][debug:022]: Debug component:
[21:53:42][C][debug:024]:   Device info 'Device Info'
[21:53:42][C][debug:024]:     Icon: 'mdi:chip'
[21:53:42][C][debug:027]:   Free space on heap 'Heap Free'
[21:53:42][C][debug:027]:     State Class: ''
[21:53:42][C][debug:027]:     Unit of Measurement: 'B'
[21:53:42][C][debug:027]:     Accuracy Decimals: 0
[21:53:42][C][debug:027]:     Icon: 'mdi:counter'
[21:53:42][C][debug:028]:   Largest free heap block 'Heap Max Block'
[21:53:42][C][debug:028]:     State Class: ''
[21:53:42][C][debug:028]:     Unit of Measurement: 'B'
[21:53:42][C][debug:028]:     Accuracy Decimals: 0
[21:53:42][C][debug:028]:     Icon: 'mdi:counter'
[21:53:42][C][debug:029]:   CPU frequency 'CPU Frequency'
[21:53:42][C][debug:029]:     State Class: ''
[21:53:42][C][debug:029]:     Unit of Measurement: 'Hz'
[21:53:42][C][debug:029]:     Accuracy Decimals: 0
[21:53:42][C][debug:029]:     Icon: 'mdi:speedometer'
[21:53:42][D][debug:037]: ESPHome version 2025.5.0
[21:53:42][D][debug:041]: Free Heap Size: 264388 bytes
[21:53:42][D][debug:159]: Flash Chip: Size=16384kB Speed=80MHz Mode=QIO
[21:53:42][D][debug:179]: Chip: Model=ESP32-S3, Features=2.4GHz WiFi, BLE,  Cores=2, Revision=0
[21:53:42][D][debug:187]: CPU Frequency: 160 MHz
[21:53:42][D][debug:192]: Framework: Arduino
[21:53:42][D][debug:202]: ESP-IDF Version: v4.4.2
[21:53:42][D][debug:207]: EFuse MAC: 30:ED:A0:14:40:EC
[21:53:42][D][debug:077]: Reset Reason: software via esp_restart
[21:53:42][D][debug:105]: Wakeup Reason: undefined
[21:53:42][D][text_sensor:064]: 'Device Info': Sending state '2025.5.0|Flash: 16384kB Speed:80MHz Mode:QIO|Chip: ESP32-S3 Features:2.4GHz WiFi, BLE,  Cores:2 Revision:0|CPU Frequency: 160 MHz|Framework: Arduino|ESP-IDF: v4.4.2|EFuse MAC: 30:ED:A0:14:40:EC|Reset: software via esp_restart|Wakeup: undefined'
[21:53:42][D][debug:077]: Reset Reason: software via esp_restart
[21:53:42][D][text_sensor:064]: 'Reset Reason': Sending state 'software via esp_restart'
[21:53:42][C][debug:110]: Partition table:
[21:53:42][C][debug:111]:   Name         Type Subtype  Address    Size      
[21:53:42][C][debug:116]:   nvs          1    2        0x00009000 0x00005000
[21:53:42][C][debug:116]:   otadata      1    0        0x0000E000 0x00002000
[21:53:42][C][debug:116]:   app0         0    16       0x00010000 0x007F0000
[21:53:42][C][debug:116]:   app1         0    17       0x00800000 0x007F0000
[21:53:42][C][debug:116]:   eeprom       1    153      0x00FF0000 0x00001000
[21:53:42][C][debug:116]:   spiffs       1    130      0x00FF1000 0x0000F000
[21:53:44][D][sensor:094]: 'Heap Free': Sending state 272572.00000 B with 0 decimals of accuracy
[21:53:44][D][sensor:094]: 'Loop Time': Sending state 562.00000 ms with 0 decimals of accuracy
[21:53:44][D][sensor:094]: 'CPU Frequency': Sending state 160000000.00000 Hz with 0 decimals of accuracy
[21:53:44][D][sensor:094]: 'Heap Max Block': Sending state 258036.00000 B with 0 decimals of accuracy
[21:53:44][D][sensor:094]: 'Free PSRAM': Sending state 8066503.00000 B with 0 decimals of accuracy
[21:53:49][D][sensor:094]: 'Heap Free': Sending state 272572.00000 B with 0 decimals of accuracy
[21:53:49][D][sensor:094]: 'Loop Time': Sending state 505.00000 ms with 0 decimals of accuracy
[21:53:49][D][sensor:094]: 'CPU Frequency': Sending state 160000000.00000 Hz with 0 decimals of accuracy
[21:53:49][D][sensor:094]: 'Heap Max Block': Sending state 258036.00000 B with 0 decimals of accuracy
[21:53:49][D][sensor:094]: 'Free PSRAM': Sending state 8066503.00000 B with 0 decimals of accuracy
[21:53:51][D][binary_sensor:036]: 'Encoder button': Sending state OFF
[21:53:52][D][binary_sensor:036]: 'Encoder button': Sending state ON
[21:53:52][D][switch:020]: 'LCD1_LED' Toggling OFF.
[21:53:52][D][switch:055]: 'LCD1_LED': Sending state OFF
[21:53:54][D][sensor:094]: 'Heap Free': Sending state 272572.00000 B with 0 decimals of accuracy
[21:53:54][D][sensor:094]: 'Loop Time': Sending state 505.00000 ms with 0 decimals of accuracy
[21:53:54][D][sensor:094]: 'CPU Frequency': Sending state 160000000.00000 Hz with 0 decimals of accuracy
[21:53:54][D][sensor:094]: 'Heap Max Block': Sending state 258036.00000 B with 0 decimals of accuracy
[21:53:54][D][sensor:094]: 'Free PSRAM': Sending state 8066503.00000 B with 0 decimals of accuracy
[21:53:55][D][binary_sensor:036]: 'Encoder button': Sending state OFF
[21:53:55][D][binary_sensor:036]: 'Encoder button': Sending state ON
[21:53:55][D][switch:020]: 'LCD1_LED' Toggling ON.
[21:53:55][D][switch:055]: 'LCD1_LED': Sending state ON
[21:53:57][D][sensor:094]: 'Encoder': Sending state 167.00000 steps with 0 decimals of accuracy
[21:53:59][D][sensor:094]: 'Encoder': Sending state 168.00000 steps with 0 decimals of accuracy
[21:53:59][D][binary_sensor:036]: 'Encoder button': Sending state OFF
[21:54:00][D][binary_sensor:036]: 'Encoder button': Sending state ON
[21:54:00][D][switch:020]: 'LCD1_LED' Toggling OFF.
[21:54:00][D][switch:055]: 'LCD1_LED': Sending state OFF
[21:54:00][D][sensor:094]: 'Heap Free': Sending state 269260.00000 B with 0 decimals of accuracy
[21:54:00][D][sensor:094]: 'Loop Time': Sending state 970.00000 ms with 0 decimals of accuracy
[21:54:00][D][sensor:094]: 'CPU Frequency': Sending state 160000000.00000 Hz with 0 decimals of accuracy
[21:54:00][D][sensor:094]: 'Heap Max Block': Sending state 258036.00000 B with 0 decimals of accuracy
[21:54:00][D][sensor:094]: 'Free PSRAM': Sending state 8066503.00000 B with 0 decimals of accuracy
[21:54:00][D][binary_sensor:036]: 'Encoder button': Sending state OFF
[21:54:01][D][binary_sensor:036]: 'Encoder button': Sending state ON
[21:54:01][D][switch:020]: 'LCD1_LED' Toggling ON.
[21:54:01][D][switch:055]: 'LCD1_LED': Sending state ON
[21:54:05][D][sensor:094]: 'Encoder': Sending state 169.00000 steps with 0 decimals of accuracy
[21:54:05][D][sensor:094]: 'Heap Free': Sending state 272552.00000 B with 0 decimals of accuracy
[21:54:05][D][sensor:094]: 'Loop Time': Sending state 969.00000 ms with 0 decimals of accuracy
[21:54:05][D][sensor:094]: 'CPU Frequency': Sending state 160000000.00000 Hz with 0 decimals of accuracy
[21:54:05][D][sensor:094]: 'Heap Max Block': Sending state 258036.00000 B with 0 decimals of accuracy
[21:54:05][D][sensor:094]: 'Free PSRAM': Sending state 8066503.00000 B with 0 decimals of accuracy
[21:54:06][D][esp32.preferences:114]: Saving 1 preferences to flash...
[21:54:06][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[21:54:10][D][sensor:094]: 'Heap Free': Sending state 272572.00000 B with 0 decimals of accuracy
[21:54:10][D][sensor:094]: 'Loop Time': Sending state 484.00000 ms with 0 decimals of accuracy
[21:54:10][D][sensor:094]: 'CPU Frequency': Sending state 160000000.00000 Hz with 0 decimals of accuracy
[21:54:10][D][sensor:094]: 'Heap Max Block': Sending state 258036.00000 B with 0 decimals of accuracy
[21:54:10][D][sensor:094]: 'Free PSRAM': Sending state 8066503.00000 B with 0 decimals of accuracy
[21:54:16][D][sensor:094]: 'Heap Free': Sending state 272572.00000 B with 0 decimals of accuracy
[21:54:16][D][sensor:094]: 'Loop Time': Sending state 483.00000 ms with 0 decimals of accuracy
[21:54:16][D][sensor:094]: 'CPU Frequency': Sending state 160000000.00000 Hz with 0 decimals of accuracy
[21:54:16][D][sensor:094]: 'Heap Max Block': Sending state 258036.00000 B with 0 decimals of accuracy
[21:54:16][D][sensor:094]: 'Free PSRAM': Sending state 8066503.00000 B with 0 decimals of accuracy

That’s enough to explain your problem with binary sensor. Ideally loop time should be <20ms vs yours 500-1000ms.
But I can’t see the reason for that on your log. Display doesn’t even have one line there…

The update interval of 250ms on the display won’t help, especially since you’re redrawing the whole screen every update, and the ILI9488 is a particularly slow display. Basically you are using the entire CPU time just writing to the display.

You would be better off using LVGL which will only redraw what changes, and only as required.

I’m aware that SPI LCD are slow, in fact I’m using 2 screens (not in this simplified example). But the update interval is not important for me, all the sensors are updated every 10 seconds and the screen information every 1s.
All works well including the rotary encoder to navigate between pages except the button to turn off and on the backlight. It is awkward not having the possibility to use interrupts in gpio for that simple thing…
I didn’t know about the existence of the LVGL library!, I thought there is no such thing in ESPhome, I will try!. Thanks!
BTW I guess I’ll eventually swap out the screens or improvise a timer wit the rotary encoder to turn on the backlight.

Thanks for the responses!

I’m checking the LVGL documentation and seems do not have support for animated gifs.
In my device I only use a small wave animated gif to show the water level and a value in percent, for that reason I swap to a N16R8.
I will keep the LVGL documentation for future projects because is really nice.

I agree.
Try with pulse_counter total. Use on_value to get trigger.
Never tried, but might work. Pulse counter uses PCNT peripheral.

https://esphome-docs.pages.dev/components/lvgl/widgets/#animimg

Nice! I didn’t expect this could be a widget. Let’s try it.
Thanks!

BTW this work like a charm:
Check the value each second and then switch it.

  - platform: pulse_counter
    pin:
      number: GPIO08
      inverted: true
      mode:
        input: true
        pullup: true
    name: "Encoder button"
    count_mode: 
      rising_edge: DISABLE
      falling_edge: INCREMENT
    use_pcnt: True
    update_interval: 1s
    on_value_range: 
      above: 1
      then:
        - switch.toggle: lcd1_led

Nice, now you have your “interrupt button”.
Try to work on display anyway, 1s loop time is not preferable in any case.