ESP32-S3 4.3inch Capacitive Touch Display from - waveshare

so i was looking into this for backlight control

CH422G - - - - - -
EXIO1 TP_RST
EXIO2 DISP
EXIO3 LCD_RST
EXIO4 SD_CS
EXIO5 USB_SEL(LOW) USB_SEL(HIGH)

so i tried this

  - platform: gpio
    name: CH422G Pin 2
    pin:
      ch422g: ch422g_hub
      number: 2
      mode:
        output: true
      inverted: true

and it indeed turns the backlight off when i turn this switch off on the devices web portal… and only does that while the switch is on… i can still use the touchscreen and control things, but when i turn the switch off to turn the lcd back on it resets the device? im on the right track cos when i do the same thing with pin 1 on the 422g i get error messages about the touchscreen chip not responding and exio1 is listed as tp rst… so is pin 2 supposed to be the backlight control or not? on the wiki they show a code snippet that seems to use an lvgl function? should i be defining the backlight in the display section??? im kinda nooby to all this stuff too

That pin does control the backlight, but also the display enable itself, so it’s not really useful for turning off the backlight. I’d suggest you set it as the enable pin in the display config:

    reset_pin:
      ch422g: io_ex
      number: 3
    enable_pin:
      ch422g: io_ex
      number: 2

and wire a real GPIO to the backlight control - see here for details:

hmm that link doesnt work for me… and i prefer to use forums anyway… discord is a blight on knowledge and is literally the biggest hurdle to internet archiving today… im just astounded that the docs tell us to use the io expander to control the backlight and that makes it reset?.. like i get that you said its also connected to display enable… but i dont see why that should reset the esp

Tough crowd tonight.

sorry i shouldnt have ranted about discord lol… but i mainly just wanted to know is it supposed to reset the esp when the display enable changes?

I have no idea.

If however your real question is “Am I doing something wrong that makes it reset” then the answer AFAIK is no, you are not. That’s just what it appears to do if you mess with the DISP control, so the only solution is “Don’t do that”.

Just tried that, and for me it seems to work pretty well. I don’t need dimming, and disabling the Display might have another advantage, as the Display itself also turns off and no wear leveling is needed. If you turn the Backlight back on the display itself does a reinitialisation and redraw automagically, which is exactly what I want.

You can also get rid of that inversion if you set the restore mode to always on. ( seems that on initial boot it needs a certain state, otherwise changing the backlight only works for one time, then stays on or off.)

ch422g:
  - id: ch422g_hub

switch:
  - platform: gpio
    name: backlight
    pin:
      ch422g: ch422g_hub
      number: 2
      mode:
        output: true
      inverted: False
    restore_mode: ALWAYS_ON

Btw.: it somehow seems that the ch422g integration does not accept an address anymore, but it works fine without.

Correct - it never used the address before anyway.

Does anyone know of a decent case for these by any chance?

If you own a 3D printer

2 Likes

Hi all,

I have one of these displays (link) and i just CANNOT get it to stop flickering like mad. Unfortunately I’m just not familiar enough with Arduino development to just wholesale switch over to that.

I’ve had zero issues getting the touchscreen to work, getting it to work with home assistant, or even opening an RTSP mjpeg feed on it. I just cant get it to stop flickering.

I’ve tried all sorts of playing with the refresh rates, the pulse widths and the PSRAM clock speed. Basically every build I’ve done has issues flickering.

I clean my build files between every compile. I have also tried preparing it for first use again, and while it helps for a couple seconds on the next boot, it doesnt make any sort of permenant fix.

I’ve added a .gif of the issue I’m experiencing.
ezgif.com-optimize

If anyone can point me in the right direction, that would be amazing.

Here is the code that produced the most recent failure.

esphome:
  name: esp-display
  friendly_name: ESP Display
  platformio_options:
    board_build.flash_mode: dio

esp32:
  board: esp32s3box
  framework:
    type: esp-idf

psram:
  mode: octal
  speed: 80Mhz

# Enable logging
logger:
#  level: DEBUG

spi:
  clk_pin:
    number: 7
    allow_other_uses: true
  mosi_pin: GPIO6

i2c:
  sda: GPIO08
  scl: GPIO09


# Enable Home Assistant API
api:

wifi:
  ssid: [---!---]
  password: [---!---]

  manual_ip:
    static_ip: [---!---]
    gateway: [---!---]
    subnet: [---!---]

bluetooth_proxy:
  active: true

button:
  - platform: restart
    name: "Restart Device"

text_sensor:
  - platform: wifi_info
    ip_address:
      name: IP Address
    ssid:
      name: Connected SSID
    bssid:
      name: Connected BSSID
    mac_address:
      name: Mac Wifi Address
    scan_results:
      name: Latest Scan Results

sensor:
  - platform: wifi_signal
    name: "WiFi Signal Sensor"
    update_interval: 60s

  - platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
    name: "WiFi Signal dB"
    id: wifi_signal_db
    update_interval: 60s
    entity_category: "diagnostic"

captive_portal:
    
display:
  - platform: rpi_dpi_rgb
    auto_clear_enabled: false
    color_order: RGB
    pclk_frequency: 16MHz
    dimensions:
      width: 800
      height: 480
    de_pin:
      number: 5
    hsync_pin:
      number: 46
      ignore_strapping_warning: true
    vsync_pin:
      number: 3
      ignore_strapping_warning: true
    pclk_pin:
      number: 7
      allow_other_uses: true
    hsync_back_porch: 30
    hsync_front_porch: 210
    hsync_pulse_width: 30
    vsync_back_porch: 4
    vsync_front_porch: 4
    vsync_pulse_width: 4
    data_pins:
      red:
        - 1         #r3
        - 2         #r4
        - 42        #r5
        - 41        #r6
        - 40        #r7
      blue:
        - 14        #b3
        - 38        #b4
        - 18        #b5
        - 17        #b6
        - 10        #b7
      green:
        - 39        #g2
        - 0         #g3
        - 45        #g4
        - 48        #g5
        - 47        #g6
        - 21        #g7
    lambda: |-
      int shift_x = (it.get_width()-310)/2;
      int shift_y = (it.get_height()-256)/2;
      for(auto i = 0; i<256; i++) {
        it.horizontal_line(shift_x+  0,i+shift_y,50, my_red.fade_to_white(i));
        it.horizontal_line(shift_x+ 50,i+shift_y,50, my_red.fade_to_black(i));

        it.horizontal_line(shift_x+105,i+shift_y,50, my_green.fade_to_white(i));
        it.horizontal_line(shift_x+155,i+shift_y,50, my_green.fade_to_black(i));

        it.horizontal_line(shift_x+210,i+shift_y,50, my_blue.fade_to_white(i));
        it.horizontal_line(shift_x+260,i+shift_y,50, my_blue.fade_to_black(i));
      }
      it.rectangle(shift_x+ 0, 0+shift_y, shift_x+ 310, 256+shift_y, my_yellow);

color:
  - id: my_blue
    blue: 100%
  - id: my_red
    red: 100%
  - id: my_green
    green: 100%
  - id: my_white
    red: 100%
    blue: 100%
    green: 100%
  - id: my_yellow
    hex: ffff00

Your yaml works just fine for me. Maybe your 5V supply is not up to the job? Though the SPI config won’t help - it’s claiming a pin used by the display, that won’t end well.

However here is a better config:

substitutions:
  name: waveshare-s3-touch
  friendly_name: Waveshare S3 4.3

esphome:
  name: "${name}"
  platformio_options:
    board_build.flash_mode: dio


esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: "y"
      CONFIG_ESP32S3_DATA_CACHE_64KB: "y"
      CONFIG_SPIRAM_FETCH_INSTRUCTIONS: y
      CONFIG_SPIRAM_RODATA: y

logger:

ch422g:

psram:
  mode: octal
  speed: 80MHz

i2c:
  sda: 8
  scl: 9
  scan: true
  frequency: 400kHz

touchscreen:
  - platform: gt911
    id: my_touchscreen
    interrupt_pin: 4
    reset_pin:
      ch422g:
      number: 1

display:
  - platform: rpi_dpi_rgb
    id: rpi_disp
    update_interval: never
    auto_clear_enabled: false
    color_order: RGB
    pclk_frequency: 16MHz
    dimensions:
      width: 800
      height: 480
    reset_pin:
      ch422g:
      number: 3
    enable_pin:
      ch422g:
      number: 2
    de_pin:
      number: 5
    hsync_pin:
      number: 46
      ignore_strapping_warning: true
    vsync_pin:
      number: 3
      ignore_strapping_warning: true
    pclk_pin: 7
    hsync_back_porch: 30
    hsync_front_porch: 210
    hsync_pulse_width: 30
    vsync_back_porch: 4
    vsync_front_porch: 4
    vsync_pulse_width: 4
    data_pins:
      red: [1, 2, 42, 41, 40]
      blue: [14, 38, 18, 17, 10]
      green: [39, 0, 45, 48, 47, 21]

lvgl:
1 Like

Oh my god.

That did it! THANK YOU SO MUCH.

So that above config I pasted, I took it from the above thread in order to attempt to reproduce what others were doing so that there was a ‘similar’ start point.

I didnt notice the duplicate pin entry under the SPI (sue me, it was after midnight, and I was tired AF).

Comparing what you have given me vs the pile of attempts I’ve made, the main difference appears to be the inclusion of the reset pin under the display, as well as setting that reset pin to 3, rather than 2.

    reset_pin:
      ch422g:
      number: 3

Some of the other forums and github posts that I’ve run across had it on 2.

For all others who may come across this in the future, here is a full working config that is flicker free. It doesn’t have much on it, but it is 100% working perfectly:

substitutions:
  name: waveshare-s3-touch
  friendly_name: Waveshare S3 4.3

esphome:
  name: "${name}"
  platformio_options:
    board_build.flash_mode: dio

esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: "y"
      CONFIG_ESP32S3_DATA_CACHE_64KB: "y"
      CONFIG_SPIRAM_FETCH_INSTRUCTIONS: y
      CONFIG_SPIRAM_RODATA: y

api:

logger:

wifi:
  ssid: [SSID NAME]
  password: !secret wifi_password

  manual_ip:
    static_ip: [IP ADDRESS]
    gateway: [GATEWAY]
    subnet: [SUBNET]

  ap:
    ssid: [INSERT SSID NAME HERE]
    password: [INSERT PASSWORD HERE]

ch422g:

psram:
  mode: octal
  speed: 80MHz

i2c:
  sda: 8
  scl: 9
  scan: true
  frequency: 400kHz

touchscreen:
  - platform: gt911
    id: my_touchscreen
    interrupt_pin: 4
    reset_pin:
      ch422g:
      number: 1
    on_touch:
      - lambda: |-
          ESP_LOGI("Touch", "Touch detected at x=%d, y=%d", touch.x, touch.y);

display:
  - platform: rpi_dpi_rgb
    id: rpi_disp
    update_interval: never
    auto_clear_enabled: false
    color_order: RGB
    pclk_frequency: 16MHz
    dimensions:
      width: 800
      height: 480
    reset_pin:
      ch422g:
      number: 3
    enable_pin:
      ch422g:
      number: 2
    de_pin:
      number: 5
    hsync_pin:
      number: 46
      ignore_strapping_warning: true
    vsync_pin:
      number: 3
      ignore_strapping_warning: true
    pclk_pin: 7
    hsync_back_porch: 30
    hsync_front_porch: 210
    hsync_pulse_width: 30
    vsync_back_porch: 4
    vsync_front_porch: 4
    vsync_pulse_width: 4
    data_pins:
      red: [1, 2, 42, 41, 40]
      blue: [14, 38, 18, 17, 10]
      green: [39, 0, 45, 48, 47, 21]

lvgl:
  displays:
    - rpi_disp
  touchscreens:
    - my_touchscreen
  pages:
    - id: main_page
      width: 100%
      bg_color: 0x000000
      bg_opa: cover
      widgets:
        - label:
            align: CENTER
            text: 'Hello World'
        - button:
            id: light_btn
            align: CENTER
            width: 100
            height: 70
            checkable: true
            widgets:
              - label:
                  align: CENTER
                  text: 'Christmas Tree'
            on_click:
              - homeassistant.action:
                  action: switch.toggle
                  data:
                    entity_id: switch.indoor_plug_3_socket_1
        - button:
            id: light_btn2
            width: 200
            height: 100
            checkable: true
            widgets:
              - label:
                  align: CENTER
                  text: 'Bsmnt Lights'
            on_click:
              - homeassistant.action:
                  action: switch.toggle
                  data:
                    entity_id: switch.rectangleplug1_socket_1

@clydebarrow Thank you again sir, I was in danger of losing what hair I have left.

1 Like

Thank you all very much for participating in this forum. Thanks to your contributions and reading a lot of documentation about the screen and ESPHome, I have managed to achieve proper functionality for the screen along with an automation for power-saving screen-off functionality and a constant brightness effect.

The screen-off effect resets the pages (it “denaturalizes” the existing page). At least for me, this is very useful because, in this way, it not only turns off the screen but also prevents accidental presses on the keyboard in the dark.

I am sharing part of the code that I believe will be useful for others. This code is specifically designed for screens from the Waveshare brand, particularly the ESP32-S3-Touch-LCD-4.3.

globals:
  - id: screen_timer
    type: int
    restore_value: false
    initial_value: '0'

esphome:
  name: waveshare-s3-touch
  friendly_name: Waveshare S3 4.3
  platformio_options:
    build_flags: "-DBOARD_HAS_PSRAM"
    board_build.arduino.memory_type: qio_opi
    board_build.flash_mode: dio
    board_upload.maximum_ram_size: 524288
  on_boot:
    priority: 600
    then:
      - lvgl.page.show: loading
      

esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: y
      CONFIG_ESP32S3_DATA_CACHE_64KB: y
      CONFIG_SPIRAM_FETCH_INSTRUCTIONS: y
      CONFIG_SPIRAM_RODATA: y

ch422g:
  - id: ch422g_hub

switch:
  - platform: gpio
    name: backlight
    id: backlight
    pin:
      ch422g: ch422g_hub
      number: 2
      mode:
        output: true
      inverted: False
    restore_mode: ALWAYS_ON

interval:
  - interval: 1s
    then:
      - if:
          condition:
            lambda: return id(screen_timer) >= 30;
          then:
            - switch.turn_off: backlight
            - lambda: id(screen_timer) = 0;

      - if:
          condition:
            lambda: return id(screen_timer) >= 0;
          then:
            - lambda: id(screen_timer) += 1;

psram:
  mode: octal
  speed: 80MHz

display:
  - platform: rpi_dpi_rgb
    id: rpi_disp
    auto_clear_enabled: false
    color_order: RGB
    pclk_frequency: 16MHz
    dimensions:
      width: 800
      height: 480
    reset_pin:
      ch422g:
      number: 3
    enable_pin:
      id: enable_pin_display
      ch422g:
      number: 2
    de_pin:
      number: 5
    hsync_pin:
      number: 46
      ignore_strapping_warning: true
    vsync_pin:
      number: 3
      ignore_strapping_warning: true
    pclk_pin: 7
    hsync_back_porch: 30
    hsync_front_porch: 210
    hsync_pulse_width: 30
    vsync_back_porch: 4
    vsync_front_porch: 4
    vsync_pulse_width: 4
    data_pins:
      red:
        - 1 #r3
        - 2 #r4
        - 42 #r5
        - 41 #r6
        - 40 #r7
      blue:
        - 14 #b3
        - 38 #b4
        - 18 #b5
        - 17 #b6
        - 10 #b7
      green:
        - 39 #g2
        - 0 #g3
        - 45 #g4
        - 48 #g5
        - 47 #g6
        - 21 #g7

# Configurar el touchscreen usando el archivo de referencia
i2c:
  sda: 8
  scl: 9
  scan: true
  frequency: 400kHz

touchscreen:
  - platform: gt911
    id: my_touchscreen
    interrupt_pin: 4
    reset_pin:
      ch422g:
      number: 1
    on_touch:
      - switch.turn_on: backlight
      - lambda: |-
          ESP_LOGI("Touch", "Touch detected at x=%d, y=%d", touch.x, touch.y);
          id(screen_timer) = 0;

Hello everyone, after managing to turn the screen black after the specified seconds, I now want to create a dark screen style. However, the screen background stays white no matter what I do.

lvgl:
  displays:
    - rpi_disp
  disp_bg_color: 0x000000
  touchscreens:
    - my_touchscreen

I tried this, but it’s still white.

Any ideas? According to the ESPHome LVGL documentation, disp_bg_color is supposed to set the screen background, and if you want to change it during runtime, you should use lvgl.update. However, it doesn’t work either at the start or when forcing an update.

I’m handling this as a global issue:

theme:
    label:
      text_font: montserrat_22
      text_color: 0xFFFFFF
    button:
      bg_color: 0x333333
      bg_grad_color: 0x111111
      bg_grad_dir: VER
      bg_opa: COVER
      border_color: 0x555555
      border_width: 1
      text_color: 0xFFFFFF
      pressed:
        bg_color: 0x555555
        bg_grad_color: 0x333333
      checked:
        bg_color: 0x444444
        bg_grad_color: 0x222222
        text_color: 0xFFD700
    buttonmatrix:
      bg_opa: TRANSP
      border_color: 0x555555
      border_width: 0
      text_color: 0xFFFFFF
      pad_all: 0
      items:
        bg_color: 0x333333
        bg_grad_color: 0x111111
        bg_grad_dir: VER
        bg_opa: COVER
        border_color: 0x555555
        border_width: 1
        text_color: 0xFFFFFF
        pressed:
          bg_color: 0x555555
          bg_grad_color: 0x333333
        checked:
          bg_color: 0x444444
          bg_grad_color: 0x222222
          text_color: 0xFFD700
    switch:
      bg_color: 0x444444
      bg_grad_color: 0x222222
      bg_grad_dir: VER
      bg_opa: COVER
      checked:
        bg_color: 0x666666
        bg_grad_color: 0x444444
        bg_grad_dir: VER
        bg_opa: COVER
      knob:
        bg_color: 0xFFFFFF
        bg_grad_color: 0xCCCCCC
        bg_grad_dir: VER
        bg_opa: COVER
    slider:
      border_width: 1
      border_opa: 15%
      bg_color: 0x555555
      bg_opa: 15%
      indicator:
        bg_color: 0x666666
        bg_grad_color: 0x444444
        bg_grad_dir: VER
        bg_opa: COVER
      knob:
        bg_color: 0x333333
        bg_grad_color: 0x111111
        bg_grad_dir: VER
        bg_opa: COVER
        border_color: 0x555555
        border_width: 1
        text_color: 0xFFFFFF
    obj:
      bg_color: 0x333333
      bg_grad_color: 0x111111
      bg_opa: TRANSP
      align: center
      pad_all: 1
      border_width: 0
      width: 220
      height: 410
  style_definitions:
    - id: header_footer
      bg_color: 0x333333
      bg_grad_color: 0x111111
      bg_grad_dir: VER
      bg_opa: COVER
      border_opa: TRANSP
      radius: 0
      pad_all: 0
      pad_row: 0
      pad_column: 0
      border_color: 0x555555
      text_color: 0xFFFFFF
      width: 100%
      height: 30

The display background is not visible unless whatever you are displaying over it has a transparent background.

1 Like

Hello.

I spent some time reading until I found the solution.
That value is only used when you refresh the screen; if it’s a fixed value, it’s different. It’s actually this value set directly in LVGL: bg_color: 0x222222. I was using this one: disp_bg_color: 0x000000.

The documentation says that by default, the color it takes is white unless you specify otherwise.

By the way, in my code, I used a different screen-off method. After reading a bit more, I found that there’s a lighter way to do the same thing directly with LVGL, as mentioned at the end of the LVGL tips. Here’s the link to the tip:

Hello everyone!
Does anyone know how to get battery monitoring?
The documentation mentioned GPIO36, but I get the error: ESP32S3 doesn’t support ADC on this pin.

Thanks, everyone!

Thank you so much for this yaml! I added my api and ota stuff so that I can update it without plugging into my laptop, and it starts up and was discovered and added to HA devices section.

Now what I’m struggling with is building the gui for it. Is there any documentation links for setting up the display? I updated the button widgets that were at the bottom of the yaml to reflect devices that I have, and I’m seeing two issues - first, the first button shows up in the middle of the screen, and then the two additional buttons I have added are both stacked in the upper left corner (I think they’re stacked, I only see one of them)

The other issue I’m having is that the buttons don’t seem to be doing anything (it seemed like it was flipping the button from blue to red when I first installed, but it’s not even doing that now)

What documentation can I look at to figure out how to build myself a dashboard for this?

Edit, reading the linked LVGL docs. Anything else, or is that it?

So, I got it working so far as the screen turns off (thanks Foxy!) and when I tap it, the backlight turns back on… and I have a single button, which toggles on and off (blue and red) but it doesn’t seem to actually turn the light off in HA. Any thoughts? I did verify that the Allow Device to perform home assistant actions button is checked (I’ve also got an M5 Atom Echo in ESPHome, and it’s able to turn the light on and off)

globals:
  - id: screen_timer
    type: int
    restore_value: false
    initial_value: '0'

esphome:
  name: waveshare-esp32-s3-touch
  friendly_name: Waveshare-ESP32-S3-Touch
  platformio_options:
    build_flags: "-DBOARD_HAS_PSRAM"
    board_build.arduino.memory_type: qio_opi
    board_build.flash_mode: dio
    board_upload.maximum_ram_size: 524288
  on_boot:
    priority: 600
    then:
      - lvgl.page.show: main_page

esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: y
      CONFIG_ESP32S3_DATA_CACHE_64KB: y
      CONFIG_SPIRAM_FETCH_INSTRUCTIONS: y
      CONFIG_SPIRAM_RODATA: y

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: <secret key here>

ota:
  - platform: esphome
    password: <some password here>

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Waveshare-Esp32-S3-Touch"
    password: <another secret password>
    
ch422g:
  - id: ch422g_hub

# Switch to turn backlight back on
switch:
  - platform: gpio
    name: backlight
    id: backlight
    pin:
      ch422g: ch422g_hub
      number: 2
      mode:
        output: true
      inverted: False
    restore_mode: ALWAYS_ON

# Timer to turn backlight off
interval:
  - interval: 1s
    then:
      - if:
          condition:
            lambda: return id(screen_timer) >= 30;
          then:
            - switch.turn_off: backlight
            - lambda: id(screen_timer) = 0;

      - if:
          condition:
            lambda: return id(screen_timer) >= 0;
          then:
            - lambda: id(screen_timer) += 1;

psram:
  mode: octal
  speed: 80MHz

i2c:
  sda: 8
  scl: 9
  scan: true
  frequency: 400kHz

touchscreen:
  - platform: gt911
    id: my_touchscreen
    interrupt_pin: 4
    reset_pin:
      ch422g:
      number: 1
    on_touch:
      - switch.turn_on: backlight
      - lambda: |-
          ESP_LOGI("Touch", "Touch detected at x=%d, y=%d", touch.x, touch.y);

display:
  - platform: rpi_dpi_rgb
    id: rpi_disp
#    update_interval: never
    auto_clear_enabled: false
    color_order: RGB
    pclk_frequency: 16MHz
    dimensions:
      width: 800
      height: 480
    reset_pin:
      ch422g:
      number: 3
    enable_pin:
      id: enable_pin_display
      ch422g:
      number: 2
    de_pin:
      number: 5
    hsync_pin:
      number: 46
      ignore_strapping_warning: true
    vsync_pin:
      number: 3
      ignore_strapping_warning: true
    pclk_pin: 7
    hsync_back_porch: 30
    hsync_front_porch: 210
    hsync_pulse_width: 30
    vsync_back_porch: 4
    vsync_front_porch: 4
    vsync_pulse_width: 4
    data_pins:
      red: [1, 2, 42, 41, 40]
      blue: [14, 38, 18, 17, 10]
      green: [39, 0, 45, 48, 47, 21]


 # Get the state of the light
binary_sensor:
  - platform: homeassistant
    id: office_corner_light
    entity_id: light.lifx_bulb
    publish_initial_state: true
    on_state:
      then:
        lvgl.widget.update:
          id: office_corner_light_btn
          state:
            checked: !lambda return x;
      

# Draw the dashboard
lvgl:
  displays:
    - rpi_disp
  touchscreens:
    - my_touchscreen
  pages:
    - id: main_page
      width: 100%
      bg_color: 0x000000
      bg_opa: cover
      widgets:
        - button:
            id: office_corner_light_btn
            align: CENTER
            width: 150
            height: 70
            checkable: true
            widgets:
              - label:
                  align: CENTER
                  text: 'Office Corner Lights'
            on_click:
              - homeassistant.action:
                  action: light.toggle
                  data:
                    entity_id: light.lifx_bulb