Turn display off (not via light/ledc component) to prevent burn-in

I’ve got a CYD display. When I set it up to report temperature overnight to homeassistant (so nothing that needs the display on), and configured the display background LED to turn off after a minute of inactivity, and then came back the next morning, I’ve noticed that the QR code of the LVGL hello world screen was still somewhat visible, i.e. seemed to be burnt in. This went away after a while but it made me realize that apparently the display needs to be turned off (See “8.2.18. Display OFF (28h)” in data sheet), BESIDES the background light to be turned off. So

interval:
  - interval: 30s
    then:
      - if:
          condition:
            - lambda: |-
                return !id(recent_touch);
          then: 
            light.turn_off:
              id: backlight
          else:
            - lambda: |-
                id(recent_touch) = false;

seems not to be enough to protect the display against burning in

How can I send the display off command to the display as well?

(Part of) My config is:

spi:
  - id: tft
    clk_pin: GPIO14
    mosi_pin: GPIO13
    miso_pin: GPIO12
display:
  - platform: mipi_spi
    model: ESP32-2432S028
    color_order: rgb
    spi_id: tft
    dimensions: 320x240
    update_interval: never # Needed for lvgl
light:
  - platform: monochromatic
    output: backlight_pwm
    name: Display Backlight
    id: backlight
    restore_mode: ALWAYS_ON
output:
  - platform: ledc
    pin: GPIO21
    id: backlight_pwm

I’m not sure if you can give direct commands like 0x28 or 0x10 on lambda, you can try though.

But in any case you can fill the screen:

// Turn the whole display off
      it.fill(COLOR_OFF);

What works for me is using a binary sensor to turn on the screen when touched, and automatically turn it off after a set amount of time (20s):

#Example configuration entry - Binary Sensor for Touch Detection
binary_sensor:
  - platform: touchscreen
    name: touch_pltscreen
    publish_initial_state: True
    entity_category: CONFIG
    x_min: 10
    x_max: 380  # Reduced for better reliability - experiment with values
    y_min: 40
    y_max: 290 # Reduced for better reliability - experiment with values
    on_press:
      then:
        - logger.log: "Touchscreen has been pressed, turning it ON (binary sensor)"
        - output.turn_on: backlight
        - delay: 20s
        - logger.log: "Timer of 20s has ended, turning the Touchscreen OFF (binary sensor)"
        - output.turn_off: backlight

output:
  - platform: gpio
    pin: GPIO12
    id: backlight

## Allow HA to see and controll the Backlight of the Touchscreen, it might come in handy for automations.
## Note that even when toggled from HA, it WILL NOT turn off again after the counter
light:
  - platform: binary
    output: backlight
    name: "TFT Backlight"
    restore_mode: ALWAYS_OFF

Thanks Karosm for the suggestion. Tried that but didn’t work unfortunately. Also tried using write_command_() but that’s protected.

I ended up creating a new black page in lvgl, and set it just before the backlight LED is switched off. Hope that will prevent burn-in.

That would be surprising… So what you got?

Yeah, not surprising…