Struggling with correct syntax for displaying pages on a OLED SSD1306

Hi,
I’m trying to display some different temperature readings on one of these little OLED displays but I’m just having trouble getting the syntax correct and how to cycle through the pages on a timer. Below is the ESP Home code section regarding the display and I’m able to get it to display the first page without any issue.

Did a search and didn’t turn anything helpful up. Any help would be appreciated.

### display settings OLED ###

i2c:
  sda: D2
  scl: D1

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    reset_pin: D0
    address: 0x3C
    id: sensor_display
    
    pages:
      - id: page1     
        lambda: |-
          
          it.rectangle(0, 0, 128, 64);
          
          // reports the current temp of the Dallas temp probe from homeassistant. When pool not in use probe measures outside temp
          if (id(pool_temp).has_state()) {
            it.printf(64, 0, id(font1), TextAlign::TOP_CENTER , "%.1f°C", id(pool_temp).state);
          }
          // this prints out the outside temperature using the pool sensor in winter and hottub sensor in summer.
          it.print(64, 62, id(font2), TextAlign::BOTTOM_CENTER, "OUTSIDE TEMP");
          
      - id: page2     
        lambda: |-
          
          it.rectangle(0, 0, 128, 64);
          
          // reports the current temp of the Dallas temp probe from homeassistant. //
          if (id(hot_tub).has_state()) {
            it.printf(64, 0, id(font1), TextAlign::TOP_CENTER , "%.1f°C", id(hot_tub).state);
          }
          // this prints out the hottub temperature using the temp from the dallas sensor on the piping of tub. //
          it.print(64, 62, id(font2), TextAlign::BOTTOM_CENTER, "HOTTUB TEMP");
      
      
      - id: page3     
        lambda: |- 
        
          it.rectangle(0, 0, 128, 64);
          
          // reports the current temp of the Dallas temp probe from homeassistant. When pool not in use probe measures outside temp
          if (id(pool_temp).has_state()) {
            it.printf(64, 0, id(font1), TextAlign::TOP_CENTER , "%.1f°C", id(pool_temp).state);
          }
          // reports the status of the pool pump and the heater relay. uncomment the next two lines to use when Pool is in season //
          it.printf(3, 62, id(font2), TextAlign::BOTTOM_LEFT, "Pump: %s", id(pool_pump).state ? "ON" : "OFF");
          it.printf(125, 62, id(font2), TextAlign::BOTTOM_RIGHT, "Heat: %s", id(pool_heater).state ? "ON" : "OFF");

######  This is the part I'm having troubles with. Help :)  #########    
    # on_...:
    #   - display.page.show_next: sensor_display
    #   - display.page.show_previous: sensor_display
    # interval:
    #   - interval: 3s
    #     then:
    #       - display.page.show_next: sensor_display
    #       - component.update: sensor_display    
      
font:
  - file: 'Saira-Bold.ttf'
    id: font1
    size: 35
  - file: 'Saira-Bold.ttf'
    id: font2
    size: 10

If you want it to change based on a timer, you just need the interval part.

There is no need for on_.... That’s just necessary if you want to change pages e.g. on_press (if a button is pushed)

Thanks for the info @7h30n3, that actually help clear up something I wasn’t sure of in the ESP Home manual. I wasn’t sure if the "on_… " was required for the timer function. I was still getting an error even after removing that portion but finally figured it out and got it working by having the interval portion of the code at the same indentation as the font section.

If anyone trips across this in the future the code that worked is below.

### display settings OLED ###

i2c:
  sda: D2
  scl: D1

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    reset_pin: D0
    address: 0x3C
    id: sensor_display
    
    pages:
      - id: page1     
        lambda: |-
          
          it.rectangle(0, 0, 128, 64);
          
          // reports the current temp of the Dallas temp probe from homeassistant. When pool not in use probe measures outside temp
          if (id(pool_temp).has_state()) {
            it.printf(64, 0, id(font1), TextAlign::TOP_CENTER , "%.1f°C", id(pool_temp).state);
          }
          // this prints out the outside temperature using the pool sensor in winter and hottub sensor in summer.
          it.print(64, 62, id(font2), TextAlign::BOTTOM_CENTER, "OUTSIDE TEMP");
          
      - id: page2     
        lambda: |-
          
          it.rectangle(0, 0, 128, 64);
          
          // reports the current temp of the Dallas temp probe from homeassistant. //
          if (id(hot_tub).has_state()) {
            it.printf(64, 0, id(font1), TextAlign::TOP_CENTER , "%.1f°C", id(hot_tub).state);
          }
          // this prints out the hottub temperature using the temp from the dallas sensor on the piping of tub. //
          it.print(64, 62, id(font2), TextAlign::BOTTOM_CENTER, "HOTTUB TEMP");
      
      
      - id: page3     
        lambda: |- 
        
          it.rectangle(0, 0, 128, 64);
          
          // reports the current temp of the Dallas temp probe from homeassistant. When pool not in use probe measures outside temp
          if (id(pool_temp).has_state()) {
            it.printf(64, 0, id(font1), TextAlign::TOP_CENTER , "%.1f°C", id(pool_temp).state);
          }
          // reports the status of the pool pump and the heater relay. uncomment the next two lines to use when Pool is in season //
          it.printf(3, 62, id(font2), TextAlign::BOTTOM_LEFT, "Pump: %s", id(pool_pump).state ? "ON" : "OFF");
          it.printf(125, 62, id(font2), TextAlign::BOTTOM_RIGHT, "Heat: %s", id(pool_heater).state ? "ON" : "OFF");
    

interval:
  - interval: 3s
    then:
      - display.page.show_next: sensor_display
      - component.update: sensor_display    
      
font:
  - file: 'Saira-Bold.ttf'
    id: font1
    size: 35
  - file: 'Saira-Bold.ttf'
    id: font2
    size: 10
3 Likes