SSD1306 OLED display Change content via Home Assistant?

I have connected an OLED display (SSD1306) to my NodeMCU ESP8266; there is also a button on it with which you can switch between different “pages”.
For example, there is the “Outside” page to display the temperature outside.
My question would be whether there are any (concrete) code examples or ideas on how I need to change the code so that I can use a new entity (e.g. select.X) in HomeAssistant to select what is displayed on the screen on the “Outside” page.
Best regards and thanks for your reply!

This is my code so far:

substitutions:
  name: "display"
  friendly_name: ESPHome

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  name_add_mac_suffix: false
  project:
    name: esphome.web
    version: '1.0'

esp8266:
  board: nodemcuv2  # Change the board type to nodemcuv2 for NodeMCU 0.1

# Enable logging
logger:

# Enable Home Assistant API
api:

# Allow Over-The-Air updates
ota:

# Allow provisioning Wi-Fi via serial
improv_serial:

wifi:
  ssid: "ssid"
  password: "password"
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Display"
    password: "password"
# In combination with the `ap` this allows the user
# to provision wifi credentials to the device via WiFi AP.
captive_portal:
font:
  - file: "gfonts://Roboto"
    id: roboto
    size: 20
  - file: "gfonts://Roboto"
    id: roboto_small
    size: 15

i2c:
  sda: D1
  scl: D2

sensor:
  - platform: homeassistant
    name: "Time"
    id: Time
    entity_id: sensor.time
  - platform: homeassistant
    name: "Wetterstation Temperature"
    id: Temperature
    entity_id: sensor.unknown_70_ee_50_a2_17_9a_unknown_70_ee_50_a2_17_9a_unknown_70_ee_50_a2_17_9a_aussenmodul_temperature
  - platform: homeassistant
    name: "Wetterstation Humidity"
    id: Humidity
    entity_id: sensor.unknown_70_ee_50_a2_17_9a_unknown_70_ee_50_a2_17_9a_unknown_70_ee_50_a2_17_9a_aussenmodul_humidity
  - platform: homeassistant
    name: "Wohnzimmer Temperature"
    id: Wohnzimmer_Temperature
    entity_id: sensor.wohnzimmer_temperatur
  - platform: homeassistant
    name: "Wohnzimmer Humidity"
    id: Wohnzimmer_Humidity
    entity_id: sensor.wohnzimmer_luftfeuchtigkeit


globals:
  - id: display_temperature
    type: bool
    restore_value: true

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode:
        input: true
        pullup: true
      inverted: true
    name: Button
    id: Button
    filters:
    #  - delayed_off: 1ms
    on_press:
      then:
        - globals.set:
            id: display_temperature
            value: !lambda "return !id(display_temperature);"
        - if:
            condition:
              lambda: "return id(display_temperature);"
            then:
              - display.page.show: weather_outdoor_page
            else:
              - display.page.show: weather_indoor_page
    on_double_click:
      then:
        - display.page.show: hello_page

time:
  - platform: homeassistant
    id: homeassistant_time
    timezone: Europe/Amsterdam
display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    reset_pin: D0
    address: 0x3C
    id: my_display

    pages:
      - id: weather_outdoor_page
        lambda: |-
          if (id(display_temperature)) {
            char str[17];
            time_t currTime = id(homeassistant_time).now().timestamp;
            strftime(str, sizeof(str), "%H:%M  Aussen", localtime(&currTime)); // Nur Uhrzeit anzeigen
            it.printf(0, 0, id(roboto_small), "%s", str); // Anzeige der Uhrzeit
            it.printf(0, 20, id(roboto), "%.1f°C", id(Temperature).state); // Display temperature
            it.printf(0, 40, id(roboto), "%.1f %%", id(Humidity).state); // Display humidity
          }

      - id: weather_indoor_page
        lambda: |-
          char str[17];
          time_t currTime = id(homeassistant_time).now().timestamp;
          strftime(str, sizeof(str), "%H:%M  Innen", localtime(&currTime)); // Nur Uhrzeit anzeigen
          it.printf(0, 0, id(roboto_small), "%s", str); // Anzeige der Uhrzeit
          it.printf(0, 20, id(roboto), "%.1f°C", id(Wohnzimmer_Temperature).state); // Display temperature
          it.printf(0, 40, id(roboto), "%.1f %%", id(Wohnzimmer_Humidity).state); // Display humidity

      - id: hello_page
        lambda: |-
          it.printf(0, 0, id(roboto), "Hello!");

select:

  • platform: template
    name: “Page select”
    id: my_select
    optimistic: true
    options:
    • Main

    • Page 2

    • Page 3

    • Page 4
      initial_option: Main
      on_value:

    • if:
      condition:
      lambda: ‘return id(my_select).state == “Main”;’
      then:
      - logger.log: “Main page selected”
      - display.page.show: page1

    • if:
      condition:
      lambda: ‘return id(my_select).state == “Page 2”;’
      then:
      - logger.log: “Page 2 selected”
      - display.page.show: page2

    • if:
      condition:
      lambda: ‘return id(my_select).state == “Page 3”;’
      then:
      - logger.log: “Page 3 selected”
      - display.page.show: page3

    • if:
      condition:
      lambda: ‘return id(my_select).state == “Page 4”;’
      then:
      - logger.log: “Page 3 selected”
      - display.page.show: page4

entity id-s can’t be changed at runtime, so your best chance is creating a template sensor in home assistant, updating it when needed (in HA), and using that in your display page.

but if your question was how to change the page, here’s what i use all over:

display:
  - platform: ssd1306_i2c # https://esphome.io/components/display/ssd1306
    address: 0x3C
    id: lcd  # https://www.aliexpress.com/item/32861875681.html
    model: "SSD1306 128x64" # SSD1306 with 128 columns and 64 rows
    update_interval: 0s
    auto_clear_enabled: false
    invert: false 
    rotation: 0°
    contrast: 50%
    flip_x: true 
    flip_y: true 
    pages: 
      - id: page_idle
        lambda: |-
        .....

select:
  - platform: template
    name: ${display_name} Page
    icon: mdi:book-open-page-variant-outline
    id: ${device_name}_display_page
    entity_category: config
    update_interval: never
    disabled_by_default: true
    lambda: |- 
          auto page = id(lcd).get_active_page();
          std::string pagename;
          if (page == id(page_idle)) {
            pagename = "Idle";
          } else if (page == id(page_battery)) {
            pagename = "Charging";
          } else if (page == id(page_gyro)) {
            pagename = "Gyro";
          } else if (page == id(page_animation)) {
            pagename = "Animation";
          } else if (page == id(page_meta)) {
            pagename = "Meta";
          } else if (page == id(page_lost)){
            pagename = "Lost";
          } else if (page == id(page_motors)){
            pagename = "Motors";
          } else{
            pagename = "Charging";
          }
          return pagename;
    options:
      - "Idle"
      - "Charging"
      - "Meta"
      - "Gyro"
      - "Animation"
      - "Motors"
      - "Lost"
    set_action:
      then:
        - lambda: |-
            auto current_page = id(lcd).get_active_page();
            auto new_page = id(page_battery);
            if (x == "Idle") {
              new_page = id(page_idle);
            } else if (x == "Charging") {
              new_page = id(page_battery);
            } else if (x == "Animation") {
              new_page = id(page_animation);
            } else if (x == "Meta") {
              new_page = id(page_meta);
            } else if (x == "Gyro") {
              new_page = id(page_gyro);
            } else if (x == "Motors") {
              new_page = id(page_motors);
            } else if (x == "Lost") {
              new_page = id(page_lost);
            }
            else {
              ESP_LOGW("select","no index found for page");
            }
            if(current_page!=new_page){
              id(lcd).update();
            }