Send messages from HA to esp home show on lcd

I want to send messages to the esphome and show it on the lcd screen. The screen is working but i cant compile this file. Somewhere must be an error.

esphome:
  name: test

esp32:
  board: nodemcu-32s
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "xxxxxxx"

ota:
     password: "xxxxxx"
  - platform: esphome

wifi:
  ssid: ""
  password: ""

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Fallback Hotspot"
    password: "IF5TaFrqxQFW"

captive_portal:

i2c:
  sda: 21
  scl: 22

globals:
  - id: display_text_global
    type: std::string
    initial_value: "Hello World!"

text_sensor:
  - platform: template
    name: "LCD Nachricht"
    id: display_text
    update_interval: never
    lambda: |-
      return {id(display_text_global)};  # Umwandlung in optional<T>

display:
  - platform: lcd_pcf8574
    dimensions: 16x2
    lambda: |-
      it.printf(0, 0, "%s", id(display_text_global).c_str());  # Text korrekt auf dem Display ausgeben

The compiler generates logs.

However the way to get info from Ha to esphome is via a home assistant component.

There are a few issues:

  1. The formatting of your ota section is incorrect. It should be:
    ota:
      - password: "xxxxxx"
        platform: esphome
    
  2. The initial value of display_text_global needs extra quotes (see example here):
    globals:
      - id: display_text_global
        type: std::string
       initial_value: '"Hello World!"'
    
  3. The comments in your lambdas need to use // (as it’s C++ code):
    text_sensor:
      - platform: template
        name: "LCD Nachricht"
        id: display_text
        update_interval: never
        lambda: |-
          return {id(display_text_global)};  // Umwandlung in optional<T>
    
    display:
      - platform: lcd_pcf8574
        dimensions: 16x2
        lambda: |-
          it.printf(0, 0, "%s", id(display_text_global).c_str());  // Text korrekt auf dem Display ausgeben
    

After fixing these (and filling in the SSID and password), your configuration compiles for me.

It’s worth noting that the template text component might be an easier way to implement this, as it allows sending text directly from Home Assistant: Template Text — ESPHome