HA, Esphome, how to send sensor value to Nextion LCD

Hello
I am trying send sensor value from ha by esphome to Nextion LCD.
This is not binary_sensor and I have no idea how to do that .
I found only simple code on esphome.io

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

Have a look at the various NS panel projects and/or videos.
The NS panel uses the nextion display and is rather well documented now with the NS panel.

Thanks
Maybe someone check my code, logs OK but nextion t0.txt field no value:

text_sensor:

  - platform: homeassistant

    name: textSonOff

    id: t10_text

    entity_id: sensor.1000a91066_t

uart:

  id: uart_2

  rx_pin: GPIO13

  tx_pin: GPIO15

  baud_rate: 9600

display:

  - platform: nextion

    id: nextion1

    uart_id: uart_2

    lambda: |-

      it.set_wait_for_ack(false);

      it.set_component_text("t0", id(t10_text).state.c_str());

Please post the code in code brackets. </>

this is what I have:

text_sensor:
  - platform: homeassistant
    id: home_text1
    entity_id: sensor.alarm_andreas
    on_value:
      then:
        - wait_until:
            switch.is_on: nextion_init
        - lambda: id(disp1).set_component_text_printf("Home.text1", "%s", id(home_text1).state.c_str());


display:
  - platform: nextion
    id: disp1
    uart_id: tf_uart
    tft_url: https://dddd/hmi0.tft 
    on_setup:
      then:
        - number.set:
            id: brightness
            value: 30
        - switch.template.publish:
            id: nextion_init
            state: on
        - lambda: id(disp1).send_command_printf("page 0");

so the text sensor tells where it should go not the display.

I found simple code on esphome.io but it does not work:

# Example configuration entry
uart:
  id: uart_2
  rx_pin: GPIO16
  tx_pin: GPIO17
  baud_rate: 115200


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

How to check? Easy way:

- lambda: id(nextion1).send_command_printf("page0", "t0", "hello world!");

As mentioned above by @Hellis81 … there are plenty examples, see below.
If not already done : in order to present things on a nextion page, this MUST have the page and objects predefined ON the nextion, for this you need to use Nextion Editor and load the bin to the screen.

My entry into this nextion-world came from below…have a look and yes…it is not as simple albeit not very complex too (Nextion editor a bit odd)

marcfager/nspanel-mf: Custom HMI controlled by ESPHome for the Sonoff NSPanel. Includes media player card and home screen with weather data and clock. More to come. (github.com)

I did some projects in Arduino IDE with sensors and servos.
Both way comunication and that works great with my Nextion.
The time has come for ESPhome :slight_smile:
I have only one text object defined in Nextion Editor as t0(text) now.
tft file uploaded, comunication OK between Nextion and ESPhome.
I want print Hello World for test :slight_smile:

Not sure what that is, I am using : set_component_text_printf as does @Hellis81 and using the objnames Home and text1
Again, plenty of other posts and examples … there is even a discord group …I myself will log off of this

I will check your code today evening.
I’ve seen these NSPanel examples yesterday.
How does it work? NSPanel has ESP module and Nextion LCD?

Yes.

Is t0 defined as text and have enough character space for it?
I believe the standard is 10 characters and “hello world” is 11.

Yes t0 is text in Nextion shows newtext as default.
I tried only “Hello” or just “H”

OK I give up
Hellis81 code is not recognized by my yaml file a lot of incompatibility syntax


and more…

Just download one of the starter kits for the NS panel and it will be a great start.

I can’t say exactly what is needed and not needed from my configuration.
But my NS panel is uploaded on GitHub also.

Given that it fails on the template line then just delete that section.
Probably also the section with brightness.

OK I probably found a problem, something is wrong with my wemos d1 or power adapter.
It works but not every time, new flash or reboot can kill functionality :frowning:
I’ve seen blinks Hello World! and sensor value for 3 seconds.
Thanks guys
This is my simple working code:

text_sensor:
  - platform: homeassistant
    id: home_text1
    entity_id: sensor.1000a91066_t

uart:
  id: uart_2
  rx_pin: GPIO13
  tx_pin: GPIO15
  baud_rate: 9600

display:
  - platform: nextion
    id: nextion1
    uart_id: uart_2
    update_interval: 3s
    lambda: |-
      id(nextion1).set_component_text_printf("page0.t0", "Hello World!");
      id(nextion1).set_component_text_printf("page0.t0", "%s", id(home_text1).state.c_str());
      id(nextion1).send_command_printf("page0.t0");
      id(nextion1).update_all_components();

Unfortunatelly it looks like my nextion nx4832t035_011 is damaged.
I tested wemos and lolin exactly the same problems.
Nextion display values occasionally.
Both esp can not connect to wifi when nextion is wired and on.

I found solution using Lolin v2 with Nextion!
That was Tx/Rx pins problem. Can’t be used pins 15/13.
My setup works well with 1/3 pins and logger entry:

logger:
baud_rate: 0

Just out of curiosity, if you try to reset from the ESP button without removing power, does the display work? From the latest Esphome updates it seems that there is a synchronization problem. However, if the power is removed and reconnected ESP it works, but with a restart esp only the panel no longer works.