Dimmable PCF8574 LCD Display with ESPHome

Hey folks! Thanks for providing the YAML here, I’d like to give back to this thread by placing my code which utilises @LUNZ 's light-based backlight control in handling the lambda code to draw text updates, which then does away with the need for the binary helper and number helper to store/set brightness or screen on/off states (the light’s native settings itself will handle those).

text_sensor:
  - platform: homeassistant    
    id: display_line_2
    entity_id: input_text.mortara_line_2
    internal: true
  - platform: homeassistant    
    id: display_line_3
    entity_id: input_text.mortara_line_3
    internal: true    
  - platform: homeassistant    
    id: display_line_4
    entity_id: input_text.mortara_line_4
    internal: true

time:
  - platform: homeassistant
    id: my_time
    timezone: "Asia/Singapore"

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

light:
  - platform: monochromatic
    output: backlight
    name: "LCD Display Backlight"
    id: light_backlight
    restore_mode: ALWAYS_ON

display:
  - platform: lcd_pcf8574
    dimensions: 20x4
    address: 0x27
    id: lcd
    update_interval: 1s
    lambda: |-
      if(id(light_backlight).current_values.is_on()) {
        id(lcd).backlight();
        it.strftime(0, 0, "%I:%M:%S %p  %d %b", id(my_time).now());
        it.printf(0, 1, "%s", id(display_line_2).state.c_str());
        it.printf(0, 2, "%s", id(display_line_3).state.c_str());
        it.printf(0, 3, "%s", id(display_line_4).state.c_str());
      } else {
        id(lcd).no_backlight();
      }

Since the backlight is now exposed as a light, I was able to group it with my room’s ceiling lights and turn them on/off as a group!

Hope that helps the next person building highly integrated Home Assistant LCD displays with ESPHome!

4 Likes