Nextion TFT LCD Display

The nextion display platform allows you to use Nextion LCD displays (datasheet, iTead) with ESPHome.

Nextion LCD Display.

As the communication with the MH-Z19 is done using UART, you need to have an UART bus in your configuration with rx_pin both the tx_pin set to the respective pins on the display. Additionally, you need to set the baud rate to 9600.

# Example configuration entry
  rx_pin: D0
  tx_pin: D1
  baud_rate: 9600

  - platform: nextion
    lambda: |-
      it.set_component_value("gauge", 50);
      it.set_component_text("textview", "Hello World!");

Configuration variables:

  • uart_id (Optional, ID): The ID of the UART bus you wish to use for this display. Use this if you want to use multiple UART buses at once.
  • lambda (Optional, lambda): The lambda to use for rendering the content on the nextion display. See Rendering Lambda for more information.
  • update_interval (Optional, Time): The interval to call the lambda to update the display. Defaults to 5s.
  • id (Optional, ID): Manually specify the ID used for code generation.

Rendering Lambda

With Nextion displays, a dedicated chip on the display itself does the whole rendering. ESPHome can only send instructions to the display to tell it how to render something and what to render.

First, you need to use the Nextion Editor to create a display file and insert it using the SD card slot. Then, in the rendering lambda, you have 3 main methods you can call to populate data on the display:

  - platform: nextion
    # ...
    lambda: |-
      // set the "value" of a component - value is always an integer
      // for example gauges represent their status using integers from 0 to 100
      it.set_component_value("gauge", 50);

      // set the text of a component
      it.set_component_text("textview", "Hello World!");

      // set the text of a component with formatting
      it.set_component_text_printf("textview", "The uptime is: %.1f", id(uptime_sensor).state);

Please see Formatted Text for a quick introduction into the printf formatting rules and Displaying Time for an introduction into the strftime time formatting.