ESPhome and Nextion Display

Does anyone have a a working example to get the nextion working with ESPhome?
I have been trying for some time now but i do not get it to work.
I did try first with wemos D1 mini and now with an ESP32 but the only thing i do get is “Waiting for ACK timed out!”
Also did try different gpio pins different baut raids but no luck.
This is the part of the used code.

display:
  - platform: nextion
    id: page0
    lambda: |-
      it.set_component_text("t0", "Hello World!");
      it.set_component_text("t1", "Hello World!");

On the display i have t0 and t1 on page 0 as a text box

So if you have a working example please let me know so i can test

Thanks in advance

Same problem here… is there anyone that could help!
Thanks

There are 2 or 3 examples of nextion code here

I just bought 2 nextion 3.5" display. I have follow all examples that I can find on the youtubes. None of them working for me. HASwitchPlate works but use lots of MQTT traffics. I use D1 Wemo mini. Anyone have the same issues get it to work? Please share. I have been testing it for 2 weeks still no success sending test text to the display.

I get esphome log show “Received unknown filler end bytes from Nextion!” when I press the button. Display does not show my test text.

You guys solve the solution what not working? I swap the rx and tx pins still same problem.

I am having a similar issue where I cannot get to display a simple text.
I created this in the editor, a simple text box.
image

The settings for it are:

In my code, I have the following:

display:
  - platform: nextion
    id: HASwitchPlateNextion
    uart_id: uart_nextion
    update_interval: 3s
    lambda: |-
        it.set_wait_for_ack(false); 
        it.set_component_text("time", "12:22");

I am expecting the 12:22 to be displayed in the text box, but nothing happens.

I am using the HASwitchPlate hardware, so the TX and RX are fine. the display communicates.

The hardware has a power switch for the display, and I turn it on at boot.

#Include the platform used for the hardware
esphome:
  name: $id
  platform: ESP8266
  board: esp01_1m
  on_boot:
    priority: 200
    then:
      - output.turn_on: nextion_power

I tried a bunch of priorities.

I am not sure if this is a setup issue I have in the code, or if it is a timing issue with when the display connects and gets the message. I have the update running every 3s, so I assume that if it does not get the update at startup, it should run through it again?
I suspect a timing issue because I get the following:

[23:19:40][C][gpio.output:011]:   Pin: GPIO12 (Mode: OUTPUT)
[23:19:40][C][logger:189]: Logger:
[23:19:40][C][logger:190]:   Level: DEBUG
[23:19:40][C][logger:191]:   Log Baud Rate: 115200
[23:19:40][C][logger:192]:   Hardware UART: UART0
[23:19:40][C][nextion:117]: Nextion:
[23:19:40][C][nextion:118]:   Device Model:     NX3224T024_011R
[23:19:40][C][nextion:119]:   Firmware Version: 163
[23:19:40][C][nextion:120]:   Serial Number:    DE605031C33E3E33
[23:19:40][C][nextion:121]:   Flash Size:       4194304
[23:19:40][C][nextion:122]:   Wake On Touch:    True
[23:19:40][C][captive_portal:148]: Captive Portal:
[23:19:40][C][ota:029]: Over-The-Air Updates:
[23:19:40][C][ota:030]:   Address: wall-switch-01.local:8266
[23:19:40][C][ota:032]:   Using Password.
[23:19:40][C][api:095]: API Server:
[23:19:40][C][api:096]:   Address: wall-switch-01.local:6053
[23:19:40][C][sntp:039]: SNTP Time:
[23:19:40][C][sntp:040]:   Server 1: '0.pool.ntp.org'
[23:19:40][C][sntp:041]:   Server 2: '1.pool.ntp.org'
[23:19:40][C][sntp:042]:   Server 3: '2.pool.ntp.org'
[23:19:40][C][sntp:043]:   Timezone: 'CST6CDT5,M3.2.0/2,M11.1.0/2'
[23:19:40][C][homeassistant.sensor:030]: Homeassistant Sensor 'temperature_downstairs'
[23:19:40][C][homeassistant.sensor:030]:   State Class: ''
[23:19:40][C][homeassistant.sensor:030]:   Unit of Measurement: ''
[23:19:40][C][homeassistant.sensor:030]:   Accuracy Decimals: 1
[23:19:40][C][homeassistant.sensor:031]:   Entity ID: 'sensor.downstairs_temperature'
[23:19:40][C][homeassistant.sensor:030]: Homeassistant Sensor 'temperature_upstairs'
[23:19:40][C][homeassistant.sensor:030]:   State Class: ''
[23:19:40][C][homeassistant.sensor:030]:   Unit of Measurement: ''
[23:19:40][C][homeassistant.sensor:030]:   Accuracy Decimals: 1
[23:19:40][C][homeassistant.sensor:031]:   Entity ID: 'sensor.upstairs_temperature'
[23:19:42][D][nextion:247]: Manually set nextion report ready
[23:19:42][W][nextion:725]: Received unknown event from nextion: 0x40

You can see above that the display is working and is on given the nextion logs. But I am not sure what the last 2 logs are.

If it is a timing issue, is there a way to turn on the display from the display lambda? Meaning turn it on, wait, then run the lambda. I can create a global to keep track of the display being on, so I don’t wait each loop. Thinking traditional MCU and trying to get into ESPHome. Need help!

I went through all of the projects online, but I cannot find a simple one to debug with, so I created one. Doesn’t help if I don’t know if this simple project is a known good one…

Thanks,
H-

Have you looked at the example code I posted above?

Yeah, I went through them all. None worked for me, that’s when I shifted gears and created the most simple project I could think of. Try to send a string from the ESP to the display.
I figured I’d go simple, then build on it for my project.

Fiddle with the baud rate. Some people say to use 9600, some say it works for them at 115200.

at 9600, I don’t get this message anymore, but the display still does not display the string I am sending.
[23:19:42][W][nextion:725]: Received unknown event from nextion: 0x40
Leads me to believe it is a timing thing.

I do think it is a conflict between turning on the display and starting the program. the on_boot command I am sending to turn the display on. I am not sure if it initializes in time to receive a command. It is just a thought. I will need now to really hack into the hardware to keep the display on all the time vs having it switched, and see if that resolves it. If it does, then I know it is a timing. If not, then it is something else and I’ll keep looking.

thanks for the hint!
I will keep at it.

Hi Haze,
Did you manage to resolve this ?
I am having the exact same problem. (now 2 weeks in …)
Cheers

No, I just ordered a new display and a new ESP so I will try a simple hardware and a simple project. I need to remove any hardware dependency from the HASwitchPlate to see where the issue is. I will report back when I do. Hope to get it resolved.

@njm, I just got my hardware and tried my program.
The code works. I tried this on from here, which is a very nice UI on Nextion:.
Here is my code:

#Name the Project here to dentify the specific node
substitutions:
  project: Wall-Switch-01
  id: wall-switch-01

#Include the chipset
<<: !include common/esphome/esp32.yaml
#  on_boot:
#    priority: -180
#    then:
#      - output.turn_on: nextion_power
      
#Include the platform used for the hardware
<<: !include common/templates/HASwitchPlate.yaml
      
time:
  - platform: sntp
    id: sntp_time

#Map the display ON GPIO to GPIO12.
#The output gets turned on on_boot in the HASwitchPlate.yaml file
output:
  - platform: gpio
    pin: GPIO12
    id: nextion_power

#Get the sensors from HomeAssistant    
sensor:
#--------------------TEMPERATURE------------------------------------------------    
  - platform: homeassistant
    id: temperature_downstairs
    entity_id: sensor.downstairs_temperature
  - platform: homeassistant
    id: temperature_upstairs
    entity_id: sensor.upstairs_temperature
    
display:
  - platform: nextion
    id: HASwitchPlateNextion
    uart_id: uart_nextion
    update_interval: 3s
    #tft_url: http://homeassistant.local:8123/local/tft/nextion_touch.tft
    lambda: |-
        it.set_wait_for_ack(false);    
        auto time_text = id(sntp_time).now().strftime("%H:%M");
        auto date_text = id(sntp_time).now().strftime("%b. %d");
        it.set_component_text("time", time_text.c_str());
        it.set_component_text_printf("temp1","%.1f F",id(temperature_downstairs).state);

I can see the press and release of the buttons on the debugger. I got the time working on the display from the ESP32, working on the temp now.

h-

@Haze Thank you for your response, the formatting of the sntp time will be very helpful, unfortunately I seem to have a more fundamental problem displaying anything from Home Assistant to the display. My buttons are working fine and controlling my bathroom IXL Tastic light, heater and fan.

Do you need to set a font in the HMI file?

@njm, the code above works, so you should try that. Hope it resolves what you see.

I will say one thing for what it’s worth; while debugging, I had the same issue. I did not see any of the data from HA being displayed. I tried many iteration of code in ESPHome and in the Nextion Studio, and nothing worked. I had a bad assumption that the buttons worked because they were responsive when I touch them, but I realized that the display was reacting to button presses, changing pages, etc. only when the action was in the display.
Do you see the debug messages from the display on the ESPHome debug window? They should show Pressed/Released every time you press a button. Mine did not.
Once I was able to get that going (communication issue), the rest worked perfectly.

Hope this helps

EDIT: Just read your note more carefully. Seems this is not your issue. Try a fresh project. The code I linked for the HMI and the code above work together for sure.

And looking at the response from @nickrout I would say that setup I mention is your best bet to remove all variables. the HMI on the github I linked has all the fonts in it. I made no changes to it so i don;t introduce any variables.

How did you fix the communication issue?

I did not yet. Let me explain.
I started with the HASwitchPlate hardware, which I could not get to work. My gut feel was it has something to do with the display turning on with a GPIO, and the timing of the display initializing vs the ESP code initializing. I tried all on_boot priorities and nothing seemed to fix it. I had too many variables (new hardware, new HMI, new ESPHome code, etc.)
I was getting a communication issue with it. Per your input, I changed the baud rate, and that changed the error message I was getting. That’s when I realized it could be a synchronization error. The ESPHome was potentially communicating with the display before the display is ready. And getting in a state that it latches up (because no subsequent comms works given I was refreshing every 3s)

So I decided to get a new ESP board and a new display. I connected the two and nothing else. Display is connected to 5V so it is always on. No variables.

That’s the setup which worked.

Now that I have a working ESPHome and a working HMI file with it, I need to try to make it work on the HASwitchPlate hardware. The only variables there are ESP32 vs. ESP8xxx, and the GPIO controlling the display power. I don’t think the ESP type is an issue. It’s abstracted by ESPHome, so this leaves the GPIO.

What I am going to do next (traveling now, but will do when i am back home) is to load the know good HMI code in the display of the HASwitchPlate, load the ESPHome code into the HASwitchPlate and see if I get the same error.

If I do, then I now 100% it is the display on synchronization issue. I will have to read up more on how to turn on the GPIO, wait (to give time to the display to initialize) then start the ESPHome.
For now, the only knob I can see is the on_boot priority. But I could be wrong. Any thoughts?