[Solved]Please help me how to define multiple pages in nextion display

Howdy,

These days I am falling in playing with esphome.
I made already 3 sensors with esphome and they worked very smooth.

Now I am trying to make another one which is a monitor for homeassistant.
It consists of 1 nextion display and 1 wemos d1mini. That’s all.

It displays some sensor data from homeassistant and control some fans and switches from homeassistant.

There are 2 pages on nextion display.
Page0 has one image and one text component for example.
Page1 has the same components.
I want that touch on page0 can go to the other page and vice versa.
I made two pages with nextion editor. there is no error.
But I don’t know how to define and code on esphome side.

my first code is as below,

binary_sensor:
  - platform: nextion
    page_id: 0
    component_id: 9
    name: "Goto Page1"
    nextion_id: display_nextion
    on_press:
      then:
        - display.page.show: page1

display:
  - platform: nextion
    id: display_nextion
    pages:
      - id: page0
        lambda: |-
          it.set_component_text("t0",  "This is page 0");
      - id: page1
        lambda: |-
          it.set_component_text("t0",  "This is page 1");

Unfortunately, it didn’t work.
When I compiled, the error showed that nextion display did not have ‘pages’ as an option.
I have tried to find a reference or guide, but I couldn’t.

How can I get this done?

Thanks in advance.

2 Likes

I solved this by myself. Thanks for reading.

1 Like

Well are you going to tell us how you fixed it?

1 Like

Well, I guess he aint!

Sorry for late reply.

I didn’t find a solution from official docs, so I found the way by myself.
I used 2 components, global variable and binary sensor to display multi pages.
I give you some sample codes to you.
I think you could easily understand what I did.

globals:
  - id: nextion_page_id
    type: int
    restore_value: no
    initial_value: '0'

binary_sensor:
  - platform: nextion
    page_id: 0
    component_id: 9
    name: "hamon touch"
    internal: true
    on_press:
      then:
        - lambda: |-
            id(nextion_page_id)=1;
            id(display_nextion).goto_page("hacon");
        - component.update: display_nextion

display:
  - platform: nextion
    id: display_nextion
    lambda: |-
      if (id(nextion_page_id) == 0) {
        it.set_component_text("t31", "This is Page 0");
      } else if (id(nextion_page_id) == 1) {
        it.set_component_text("t31", "This is Page 1");
      }
    update_interval: 3s

In above sample, “hacon” is page’s name.
As you might know, English is not my native, so I am hard to explain deeply.

If you have any question, please feel free to ask me. Thank you.

2 Likes

Thx for your knowledge My another name is Minsho : )

good, I am using a wemos d1 mini which is connected to home assisstant through esphome.

wemos d1 mini is also connected to the display

i’m using a nextion 2.4 display, i can’t show the temperature value on the display through the homeassistant

As you can see in the image, the temperature value does not appear on the display.

I am using three temperature sensors that appear on the homeassisstant showing the temperature.
I can’t show the temperature on the nextion display

It is impossible to help without seeing your yaml esphome code.

Yeah, but tell me what code you would use to show the temperature on the display.
this link https://we.tl/t-DveHEfeSNw is my yaml file

I am not going to some random site to get your yaml. Post it here or pastebin.

esphome:
name: station_lcd
platform: ESP8266
board: d1_mini

wifi:
ssid: meoescritorio
password: pedroescritorio
fast_connect: true

manual_ip:
# Set this to the IP of the ESP
static_ip: 192.168.1.78
# Set this to the IP address of the router.
gateway: 10.0.0.1
# The subnet of the network. 255.255.255.0 works for most home networks.
subnet: 255.255.255.0

api:

ota:

logger:
baud_rate: 0 # Disable UART logging (pins GPIO1/3 are used for Nextion communication)

uart:
rx_pin: D1
tx_pin: D6
baud_rate: 9600

time:

  • platform: sntp
    id: sntp_time

sensor:

  • platform: homeassistant
    id: temperatura1
    entity_id: sensor.temperatura1

globals:

  • id: first_page
    type: bool
    restore_value: no

  • id: sensor.tempertatura1
    type: int
    restore_value: no

    platform: homeassistant
    id: sensor.temperatura1
    entity_id: sensor.temperatura1

  • platform: homeassistant # Inside temperature
    id: temperature_inside

display:

  • platform: nextion
    id: teplomer
    update_interval: 5s
    lambda: |-

first of all,
you don’t have to use global variable to show temperature in nextion.

instead, you can use this syntax to show temperature.
I assume that you use text component and it’s object name is t1.
also, name of id can not contain .

it.set_component_text_printf(“t1”, “%.1f°C”, (id(temperature1).state));

thanks, post here the code that I posted with the changes you would make the code please

I didn’t understand very well what you said was the name of object t1

this from name of object t1 is defined in the nextion editor program ?

could you please post your capture of page you created in nextion editor?
then I will rewrite your yaml code.

thanks, i’ll send you the capture of nexiton editor

OK.
I rewrite your code as belows.
It should work for “inside”.
If it is OK, then you should add more syntax under lambda for outside and pool.

esphome:
  name: station_lcd
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: meoescritorio
  password: pedroescritorio
  fast_connect: true
  manual_ip:
    static_ip: 192.168.1.78
    gateway: 192.168.1.1
    subnet: 255.255.255.0

api:

ota:

logger:

globals:
  - id: first_page
    type: bool
    restore_value: no

uart:
  rx_pin: D1
  tx_pin: D6
  baud_rate: 9600

time:
  - platform: sntp
    id: sntp_time

sensor:
  - platform: homeassistant
    name: "Temperature Inside"
    id: temperature_inside
    internal: true
    entity_id: sensor.temperatura1

display:
  - platform: nextion
    id: teplomer
    lambda: |-
      it.set_component_text_printf("inside", "%.1f", (id(temperature_inside).state));
    update_interval: 5s

I already tried with your code and still does not show the temperature.

I get these warning in the log

logs showed that any sensor data for “inside” didn’t come from homeassistant.
you have to check that sensor.temperatura1.
is sensor.temperatura1 correct? any mis typo?
it might be “sensor.temperature1”