EspHome with nextion display

Hi
I am trying to make a project with a nextion display and esphome.I would like my d1 mini to change pages created on my nextion display, managed to make it change two pages with this code:

globals:
 - id: nextion_page_id            
   type: int
   restore_value: no
   initial_value: '0'
display:
  - platform: nextion
    id: display_nextion
    update_interval: 5s
    lambda: |-
      if (id(nextion_page_id) == 0) {  
      it.goto_page("main");
       auto time = id(sntp_time).now();
          it.set_component_text_printf("hour","%02d",time.hour);
          it.set_component_text_printf("minute","%02d",time.minute);
          it.set_component_text_printf("date","%02d",time.day_of_month);
          it.set_component_text_printf("month","%02d",time.month);
          it.set_component_text_printf("year","%02d",time.year);
else 
       it.goto_page("page1");
}
id(nextion_page_id) = !id(nextion_page_id);

Can somebody help me-being a total newbie –on how to change more than two pages?
I tried something like this but did not work.

display:
  - platform: nextion
    id: display_nextion
    update_interval: 5s
    lambda: |-
      if (id(nextion_page_id) == 0) {  
      it.goto_page("main");
       auto time = id(sntp_time).now();
          it.set_component_text_printf("hour","%02d",time.hour);
          it.set_component_text_printf("minute","%02d",time.minute);
          it.set_component_text_printf("date","%02d",time.day_of_month);
          it.set_component_text_printf("month","%02d",time.month);
          it.set_component_text_printf("year","%02d",time.year);
      }
      
      
  - platform: nextion
    id: display_nextion1
    update_interval: 5s
    lambda: |-
      if (id(nextion_page_id) == 1) {  
      it.goto_page("page1");     }
      
      
  - platform: nextion
    id: display_nextion2
    update_interval: 5s
    lambda: |-
      if (id(nextion_page_id) == 2) {  
      it.goto_page("page2");     }
       else 
       it.goto_page("page3"); 
      
  
      id(nextion_page_id) = !id(nextion_page_id);