Esphome & nextion tft lcd

Hi!
Did you solve this?

Hi, long time no see. After a few updates of a lot of stuff further my text sensor is not properly filled anymore in the display. Also I get errors but I do not know what they mean. Anyone able to direct?

[12:40:46][C][api:143]:   Using noise encryption: NO
[12:40:46][C][homeassistant.text_sensor:023]: Homeassistant Text Sensor 't10_text'
[12:40:46][C][homeassistant.text_sensor:024]:   Entity ID: 'sensor.nextiont0_text'
[12:40:46][C][homeassistant.text_sensor:023]: Homeassistant Text Sensor 'dim_text'
[12:40:46][C][homeassistant.text_sensor:024]:   Entity ID: 'sensor.nextiondim_text'
[12:40:46][C][homeassistant.text_sensor:023]: Homeassistant Text Sensor 'uart_text'
[12:40:46][C][homeassistant.text_sensor:024]:   Entity ID: 'sensor.nextion_uart'
[12:40:49][E][nextion:1107]: This command is deprecated
[12:40:49][V][component:199]: Component nextion.display took a long time for an operation (0.08 s).
[12:40:49][V][component:200]: Components should block for at most 20-30ms.
[12:40:49][W][nextion:395]: Nextion reported variable name invalid!
[12:40:54][E][nextion:1107]: This command is deprecated
[12:40:54][V][component:199]: Component nextion.display took a long time for an operation (0.08 s).
[12:40:54][V][component:200]: Components should block for at most 20-30ms.
[12:40:54][W][nextion:395]: Nextion reported variable name invalid!
[12:40:59][E][nextion:1107]: This command is deprecated
[12:40:59][V][component:199]: Component nextion.display took a long time for an operation (0.08 s).
[12:40:59][V][component:200]: Components should block for at most 20-30ms.
[12:40:59][W][nextion:395]: Nextion reported variable name invalid!
[12:41:04][E][nextion:1107]: This command is deprecated
[12:41:04][V][component:199]: Component nextion.display took a long time for an operation (0.08 s).
[12:41:04][V][component:200]: Components should block for at most 20-30ms.
[12:41:04][W][nextion:395]: Nextion reported variable name invalid!
[12:41:09][E][nextion:1107]: This command is deprecated
[12:41:09][V][component:199]: Component nextion.display took a long time for an operation (0.08 s).
[12:41:09][V][component:200]: Components should block for at most 20-30ms.
[12:41:09][W][nextion:395]: Nextion reported variable name invalid!

What command is deprecated?

I believe this is relevant:

uart:
  rx_pin: D7
  tx_pin: D5
  baud_rate: 9600

display:
  - platform: nextion
    lambda: |-
      it.set_wait_for_ack(false);
      it.set_component_text("t10", id(t10_text).state.c_str());

text_sensor:
  - platform: homeassistant
    id: t10_text
    entity_id: sensor.nextiont0_text
  - platform: homeassistant
    id: dim_text
    entity_id: sensor.nextiondim_text
  - platform: homeassistant
    id: uart_text
    entity_id: sensor.nextion_uart

There must be more code.
The log says you are asking for a variable from nextion that does not exist.

This is all regarding nextion

uart:
  rx_pin: D7
  tx_pin: D5
  baud_rate: 9600

display:
  - platform: nextion
    lambda: |-
      it.set_wait_for_ack(false);
      it.set_component_text("t10", id(t10_text).state.c_str());

text_sensor:
  - platform: homeassistant
    id: t10_text
    entity_id: sensor.nextiont0_text
  - platform: homeassistant
    id: dim_text
    entity_id: sensor.nextiondim_text 
  - platform: homeassistant
    id: uart_text
    entity_id: sensor.nextion_uart

binary_sensor:
  - platform: nextion
    page_id: 0
    component_id: 3
    name: "Nextion.Button.Doorbel"
    id: Nextion_Button_Doorbel
  - platform: nextion
    page_id: 1
    component_id: 2
    name: "Nextion.Button.Package delivered"
  - platform: nextion
    page_id: 1
    component_id: 3
    name: "Nextion.Button.Package not delivered"
  - platform: nextion
    page_id: 2
    component_id: 1
    name: "Nextion.Button.mailbox"
  - platform: nextion
    page_id: 2
    component_id: 2
    name: "Nextion.Button.binbox"
  - platform: nextion
    page_id: 2
    component_id: 3
    name: "Nextion.Button.other"
  - platform: nextion
    page_id: 0
    component_id: 2
    name: "Nextion.Button.watchme"
  - platform: nextion
    page_id: 6
    component_id: 5
    name: "Nextion.Button.delivered37"
  - platform: nextion
    page_id: 6
    component_id: 6
    name: "Nextion.Button.delivered8"
    
switch:
  - platform: uart
    name: "dim1"
    data: 'dim=1'
  - platform: uart
    name: "dim20"
    data: 'dim=20'
  - platform: uart
    name: "dim100"
    data: 'dim=100'
  - platform: uart
    name: "dimsave"
    data: [0xFF, 0xFF, 0xFF]

These are the nextion variables, make sure all is still in the tft/hmi file

100% all is in. It used to work when I made it at that time. No errors then.

But what does these mean:
[13:53:56][E][nextion:1107]: This command is deprecated
[13:53:56][V][component:199]: Component nextion.display took a long time for an operation (0.08 s).
[13:53:56][V][component:200]: Components should block for at most 20-30ms.
[13:53:56][W][nextion:395]: Nextion reported variable name invalid!

First three don’t know for sure.
The last one is that the ESP is asking for a variable that is not there or not global.

My guess is that the fourth one is the reason for the other three.

Ok, but how do I discover what command is deprecated then?

As I said, I believe the fourth error line:

[13:53:56][W][nextion:395]: Nextion reported variable name invalid!

is the reason you get:

[13:53:56][E][nextion:1107]: This command is deprecated
[13:53:56][V][component:199]: Component nextion.display took a long time for an operation (0.08 s).
[13:53:56][V][component:200]: Components should block for at most 20-30ms.

This is a wild guess but it’s wort testing.
If ESP asks for variable x and x is not available, then it might respond with the messages in the wrong order.
I would still test that first before hunting the rest

I do want to hunt but don;t know where to shoot yet…

some more (very verbose) logging:

14:10:23][VV][nextion:033]: send_command t10.txt="Hello, this is \r a message \r for you!"
[14:10:23][VV][nextion:936]: Add to queue type: NORESULT component set_component_text
[14:10:23][V][component:199]: Component nextion.display took a long time for an operation (0.10 s).
[14:10:23][V][component:200]: Components should block for at most 20-30ms.
[14:10:23][VV][nextion:297]: this->command_data_ \xff\xff\xff length 4
[14:10:23][VV][nextion:200]: print_queue_members_ (top 10) size 1
[14:10:23][VV][nextion:201]: *******************************************
[14:10:23][VV][nextion:210]: Nextion queue type: 0:NO_RESULT , name: set_component_text
[14:10:23][VV][nextion:214]: *******************************************
[14:10:23][VV][nextion:302]: print_queue_members_ size 1
[14:10:23][W][nextion:395]: Nextion reported variable name invalid!
[14:10:23][VV][nextion:267]: Removing set_component_text from the queue
[14:10:23][VV][nextion:780]: Loop End
[14:10:23][V][component:199]: Component nextion.display took a long time for an operation (0.05 s).
[14:10:23][V][component:200]: Components should block for at most 20-30ms.
[14:10:25][VV][api.service:470]: on_ping_request: PingRequest {}
[14:10:25][VV][api.service:043]: send_ping_response: PingResponse {}
[14:10:25][VV][api.service:470]: on_ping_request: PingRequest {}
[14:10:25][VV][api.service:043]: send_ping_response: PingResponse {}
[14:10:28][VV][scheduler:195]: Running interval 'update' with interval=5000 last_execution=226816 (now=231816)

Here is the source and where it is typed out:
ESPHome: /opt/build/esphome/esphome/components/nextion/nextion.cpp Source File

At the very bottom you see the error message

Yes found that before, but I do not know how to read that…

I am sure this part is not working anymore:

display:
  - platform: nextion
    lambda: |-
      it.set_wait_for_ack(false);
      it.set_component_text("t10", id(t10_text).state.c_str());

text_sensor:
  - platform: homeassistant
    id: t10_text
    entity_id: sensor.nextiont0_text

When I created it long time ago I was able to send text to that sensor and that would be displayed. But now it does not display it anymore… (on the nextion)

I started to build a Nextion this Saturday and here is my display part:

uart:
  tx_pin: 13
  rx_pin: 12
  baud_rate: 9600
  id: tf_uart

switch:
  - platform: template
    name: $device_name Nextion inited
    id: nextion_init
    entity_category: config
    restore_state: false
    assumed_state: off
    optimistic: true

display:
  - platform: nextion
    id: disp1
    uart_id: tf_uart
    tft_url: redacted
    on_setup:
      then:
        - number.set:
            id: brightness
            value: 30
        - wait_until:
            api.connected
        - switch.template.publish:
            id: nextion_init
            state: on
        - lambda: id(disp1).send_command_printf("page 0");
        

On my other Nextion screen (NS panel) I have this for example to send a value to the screen:

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());

I just haven’t got this far on the new screen

The thing is this did work, and I just recently discovered it does not anymore…

In the logging I can see the entity is being sent to the nextion but it is not displayed anymore.

Sooooo…The Right Way :tm: to do this in the current version of ESPHome is this:

First, create a text_sensor to represent the text box on your Nextion display within ESPHome. For example, I have a page on the display named “weather” with a text box called “txtStatus”:

text_sensor:
  - platform: nextion
    nextion_id: main_lcd
    id: nextionTextStatus1
    component_name: weather.txtStatus

Once this is defined, you can update the text sensor the same way you would update any other text sensor in ESPHome, based on:

I use set_state() in a lambda to set the text on this particular component:

std::string status_message = "some message";
id(nextionTextStatus1).set_state(status_message, false, true);

There are a couple of benefits of this approach:

The first is that you can update the text sensor from anywhere within your ESPHome configuration – it doesn’t have to happen within the display lambda.

As somewhat of a consequence of the first point above, the other benefit is that you are not relying on the display lambda to refresh elements on your display. As soon as you set_state() or publish_state() on the text_sensor that corresponds to the element on the Nextion, the new state is sent to the display. You don’t need to use component.update to force a refresh of the display nor do you need to wait for the display lambda to fire. In addition, this approach helps to minimize traffic on the serial connection between the ESP and the Nextion – with the traditional/original approach, you might cram the updating of a whole mess of Nextion elements into there, forcing a whole bunch of updates/traffic through the serial connection every time the display lambda fires. With this approach, only components that get updated are sent to the display, and it happens immediately as they are updated. No delay.

With this in mind, you can eliminate the display lambda you have in your code above.

Last piece of advice – make sure you using a hardware serial port (UART) on the ESP. ESP32s have a couple (so it’s easy on these), but the '8266 has only one that’s practically usable (on GPIOs 1 & 3). The “soft” serial (bit-banging) that most folks resort to on the '8266 will almost certainly cause issues in some form or another when communicating with the Nextion. I can’t stress this enough. Use a hardware UART, even if it otherwise “seems to work”.

Hopefully this answers your question! Let me know if you need any more detail. :slight_smile:

2 Likes

Hi thank you for your reply. I am not sure what to do now. I had above and that worked well.

Should I change that now? And to what?

I used to “fill” the sensor in homeassistant with text (sensor.nextiont0_text) and that was then “known” in esphome sending it to t10 via above config. What do I need to change to get that going then?

And maybe I am repeaitng myself (sorry) but it used to work… but now I see this error:

[20:33:10][VV][scheduler:195]: Running interval 'update' with interval=5000 last_execution=162474621 (now=162479621)
[20:33:10][E][nextion:1107]: This command is deprecated
[20:33:10][VV][nextion:033]: send_command t10.txt="Hello, this is \r a message \r for you!"
[20:33:10][VV][nextion:936]: Add to queue type: NORESULT component set_component_text
[20:33:10][V][component:199]: Component nextion.display took a long time for an operation (0.10 s).
[20:33:10][V][component:200]: Components should block for at most 20-30ms.
[20:33:10][VV][nextion:297]: this->command_data_ \xff\xff\xff length 4
[20:33:10][VV][nextion:200]: print_queue_members_ (top 10) size 1
[20:33:10][VV][nextion:201]: *******************************************
[20:33:10][VV][nextion:210]: Nextion queue type: 0:NO_RESULT , name: set_component_text
[20:33:10][VV][nextion:214]: *******************************************
[20:33:10][VV][nextion:302]: print_queue_members_ size 1
[20:33:10][W][nextion:395]: Nextion reported variable name invalid!
[20:33:10][VV][nextion:267]: Removing set_component_text from the queue
[20:33:10][VV][nextion:780]: Loop End
[20:33:10][V][component:199]: Component nextion.display took a long time for an operation (0.05 s).
[20:33:10][V][component:200]: Components should block for at most 20-30ms.
[20:33:15][VV][scheduler:195]: Running interval 'update' with interval=5000 last_execution=162479621 (now=162484626)
[20:33:15][E][nextion:1107]: This command is deprecated
[20:33:15][VV][nextion:033]: send_command t10.txt="Hello, this is \r a message \r for you!"
[20:33:15][VV][nextion:936]: Add to queue type: NORESULT component set_component_text
[20:33:15][V][component:199]: Component nextion.display took a long time for an operation (0.10 s).
[20:33:15][V][component:200]: Components should block for at most 20-30ms.
[20:33:15][VV][nextion:297]: this->command_data_ \xff\xff\xff length 4
[20:33:15][VV][nextion:200]: print_queue_members_ (top 10) size 1
[20:33:15][VV][nextion:201]: *******************************************
[20:33:15][VV][nextion:210]: Nextion queue type: 0:NO_RESULT , name: set_component_text
[20:33:15][VV][nextion:214]: *******************************************
[20:33:15][VV][nextion:302]: print_queue_members_ size 1
[20:33:15][W][nextion:395]: Nextion reported variable name invalid!
[20:33:15][VV][nextion:267]: Removing set_component_text from the queue
[20:33:15][VV][nextion:780]: Loop End
[20:33:15][V][component:199]: Component nextion.display took a long time for an operation (0.05 s).
[20:33:16][V][component:200]: Components should block for at most 20-30ms.
[20:33:18][VV][api.service:470]: on_ping_request: PingRequest {}
[20:33:18][VV][api.service:043]: send_ping_response: PingResponse {}
[20:33:20][VV][scheduler:195]: Running interval 'update' with interval=5000 last_execution=162484621 (now=162489621)
[20:33:20][E][nextion:1107]: This command is deprecated
[20:33:20][VV][nextion:033]: send_command t10.txt="Hello, this is \r a message \r for you!"
[20:33:20][VV][nextion:936]: Add to queue type: NORESULT component set_component_text
[20:33:20][V][component:199]: Component nextion.display took a long time for an operation (0.10 s).
[20:33:20][V][component:200]: Components should block for at most 20-30ms.
[20:33:20][VV][nextion:297]: this->command_data_ \xff\xff\xff length 4
[20:33:20][VV][nextion:200]: print_queue_members_ (top 10) size 1
[20:33:20][VV][nextion:201]: *******************************************
[20:33:20][VV][nextion:210]: Nextion queue type: 0:NO_RESULT , name: set_component_text
[20:33:20][VV][nextion:214]: *******************************************
[20:33:20][VV][nextion:302]: print_queue_members_ size 1
[20:33:20][W][nextion:395]: Nextion reported variable name invalid!
[20:33:20][VV][nextion:267]: Removing set_component_text from the queue

You should be able to get away with something more or less like this:

display:
  - platform: nextion
    id: main_lcd

text_sensor:
  - platform: homeassistant
    id: t10_text
    entity_id: sensor.nextiont0_text
    on_value:
      then:
        - lambda: "id(nextionTextBox).set_state(id(t10_text).state, false, true);"
  - platform: nextion
    nextion_id: main_lcd
    id: nextionTextBox
    component_name: your_page.your_text_box

This probably isn’t verbatim what you need but should be reasonably close. Of course you’ll need to make sure the names of the various elements are consistent with what you’re using on the Nextion, etc.

Sorry I cannot get this working back. this is where it worked well:

Errors keep coming and it still does not work.

This I use now:

display:
  - platform: nextion
    id: main_lcd
    lambda: |-
      it.set_wait_for_ack(false);
      it.set_component_text("t10", id(t10_text).state.c_str());

text_sensor:
  - platform: homeassistant
    id: t10_text
    entity_id: sensor.nextiont0_text
    on_value:
      then:
        - lambda: "id(nextionTextBox).set_state(id(t10_text).state, false, true);"
  - platform: nextion
    nextion_id: main_lcd
    id: nextionTextBox
    component_name: 5.t10 # where 5 is the pagenumber and t10 is the text box